Add authorization

This commit is contained in:
2025-10-23 11:22:27 +02:00
parent a1563b53ac
commit e1c8b4ebeb
7 changed files with 82 additions and 9 deletions

View File

@@ -1,9 +1,25 @@
# backend/app/main.py
from fastapi import FastAPI, Request
import os
from typing import Annotated
from fastapi import Depends, FastAPI, HTTPException, Request
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
app = FastAPI()
async def get_user(request: Request) -> dict:
if username := os.environ.get("APS_username", None):
return {"username": username}
if "ynh_user" not in request.headers:
raise HTTPException(status_code=401, detail="Missing ynh_user header")
return {"username": request.headers["ynh_user"]}
UserDep = Annotated[dict, Depends(get_user)]
app = FastAPI(dependencies=[Depends(get_user)])
templates = Jinja2Templates(directory="src/allmende_payment_system/templates")
app.mount(
"/static",