Skip to content

Commit

Permalink
Also fetching display name now (and potentially other info)
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenthoms committed Sep 21, 2023
1 parent bae51f0 commit cbbe417
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions backend/src/backend/primary/routers/general.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime
import logging
import json

import starsessions
from starlette.responses import StreamingResponse
Expand All @@ -17,13 +18,11 @@

class UserInfo(BaseModel):
username: str
display_name: str | None
avatar_b64str: str | None
has_sumo_access: bool
has_smda_access: bool

class UserAvatar(BaseModel):
avatar: bytes

router = APIRouter()


Expand Down Expand Up @@ -54,6 +53,7 @@ async def logged_in_user(request: Request, includeAvatar: bool = Query(False, de
user_info = UserInfo(
username=authenticated_user.get_username(),
avatar_b64str=None,
display_name=None,
has_sumo_access=authenticated_user.has_sumo_access_token(),
has_smda_access=authenticated_user.has_smda_access_token(),
)
Expand All @@ -64,6 +64,11 @@ async def logged_in_user(request: Request, includeAvatar: bool = Query(False, de
result = await client.get("https://graph.microsoft.com/v1.0/me/photo/$value", headers=headers)
if result.status_code == 200:
user_info.avatar_b64str = base64.b64encode(result.content)

async with httpx.AsyncClient() as client:
result = await client.get("https://graph.microsoft.com/v1.0/me", headers=headers)
if result.status_code == 200:
user_info.display_name = json.loads(result.content.decode("utf-8")).get("displayName", None)

return user_info

Expand Down

0 comments on commit cbbe417

Please sign in to comment.