Skip to content

Commit

Permalink
Merge pull request #48 from factly/feat/session
Browse files Browse the repository at this point in the history
add session api
  • Loading branch information
paul-tharun authored Sep 11, 2024
2 parents c048fb4 + faa877c commit eb92bd5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
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=[])

0 comments on commit eb92bd5

Please sign in to comment.