Skip to content

Commit 54fd20c

Browse files
Remove all usage of user parameter
Remove all usage of consuming the `user` parameter to process the user's first name and last name.
1 parent a0fe95e commit 54fd20c

File tree

2 files changed

+6
-17
lines changed

2 files changed

+6
-17
lines changed

src/AspNet.Security.OAuth.Apple/AppleAuthenticationHandler.cs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ protected virtual IEnumerable<Claim> ExtractClaimsFromToken([NotNull] string tok
160160
/// <returns>
161161
/// An <see cref="IEnumerable{Claim}"/> containing the claims extracted from the user information.
162162
/// </returns>
163+
[Obsolete("This method is obsolete and will be removed in a future version.")]
163164
protected virtual IEnumerable<Claim> ExtractClaimsFromUser([NotNull] JsonElement user)
164165
{
165166
var claims = new List<Claim>();
@@ -170,6 +171,11 @@ protected virtual IEnumerable<Claim> ExtractClaimsFromUser([NotNull] JsonElement
170171
claims.Add(new Claim(ClaimTypes.Surname, name.GetString("lastName") ?? string.Empty, ClaimValueTypes.String, ClaimsIssuer));
171172
}
172173

174+
if (user.TryGetProperty("email", out var email))
175+
{
176+
claims.Add(new Claim(ClaimTypes.Email, email.GetString() ?? string.Empty, ClaimValueTypes.String, ClaimsIssuer));
177+
}
178+
173179
return claims;
174180
}
175181

@@ -346,17 +352,6 @@ private async Task<HandleRequestResult> HandleRemoteAuthenticateAsync(
346352
properties.StoreTokens(authTokens);
347353
}
348354

349-
if (parameters.TryGetValue("user", out var userJson))
350-
{
351-
using var user = JsonDocument.Parse(userJson);
352-
var userClaims = ExtractClaimsFromUser(user.RootElement);
353-
354-
foreach (var claim in userClaims)
355-
{
356-
identity.AddClaim(claim);
357-
}
358-
}
359-
360355
var ticket = await CreateTicketAsync(identity, properties, tokens);
361356

362357
if (ticket != null)

test/AspNet.Security.OAuth.Providers.Tests/Apple/AppleTests.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
4444

4545
[Theory]
4646
[InlineData(ClaimTypes.Email, "[email protected]")]
47-
[InlineData(ClaimTypes.GivenName, "Johnny")]
4847
[InlineData(ClaimTypes.NameIdentifier, "001883.fcc77ba97500402389df96821ad9c790.1517")]
49-
[InlineData(ClaimTypes.Surname, "Appleseed")]
5048
public async Task Can_Sign_In_Using_Apple_With_Client_Secret(string claimType, string claimValue)
5149
{
5250
// Arrange
@@ -71,9 +69,7 @@ static void ConfigureServices(IServiceCollection services)
7169

7270
[Theory]
7371
[InlineData(ClaimTypes.Email, "[email protected]")]
74-
[InlineData(ClaimTypes.GivenName, "Johnny")]
7572
[InlineData(ClaimTypes.NameIdentifier, "001883.fcc77ba97500402389df96821ad9c790.1517")]
76-
[InlineData(ClaimTypes.Surname, "Appleseed")]
7773
public async Task Can_Sign_In_Using_Apple_With_Private_Key(string claimType, string claimValue)
7874
{
7975
// Arrange
@@ -146,9 +142,7 @@ static void ConfigureServices(IServiceCollection services)
146142

147143
[Theory]
148144
[InlineData(ClaimTypes.Email, "[email protected]")]
149-
[InlineData(ClaimTypes.GivenName, "Johnny")]
150145
[InlineData(ClaimTypes.NameIdentifier, "001883.fcc77ba97500402389df96821ad9c790.1517")]
151-
[InlineData(ClaimTypes.Surname, "Appleseed")]
152146
public async Task Can_Sign_In_Using_Apple_With_No_Token_Validation(string claimType, string claimValue)
153147
{
154148
// Arrange

0 commit comments

Comments
 (0)