Open heguro opened 2 months ago
+1 on this. Was about to make the same PR
+1 for this request.
Some orgs don't have the email field setup in O365 and this will allow them to not require an additional step for onboarding the app
@thivy - this needs to be merged to main.
Fix #273, May related: #408, #418
The profile object returned when signing in from Azure AD may be missing the
email
property. In this case, the following will occur.profile.email.toLowerCase()
, so AzureADProvider doesn't return profile and cause an sign-in loop.email
property is used in theuserHashedId
function to identify users in the database, but if theemail
property isundefined
, the hashing fails.In this PR, if the
email
property is missing, thepreferred_username
property, which contains the user principal name, is used as theemail
instead.(Note: Personally, I believe using an immutable identifier like
sub
foruserHashedId
would be more robust than usingemail
orpreferred_username
(which Microsoft's documentation states are mutable). However, implementing this idea is not included in this PR to maintain compatibility with previously stored data.)