Skip to content

Add upn fallback for single-tenant Microsoft/Azure AD authentication#295

Open
lperezmo wants to merge 1 commit intomkhorasani:mainfrom
lperezmo:main
Open

Add upn fallback for single-tenant Microsoft/Azure AD authentication#295
lperezmo wants to merge 1 commit intomkhorasani:mainfrom
lperezmo:main

Conversation

@lperezmo
Copy link
Copy Markdown

Problem

Azure AD tokens for single-tenant (work/school) configurations often omit the email claim but include upn (User Principal Name), which is typically the user's email address. This causes authentication to fail because downstream code expects email to be present. This affects anyone using Microsoft OAuth with a single-tenant app registration to restrict login to their organization.

Fix

Falls back to upn when email is absent in the decoded JWT. The change is minimal (3 lines) and fully backwards compatible - multi-tenant setups that already return email are unaffected, and upn is preserved in the dict for anyone relying on it.

Context

I've been monkey-patching this method in production for about a year to get single-tenant SSO working for my organization. Figured it was worth upstreaming since it's a small, safe change and this is probably a common pain point for anyone using single-tenant app registrations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant