Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add session api #48

Merged
merged 3 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions app/api/api_v1/routers/session.py
Original file line number Diff line number Diff line change
@@ -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"
)
2 changes: 2 additions & 0 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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=[])