Browse Source

Apple Sign In - Name response

pull/2442/head
Jonathan Law 2 weeks ago
parent
commit
c06ebbf7ac
No known key found for this signature in database GPG Key ID: 7AA5C0DE5101BEB1
  1. 1
      src/OpenIddict.Abstractions/OpenIddictConstants.cs
  2. 12
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Userinfo.cs
  3. 2
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.cs

1
src/OpenIddict.Abstractions/OpenIddictConstants.cs

@ -547,6 +547,7 @@ public static class OpenIddictConstants
public const string Phone = "phone";
public const string Profile = "profile";
public const string Roles = "roles";
public const string Name = "name";
}
public static class Separators

12
src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Userinfo.cs

@ -512,6 +512,18 @@ public static partial class OpenIddictClientWebIntegrationHandlers
}
}
// Note: Apple returns a non-standard "name" claim formatted as a JSON object.
else if (context.Registration.ProviderType is ProviderTypes.Apple)
{
var name = context.Response[Claims.Name];
if (name is not null)
{
context.Response[Claims.Name] = $"{name?["firstName"]} {name?["lastName"]}";
context.Response[Claims.FamilyName] = name?["lastName"];
context.Response[Claims.GivenName] = name?["firstName"];
}
}
return ValueTask.CompletedTask;
}
}

2
src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.cs

@ -1750,7 +1750,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
context.ResponseMode = context.Registration.ProviderType switch
{
// Note: Apple requires using form_post when the "email" or "name" scopes are requested.
ProviderTypes.Apple when context.Scopes.Contains(Scopes.Email) || context.Scopes.Contains("name")
ProviderTypes.Apple when context.Scopes.Contains(Scopes.Email) || context.Scopes.Contains(Scopes.Name)
=> ResponseModes.FormPost,
_ => context.ResponseMode

Loading…
Cancel
Save