Skip to content

Commit

Permalink
include identity in auth api response
Browse files Browse the repository at this point in the history
  • Loading branch information
cmyui committed Jul 6, 2024
1 parent a1be00c commit f767d23
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
5 changes: 4 additions & 1 deletion app/api/public/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 12 additions & 2 deletions app/usecases/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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,
),
)

0 comments on commit f767d23

Please sign in to comment.