diff --git a/src/AspNet.Security.OAuth.Apple/AppleAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Apple/AppleAuthenticationHandler.cs index be9c3c0ab..960b1d78e 100644 --- a/src/AspNet.Security.OAuth.Apple/AppleAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.Apple/AppleAuthenticationHandler.cs @@ -160,6 +160,7 @@ protected virtual IEnumerable ExtractClaimsFromToken([NotNull] string tok /// /// An containing the claims extracted from the user information. /// + [Obsolete("This method is obsolete and will be removed in a future version.")] protected virtual IEnumerable ExtractClaimsFromUser([NotNull] JsonElement user) { var claims = new List(); @@ -170,6 +171,11 @@ protected virtual IEnumerable ExtractClaimsFromUser([NotNull] JsonElement claims.Add(new Claim(ClaimTypes.Surname, name.GetString("lastName") ?? string.Empty, ClaimValueTypes.String, ClaimsIssuer)); } + if (user.TryGetProperty("email", out var email)) + { + claims.Add(new Claim(ClaimTypes.Email, email.GetString() ?? string.Empty, ClaimValueTypes.String, ClaimsIssuer)); + } + return claims; } @@ -346,17 +352,6 @@ private async Task HandleRemoteAuthenticateAsync( properties.StoreTokens(authTokens); } - if (parameters.TryGetValue("user", out var userJson)) - { - using var user = JsonDocument.Parse(userJson); - var userClaims = ExtractClaimsFromUser(user.RootElement); - - foreach (var claim in userClaims) - { - identity.AddClaim(claim); - } - } - var ticket = await CreateTicketAsync(identity, properties, tokens); if (ticket != null) diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Apple/AppleTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Apple/AppleTests.cs index dcb53ec73..72e8e3740 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Apple/AppleTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Apple/AppleTests.cs @@ -44,9 +44,7 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [Theory] [InlineData(ClaimTypes.Email, "johnny.appleseed@apple.local")] - [InlineData(ClaimTypes.GivenName, "Johnny")] [InlineData(ClaimTypes.NameIdentifier, "001883.fcc77ba97500402389df96821ad9c790.1517")] - [InlineData(ClaimTypes.Surname, "Appleseed")] public async Task Can_Sign_In_Using_Apple_With_Client_Secret(string claimType, string claimValue) { // Arrange @@ -71,9 +69,7 @@ static void ConfigureServices(IServiceCollection services) [Theory] [InlineData(ClaimTypes.Email, "johnny.appleseed@apple.local")] - [InlineData(ClaimTypes.GivenName, "Johnny")] [InlineData(ClaimTypes.NameIdentifier, "001883.fcc77ba97500402389df96821ad9c790.1517")] - [InlineData(ClaimTypes.Surname, "Appleseed")] public async Task Can_Sign_In_Using_Apple_With_Private_Key(string claimType, string claimValue) { // Arrange @@ -146,9 +142,7 @@ static void ConfigureServices(IServiceCollection services) [Theory] [InlineData(ClaimTypes.Email, "johnny.appleseed@apple.local")] - [InlineData(ClaimTypes.GivenName, "Johnny")] [InlineData(ClaimTypes.NameIdentifier, "001883.fcc77ba97500402389df96821ad9c790.1517")] - [InlineData(ClaimTypes.Surname, "Appleseed")] public async Task Can_Sign_In_Using_Apple_With_No_Token_Validation(string claimType, string claimValue) { // Arrange