From f767d23545d30c38d676905a93e69d3538753d2a Mon Sep 17 00:00:00 2001 From: cmyui Date: Sat, 6 Jul 2024 07:34:22 -0400 Subject: [PATCH] include identity in auth api response --- app/api/public/authentication.py | 5 ++++- app/usecases/authentication.py | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/api/public/authentication.py b/app/api/public/authentication.py index a05ebc2..9d8e5d3 100644 --- a/app/api/public/authentication.py +++ b/app/api/public/authentication.py @@ -30,7 +30,10 @@ async def authenticate( if isinstance(response, Error): return JSONResponse(content=response.model_dump(), status_code=401) - http_response = JSONResponse(content={}, status_code=200) + http_response = JSONResponse( + content=response.identity.model_dump(), + status_code=200, + ) http_response.set_cookie( "X-Akatsuki-Access-Token", value=response.access_token, diff --git a/app/usecases/authentication.py b/app/usecases/authentication.py index 2e3d548..e9a44af 100644 --- a/app/usecases/authentication.py +++ b/app/usecases/authentication.py @@ -3,8 +3,6 @@ from pydantic import BaseModel -import app.state -from app import logger from app import security from app.common_types import UserPrivileges from app.errors import Error @@ -13,8 +11,15 @@ from app.repositories import users +class Identity(BaseModel): + user_id: int + username: str + privileges: UserPrivileges + + class AuthorizationGrant(BaseModel): access_token: str + identity: Identity privileges: UserPrivileges expires_at: datetime | None @@ -72,4 +77,9 @@ async def authenticate( access_token=access_token.access_token, privileges=access_token.privileges, expires_at=None, + identity=Identity( + user_id=user.id, + username=user.username, + privileges=user.privileges, + ), )