Handle MicrosoftAccount email fallback #9083 (#9304)

This commit is contained in:
Chris Ross 2019-04-12 08:26:15 -07:00 committed by GitHub
parent 287c889943
commit 0d45fe73d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View File

@ -27,7 +27,15 @@ namespace Microsoft.AspNetCore.Authentication.MicrosoftAccount
ClaimActions.MapJsonKey(ClaimTypes.Name, "displayName");
ClaimActions.MapJsonKey(ClaimTypes.GivenName, "givenName");
ClaimActions.MapJsonKey(ClaimTypes.Surname, "surname");
ClaimActions.MapCustomJson(ClaimTypes.Email, user => user.GetString("mail") ?? user.GetString("userPrincipalName"));
ClaimActions.MapCustomJson(ClaimTypes.Email, user =>
{
var mail = user.GetString("mail");
if (string.IsNullOrEmpty(mail))
{
mail = user.GetString("userPrincipalName");
}
return mail;
});
}
}
}

View File

@ -203,7 +203,8 @@ namespace Microsoft.AspNetCore.Authentication.Tests.MicrosoftAccount
displayName = "Test Name",
givenName = "Test Given Name",
surname = "Test Family Name",
mail = "Test email"
mail = "",
userPrincipalName = "Test email"
});
}