Skip to content

Commit

Permalink
Add an event handler responsible for mapping non-standard revocation …
Browse files Browse the repository at this point in the history
…parameters to their standard equivalent
  • Loading branch information
kevinchalet committed Feb 10, 2025
1 parent da82d11 commit 04e66fe
Showing 1 changed file with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public static class Revocation
/*
* Revocation request preparation:
*/
MapNonStandardRequestParameters.Descriptor,
OverrideHttpMethod.Descriptor,
AttachBearerAccessToken.Descriptor,

Expand All @@ -30,6 +31,42 @@ public static class Revocation
NormalizeContentType.Descriptor
]);

/// <summary>
/// Contains the logic responsible for mapping non-standard request parameters
/// to their standard equivalent for the providers that require it.
/// </summary>
public sealed class MapNonStandardRequestParameters : IOpenIddictClientHandler<PrepareRevocationRequestContext>
{
/// <summary>
/// Gets the default descriptor definition assigned to this handler.
/// </summary>
public static OpenIddictClientHandlerDescriptor Descriptor { get; }
= OpenIddictClientHandlerDescriptor.CreateBuilder<PrepareRevocationRequestContext>()
.UseSingletonHandler<MapNonStandardRequestParameters>()
.SetOrder(int.MinValue + 100_000)
.SetType(OpenIddictClientHandlerType.BuiltIn)
.Build();

/// <inheritdoc/>
public ValueTask HandleAsync(PrepareRevocationRequestContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}

// Yandex doesn't support the standard "token" parameter and requires
// using the non-standard "access_token" parameter instead.
if (context.Registration.ProviderType is ProviderTypes.VkId)
{
context.Request.AccessToken = context.Token;
context.Request.Token = null;
}

return default;
}
}

/// <summary>
/// Contains the logic responsible for overriding the HTTP method for the providers that require it.
/// </summary>
Expand Down Expand Up @@ -61,7 +98,6 @@ public ValueTask HandleAsync(PrepareRevocationRequestContext context)

request.Method = context.Registration.ProviderType switch
{

ProviderTypes.Zendesk => HttpMethod.Delete,

_ => request.Method
Expand Down

0 comments on commit 04e66fe

Please sign in to comment.