-
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.
Merge pull request #48 from factly/feat/session
add session api
- Loading branch information
Showing
2 changed files
with
30 additions
and
0 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 |
---|---|---|
@@ -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" | ||
) |
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