Fix sign-in loop when email is not set in Azure AD account #430
+4
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.azurechat/src/features/auth-page/auth-api.ts
Line 47 in f53e525
email
property is used in theuserHashedId
function to identify users in the database, but if theemail
property isundefined
, the hashing fails.azurechat/src/features/auth-page/helpers.ts
Lines 28 to 32 in f53e525
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.)