mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-06 19:08:59 -05:00
Add environment variable to specify OAuth Email Claim #1713
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @cdgco on GitHub (Aug 7, 2024).
Is your feature request related to a problem? Please describe.
I'm currently using Microsoft Entra ID as my OAuth provider but Entra does not reliably return user emails in the
emailclaim of the OAuth ID token. Some users in my environment do not have the email field set but instead have the email returned in thepreferred_usernameorusernameclaims.As a result, when a user who does not have the email claim tries to login, the logs show
OAuth callback failed, email is missingand the user is redirected to an API page listingThe email or password provided is incorrect. Please check for typos and try logging in again.Describe the solution you'd like
To more widely support different OAuth configurations, environment variables should be added similar to
OAUTH_USERNAME_CLAIMallowing users to specify an alternative email claim, such asOAUTH_EMAIL_CLAIMand/orMICROSOFT_EMAIL_CLAIM.This should be pretty straightforward, only need to define the variable(s) in backend/config.py and change line 2161 of main.py to something like this:
I'm happy to open a PR as well.
Describe alternatives you've considered
Alternatively, for the Microsoft auth provider, it could check for the
preferred_usernameclaim and fall back to that value if theemailclaim doesn't exist.@justinh-rahb commented on GitHub (Aug 7, 2024):
That would be a valuable PR, I think the approach you outline should work. If this primarily only affects microsoft, perhaps the variable should be named accordingly, otherwise this may make things difficult if you use both Google and Microsoft (as I do). FWIW, it seems all my users return a valid
emailclaim 😅@cdgco commented on GitHub (Aug 7, 2024):
I ended following the same implementation as the picture claim that seems to be provider agnostic and I think it would be good to have this support OIDC as well, so using just the
OAUTH_EMAIL_CLAIMshould cover all the bases.I think the missing claim is something to do with aliases in Azure but not totally sure. My primary account has an email but my org has some permissions only / alias accounts that don't seem to have emails assigned.
@someonewating commented on GitHub (May 24, 2025):
I believe the root cause is indeed Microsoft Entra ID.
Not sure why @justinh-rahb 's Entra ID is able to return
emailclaim. In my tenant, the account does not haveemailclaim unless it is configured.After adding the email address to the 'Contact Information'. The error is resolved.