Skip to content

Commit 04e66fe

Browse files
committed
Add an event handler responsible for mapping non-standard revocation parameters to their standard equivalent
1 parent da82d11 commit 04e66fe

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

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

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public static class Revocation
2121
/*
2222
* Revocation request preparation:
2323
*/
24+
MapNonStandardRequestParameters.Descriptor,
2425
OverrideHttpMethod.Descriptor,
2526
AttachBearerAccessToken.Descriptor,
2627

@@ -30,6 +31,42 @@ public static class Revocation
3031
NormalizeContentType.Descriptor
3132
]);
3233

34+
/// <summary>
35+
/// Contains the logic responsible for mapping non-standard request parameters
36+
/// to their standard equivalent for the providers that require it.
37+
/// </summary>
38+
public sealed class MapNonStandardRequestParameters : IOpenIddictClientHandler<PrepareRevocationRequestContext>
39+
{
40+
/// <summary>
41+
/// Gets the default descriptor definition assigned to this handler.
42+
/// </summary>
43+
public static OpenIddictClientHandlerDescriptor Descriptor { get; }
44+
= OpenIddictClientHandlerDescriptor.CreateBuilder<PrepareRevocationRequestContext>()
45+
.UseSingletonHandler<MapNonStandardRequestParameters>()
46+
.SetOrder(int.MinValue + 100_000)
47+
.SetType(OpenIddictClientHandlerType.BuiltIn)
48+
.Build();
49+
50+
/// <inheritdoc/>
51+
public ValueTask HandleAsync(PrepareRevocationRequestContext context)
52+
{
53+
if (context is null)
54+
{
55+
throw new ArgumentNullException(nameof(context));
56+
}
57+
58+
// Yandex doesn't support the standard "token" parameter and requires
59+
// using the non-standard "access_token" parameter instead.
60+
if (context.Registration.ProviderType is ProviderTypes.VkId)
61+
{
62+
context.Request.AccessToken = context.Token;
63+
context.Request.Token = null;
64+
}
65+
66+
return default;
67+
}
68+
}
69+
3370
/// <summary>
3471
/// Contains the logic responsible for overriding the HTTP method for the providers that require it.
3572
/// </summary>
@@ -61,7 +98,6 @@ public ValueTask HandleAsync(PrepareRevocationRequestContext context)
6198

6299
request.Method = context.Registration.ProviderType switch
63100
{
64-
65101
ProviderTypes.Zendesk => HttpMethod.Delete,
66102

67103
_ => request.Method

0 commit comments

Comments
 (0)