mirror of
https://gitee.com/dcren/openiddict-documentation.git
synced 2025-11-10 11:24:45 +08:00
Update the documentation pages
This commit is contained in:
@@ -218,11 +218,70 @@ store the tenant name. Once added, the URIs can include a placeholder of the sam
|
||||
Description="The tenant used to identify the Zendesk instance" />
|
||||
</Provider>
|
||||
</code></pre></div>
|
||||
<h2 id="unwrap-userinfo-responses-if-necessary">Unwrap userinfo responses if necessary</h2>
|
||||
<p>If the provider returns wrapped or nested userinfo responses (e.g under a <code>response</code> or <code>data</code> node), the <code>UnwrapUserinfoResponse</code> handler in
|
||||
<a href="https://github.com/openiddict/openiddict-core/blob/dev/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Userinfo.cs">OpenIddictClientWebIntegrationHandlers.Userinfo.cs</a>
|
||||
must be updated to unwrap the userinfo payload and allow OpenIddict to map them to flat CLR <code>Claim</code> instances:</p>
|
||||
<pre><code class="lang-csharp">/// <summary>
|
||||
/// Contains the logic responsible for extracting the userinfo response
|
||||
/// from nested JSON nodes (e.g "data") for the providers that require it.
|
||||
/// </summary>
|
||||
public sealed class UnwrapUserinfoResponse : IOpenIddictClientHandler<ExtractUserinfoResponseContext>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the default descriptor definition assigned to this handler.
|
||||
/// </summary>
|
||||
public static OpenIddictClientHandlerDescriptor Descriptor { get; }
|
||||
= OpenIddictClientHandlerDescriptor.CreateBuilder<ExtractUserinfoResponseContext>()
|
||||
.UseSingletonHandler<UnwrapUserinfoResponse>()
|
||||
.SetOrder(int.MaxValue - 50_000)
|
||||
.SetType(OpenIddictClientHandlerType.BuiltIn)
|
||||
.Build();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ValueTask HandleAsync(ExtractUserinfoResponseContext context)
|
||||
{
|
||||
if (context is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
context.Response = context.Registration.ProviderType switch
|
||||
{
|
||||
// Fitbit returns a nested "user" object.
|
||||
ProviderTypes.Fitbit => new(context.Response["user"]?.GetNamedParameters() ??
|
||||
throw new InvalidOperationException(SR.FormatID0334("user"))),
|
||||
|
||||
// StackExchange returns an "items" array containing a single element.
|
||||
ProviderTypes.StackExchange => new(context.Response["items"]?[0]?.GetNamedParameters() ??
|
||||
throw new InvalidOperationException(SR.FormatID0334("items/0"))),
|
||||
|
||||
// SubscribeStar returns a nested "user" object that is itself nested in a GraphQL "data" node.
|
||||
ProviderTypes.SubscribeStar => new(context.Response["data"]?["user"]?.GetNamedParameters() ??
|
||||
throw new InvalidOperationException(SR.FormatID0334("data/user"))),
|
||||
|
||||
_ => context.Response
|
||||
};
|
||||
|
||||
return default;
|
||||
}
|
||||
}
|
||||
</code></pre><div class="NOTE"><h5>Note</h5><p>If you're unsure whether the provider returns wrapped responses or not, the
|
||||
received payload can be found in the logs after a successful authorization flow:</p>
|
||||
<pre><code>OpenIddict.Client.OpenIddictClientDispatcher: Information: The userinfo response returned by https://contoso.com/users/me was successfully extracted: {
|
||||
"data": {
|
||||
"username": "odile.donat",
|
||||
"name": "Odile Donat",
|
||||
"email": "odile.donat@fabrikam.com"
|
||||
}
|
||||
}.
|
||||
</code></pre></div>
|
||||
<h2 id="if-the-provider-doesnt-support-standard-openid-connect-userinfo-map-the-provider-specific-claims-to-their-claimtypes-equivalent">If the provider doesn't support standard OpenID Connect userinfo, map the provider-specific claims to their <code>ClaimTypes</code> equivalent</h2>
|
||||
<p>If the provider doesn't return an <code>id_token</code> and doesn't offer a standard userinfo endpoint, it is likely it uses custom parameters
|
||||
to represent things like the user identifier. If so, update the <code>MapCustomWebServicesFederationClaims</code> event handler to map these
|
||||
parameters to the usual WS-Federation claims exposed by the .NET BCL <code>ClaimTypes</code> class, which simplifies integration with libraries
|
||||
like ASP.NET Core Identity:</p>
|
||||
to represent things like the user identifier. If so, update the <code>MapCustomWebServicesFederationClaims</code> event handler in
|
||||
<a href="https://github.com/openiddict/openiddict-core/blob/dev/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.cs">OpenIddictClientWebIntegrationHandlers.cs</a>
|
||||
to map these parameters to the usual WS-Federation claims exposed by the .NET BCL <code>ClaimTypes</code> class, which simplifies integration
|
||||
with libraries like ASP.NET Core Identity:</p>
|
||||
<pre><code class="lang-csharp">/// <summary>
|
||||
/// Contains the logic responsible for mapping select custom claims to
|
||||
/// their WS-Federation equivalent for the providers that require it.
|
||||
|
||||
Reference in New Issue
Block a user