Skip to content

Commit

Permalink
Remove all usage of user parameter
Browse files Browse the repository at this point in the history
Remove all usage of consuming the `user` parameter to process the user's first name and last name.
  • Loading branch information
martincostello committed Aug 31, 2022
1 parent a0fe95e commit 54fd20c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
17 changes: 6 additions & 11 deletions src/AspNet.Security.OAuth.Apple/AppleAuthenticationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ protected virtual IEnumerable<Claim> ExtractClaimsFromToken([NotNull] string tok
/// <returns>
/// An <see cref="IEnumerable{Claim}"/> containing the claims extracted from the user information.
/// </returns>
[Obsolete("This method is obsolete and will be removed in a future version.")]
protected virtual IEnumerable<Claim> ExtractClaimsFromUser([NotNull] JsonElement user)
{
var claims = new List<Claim>();
Expand All @@ -170,6 +171,11 @@ protected virtual IEnumerable<Claim> 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;
}

Expand Down Expand Up @@ -346,17 +352,6 @@ private async Task<HandleRequestResult> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu

[Theory]
[InlineData(ClaimTypes.Email, "[email protected]")]
[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
Expand All @@ -71,9 +69,7 @@ static void ConfigureServices(IServiceCollection services)

[Theory]
[InlineData(ClaimTypes.Email, "[email protected]")]
[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
Expand Down Expand Up @@ -146,9 +142,7 @@ static void ConfigureServices(IServiceCollection services)

[Theory]
[InlineData(ClaimTypes.Email, "[email protected]")]
[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
Expand Down

0 comments on commit 54fd20c

Please sign in to comment.