Skip to content

Commit

Permalink
api: update user based on oauth token
Browse files Browse the repository at this point in the history
Keep the user details (name and email) in sync
with the values from the oauth.
  • Loading branch information
anarute committed Feb 9, 2024
1 parent 4491829 commit 6aa15b5
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion api/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,20 @@ async def get_current_user(token: Annotated[str, Depends(oauth2_scheme)], db: Se
status_code=status.HTTP_401_UNAUTHORIZED,
detail="You are not an authorized user.",
)

update_user = False
if not user.first_name or user.first_name != decoded["given_name"]:
update_user = True
user.first_name = decoded["given_name"]
if not user.last_name or user.last_name != decoded["family_name"]:
update_user = True
user.last_name = decoded["family_name"]
if not user.email or user.email != decoded["email"]:
update_user = True
user.email = decoded["email"]
if update_user:
UserService(db).update_user(
username=user.username, email=user.email, first_name=user.first_name, last_name=user.last_name
)
if USE_OIDC_ROLES:
user.roles = decoded[OIDC_ROLES_PROPERTY].copy()
user.authorized_scopes = decoded["scopes"].copy()
Expand Down

0 comments on commit 6aa15b5

Please sign in to comment.