Skip to content

Commit

Permalink
Update the Yandex provider to allow specifying a device_id/device_name
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinchalet committed Feb 10, 2025
1 parent ac02954 commit d9732c8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public static partial class OpenIddictClientWebIntegrationHandlers
* Revocation processing:
*/
OverrideRevocationEndpointClientAuthenticationMethod.Descriptor,
AttachAdditionalRevocationRequestParameters.Descriptor,
AttachNonStandardRevocationClientAssertionClaims.Descriptor,
AttachRevocationRequestNonStandardClientCredentials.Descriptor,

Expand Down Expand Up @@ -1962,6 +1961,27 @@ public ValueTask HandleAsync(ProcessChallengeContext context)
context.Request["language"] = settings.Language;
}

// Yandex allows sending optional "device_id" and "device_name" parameters.
else if (context.Registration.ProviderType is ProviderTypes.Yandex)
{
var settings = context.Registration.GetYandexSettings();

if (!context.Properties.TryGetValue(Yandex.Properties.DeviceId, out string? identifier) ||
string.IsNullOrEmpty(identifier))
{
identifier = settings.DeviceId;
}

if (!context.Properties.TryGetValue(Yandex.Properties.DeviceName, out string? name) ||
string.IsNullOrEmpty(name))
{
name = settings.DeviceName;
}

context.Request["device_id"] = identifier;
context.Request["device_name"] = name;
}

// By default, Zoho doesn't return a refresh token but
// allows sending an "access_type" parameter to retrieve one.
else if (context.Registration.ProviderType is ProviderTypes.Zoho)
Expand Down Expand Up @@ -2014,49 +2034,6 @@ public ValueTask HandleAsync(ProcessRevocationContext context)
}
}

/// <summary>
/// Contains the logic responsible for attaching additional parameters
/// to the revocation request for the providers that require it.
/// </summary>
public sealed class AttachAdditionalRevocationRequestParameters : IOpenIddictClientHandler<ProcessRevocationContext>
{
/// <summary>
/// Gets the default descriptor definition assigned to this handler.
/// </summary>
public static OpenIddictClientHandlerDescriptor Descriptor { get; }
= OpenIddictClientHandlerDescriptor.CreateBuilder<ProcessRevocationContext>()
.UseSingletonHandler<AttachAdditionalRevocationRequestParameters>()
.SetOrder(AttachRevocationRequestParameters.Descriptor.Order + 500)
.SetType(OpenIddictClientHandlerType.BuiltIn)
.Build();

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

Debug.Assert(context.RevocationRequest is not null, SR.GetResourceString(SR.ID4008));

// Yandex requires attaching a non-standard "device_id" parameter to revocation requests.
// This parameter must be manually provided by the application via an authentication property.
if (context.Registration.ProviderType is ProviderTypes.Yandex)
{
if (!context.Properties.TryGetValue(VkId.Properties.DeviceId, out string? identifier) ||
string.IsNullOrEmpty(identifier))
{
throw new InvalidOperationException(SR.GetResourceString(SR.ID0467));
}

context.RevocationRequest["device_id"] = identifier;
}

return default;
}
}

/// <summary>
/// Contains the logic responsible for adding non-standard claims to the client
/// assertions used for the revocation endpoint for the providers that require it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2237,6 +2237,15 @@
<GrantType Value="refresh_token" />
</Configuration>
</Environment>

<Property Name="DeviceId" DictionaryKey=".device_id" />
<Property Name="DeviceName" DictionaryKey=".device_name" />

<Setting PropertyName="DeviceId" ParameterName="identifier" Type="String" Required="false"
Description="Gets or sets the optional device identifier that will be attached to authorization requests" />

<Setting PropertyName="DeviceName" ParameterName="name" Type="String" Required="false"
Description="Gets or sets the optional device name that will be attached to authorization requests" />
</Provider>

<!--
Expand Down

0 comments on commit d9732c8

Please sign in to comment.