-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
pre-commit
committed
Sep 11, 2024
1 parent
7286c87
commit faa877c
Showing
2 changed files
with
11 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters