Skip to content

Commit aa2f7fb

Browse files
committed
refac
1 parent cdc2b3b commit aa2f7fb

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

backend/open_webui/utils/oauth.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,12 +1397,21 @@ async def handle_callback(self, request, provider, response, db=None):
13971397

13981398
# Try to get userinfo from the token first, some providers include it there
13991399
user_data: UserInfo = token.get('userinfo')
1400+
# Preserve extra claims from the ID token (e.g. roles, groups for
1401+
# Microsoft Entra ID) before the userinfo endpoint possibly overwrites them.
1402+
id_token_claims = dict(user_data) if user_data else {}
14001403
if (
14011404
(not user_data)
14021405
or (auth_manager_config.OAUTH_EMAIL_CLAIM not in user_data)
14031406
or (auth_manager_config.OAUTH_USERNAME_CLAIM not in user_data)
14041407
):
14051408
user_data: UserInfo = await client.userinfo(token=token)
1409+
# Merge back ID token claims that the userinfo endpoint doesn't
1410+
# return. Only backfill missing keys so userinfo always wins.
1411+
if user_data and id_token_claims:
1412+
for key, value in id_token_claims.items():
1413+
if key not in user_data:
1414+
user_data[key] = value
14061415
if provider == 'feishu' and isinstance(user_data, dict) and 'data' in user_data:
14071416
user_data = user_data['data']
14081417
if not user_data:

0 commit comments

Comments
 (0)