Add authorization
This commit is contained in:
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user