diff --git a/app/api/api_v1/routers/session.py b/app/api/api_v1/routers/session.py new file mode 100644 index 0000000..7ae8e48 --- /dev/null +++ b/app/api/api_v1/routers/session.py @@ -0,0 +1,28 @@ +from typing import Optional + +import httpx +from fastapi import APIRouter, Header, HTTPException +from fastapi.responses import JSONResponse + +session_router = router = APIRouter() + + +@router.get("/whoami") +async def get_session(authorization: Optional[str] = Header(None)): + if not authorization: + raise HTTPException( + status_code=401, detail="Authorization header is missing" + ) + + async with httpx.AsyncClient() as client: + response = await client.get( + "https://develop-xtjn2g.zitadel.cloud/oidc/v1/userinfo", + headers={"Authorization": authorization}, + ) + + if response.status_code == 200: + return JSONResponse(content=response.json(), status_code=200) + else: + raise HTTPException( + status_code=401, detail="Invalid or expired session" + ) diff --git a/app/main.py b/app/main.py index e996cbd..4b96055 100644 --- a/app/main.py +++ b/app/main.py @@ -8,6 +8,7 @@ from app.api.api_v1.routers.docs import docs_router from app.api.api_v1.routers.metadata import metadata_router from app.api.api_v1.routers.s3_checks import s3_router +from app.api.api_v1.routers.session import session_router from app.core.config import Settings settings = Settings() @@ -37,3 +38,4 @@ async def home(request: Request): app.include_router( dictionary_router, prefix="/dictionary", tags=["Dictionary"] ) +app.include_router(session_router, prefix="/session", tags=[])