Skip to content

Commit

Permalink
pre-commit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit committed Sep 11, 2024
1 parent 7286c87 commit faa877c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
15 changes: 10 additions & 5 deletions app/api/api_v1/routers/session.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
from typing import Optional

import httpx
from fastapi import APIRouter, Header, HTTPException
from fastapi.responses import JSONResponse
import httpx
from typing import Optional

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")
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}
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")
raise HTTPException(
status_code=401, detail="Invalid or expired session"
)
4 changes: 1 addition & 3 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,4 @@ async def home(request: Request):
app.include_router(
dictionary_router, prefix="/dictionary", tags=["Dictionary"]
)
app.include_router(
session_router, prefix="/session", tags=[]
)
app.include_router(session_router, prefix="/session", tags=[])

0 comments on commit faa877c

Please sign in to comment.