Skip to content

Commit d9732c8

Browse files
committed
Update the Yandex provider to allow specifying a device_id/device_name
1 parent ac02954 commit d9732c8

File tree

2 files changed

+30
-44
lines changed

2 files changed

+30
-44
lines changed

src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.cs

Lines changed: 21 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ public static partial class OpenIddictClientWebIntegrationHandlers
5454
* Revocation processing:
5555
*/
5656
OverrideRevocationEndpointClientAuthenticationMethod.Descriptor,
57-
AttachAdditionalRevocationRequestParameters.Descriptor,
5857
AttachNonStandardRevocationClientAssertionClaims.Descriptor,
5958
AttachRevocationRequestNonStandardClientCredentials.Descriptor,
6059

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

1964+
// Yandex allows sending optional "device_id" and "device_name" parameters.
1965+
else if (context.Registration.ProviderType is ProviderTypes.Yandex)
1966+
{
1967+
var settings = context.Registration.GetYandexSettings();
1968+
1969+
if (!context.Properties.TryGetValue(Yandex.Properties.DeviceId, out string? identifier) ||
1970+
string.IsNullOrEmpty(identifier))
1971+
{
1972+
identifier = settings.DeviceId;
1973+
}
1974+
1975+
if (!context.Properties.TryGetValue(Yandex.Properties.DeviceName, out string? name) ||
1976+
string.IsNullOrEmpty(name))
1977+
{
1978+
name = settings.DeviceName;
1979+
}
1980+
1981+
context.Request["device_id"] = identifier;
1982+
context.Request["device_name"] = name;
1983+
}
1984+
19651985
// By default, Zoho doesn't return a refresh token but
19661986
// allows sending an "access_type" parameter to retrieve one.
19671987
else if (context.Registration.ProviderType is ProviderTypes.Zoho)
@@ -2014,49 +2034,6 @@ public ValueTask HandleAsync(ProcessRevocationContext context)
20142034
}
20152035
}
20162036

2017-
/// <summary>
2018-
/// Contains the logic responsible for attaching additional parameters
2019-
/// to the revocation request for the providers that require it.
2020-
/// </summary>
2021-
public sealed class AttachAdditionalRevocationRequestParameters : IOpenIddictClientHandler<ProcessRevocationContext>
2022-
{
2023-
/// <summary>
2024-
/// Gets the default descriptor definition assigned to this handler.
2025-
/// </summary>
2026-
public static OpenIddictClientHandlerDescriptor Descriptor { get; }
2027-
= OpenIddictClientHandlerDescriptor.CreateBuilder<ProcessRevocationContext>()
2028-
.UseSingletonHandler<AttachAdditionalRevocationRequestParameters>()
2029-
.SetOrder(AttachRevocationRequestParameters.Descriptor.Order + 500)
2030-
.SetType(OpenIddictClientHandlerType.BuiltIn)
2031-
.Build();
2032-
2033-
/// <inheritdoc/>
2034-
public ValueTask HandleAsync(ProcessRevocationContext context)
2035-
{
2036-
if (context is null)
2037-
{
2038-
throw new ArgumentNullException(nameof(context));
2039-
}
2040-
2041-
Debug.Assert(context.RevocationRequest is not null, SR.GetResourceString(SR.ID4008));
2042-
2043-
// Yandex requires attaching a non-standard "device_id" parameter to revocation requests.
2044-
// This parameter must be manually provided by the application via an authentication property.
2045-
if (context.Registration.ProviderType is ProviderTypes.Yandex)
2046-
{
2047-
if (!context.Properties.TryGetValue(VkId.Properties.DeviceId, out string? identifier) ||
2048-
string.IsNullOrEmpty(identifier))
2049-
{
2050-
throw new InvalidOperationException(SR.GetResourceString(SR.ID0467));
2051-
}
2052-
2053-
context.RevocationRequest["device_id"] = identifier;
2054-
}
2055-
2056-
return default;
2057-
}
2058-
}
2059-
20602037
/// <summary>
20612038
/// Contains the logic responsible for adding non-standard claims to the client
20622039
/// assertions used for the revocation endpoint for the providers that require it.

src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationProviders.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2237,6 +2237,15 @@
22372237
<GrantType Value="refresh_token" />
22382238
</Configuration>
22392239
</Environment>
2240+
2241+
<Property Name="DeviceId" DictionaryKey=".device_id" />
2242+
<Property Name="DeviceName" DictionaryKey=".device_name" />
2243+
2244+
<Setting PropertyName="DeviceId" ParameterName="identifier" Type="String" Required="false"
2245+
Description="Gets or sets the optional device identifier that will be attached to authorization requests" />
2246+
2247+
<Setting PropertyName="DeviceName" ParameterName="name" Type="String" Required="false"
2248+
Description="Gets or sets the optional device name that will be attached to authorization requests" />
22402249
</Provider>
22412250

22422251
<!--

0 commit comments

Comments
 (0)