Skip to content

fix: fall back to userPrincipalName when mail is empty in AzureADv2#638

Open
Yanhu007 wants to merge 1 commit intomarkbates:masterfrom
Yanhu007:fix/azureadv2-email-fallback
Open

fix: fall back to userPrincipalName when mail is empty in AzureADv2#638
Yanhu007 wants to merge 1 commit intomarkbates:masterfrom
Yanhu007:fix/azureadv2-email-fallback

Conversation

@Yanhu007
Copy link
Copy Markdown

Fixes #289

Problem

The AzureADv2 provider maps user.Email from the Microsoft Graph API mail field. However, many Azure AD accounts (especially personal Microsoft accounts and some organizational accounts) have mail as null/empty while userPrincipalName contains their email address.

This results in an empty Email field on the returned user.

Fix

Fall back to userPrincipalName when mail is empty:

user.Email = u.Email
if user.Email == "" {
    user.Email = u.UserPrincipalName
}

This matches the approach used by other OAuth providers (e.g., Google) that check multiple fields for email.

Many Azure AD users have a null/empty "mail" field while their
"userPrincipalName" contains a valid email address. Fall back to
userPrincipalName when mail is empty so the Email field is populated.

Fixes markbates#289
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.

Azureadv2 provider does not mapping email info correctly

1 participant