Browse Source

Add Wikimedia to the list of supported providers

pull/2035/head
Kévin Chalet 2 years ago
parent
commit
1562d5be3b
  1. 6
      src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandlers.cs
  2. 59
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Userinfo.cs
  3. 21
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationProviders.xml

6
src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreHandlers.cs

@ -425,7 +425,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
throw new InvalidOperationException(SR.GetResourceString(SR.ID0354));
}
// Resolve the cookie builder from the OWIN integration options.
// Resolve the cookie builder from the ASP.NET Core integration options.
var builder = _options.CurrentValue.CookieBuilder;
// Compute the name of the cookie name based on the prefix and the random nonce.
@ -741,7 +741,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
var response = context.Transaction.GetHttpRequest()?.HttpContext.Response ??
throw new InvalidOperationException(SR.GetResourceString(SR.ID0114));
// Resolve the cookie builder from the OWIN integration options.
// Resolve the cookie builder from the ASP.NET Core integration options.
var builder = _options.CurrentValue.CookieBuilder;
// Unless a value was explicitly set in the options, use the expiration date
@ -980,7 +980,7 @@ public static partial class OpenIddictClientAspNetCoreHandlers
var response = context.Transaction.GetHttpRequest()?.HttpContext.Response ??
throw new InvalidOperationException(SR.GetResourceString(SR.ID0114));
// Resolve the cookie builder from the OWIN integration options.
// Resolve the cookie builder from the ASP.NET Core integration options.
var builder = _options.CurrentValue.CookieBuilder;
// Unless a value was explicitly set in the options, use the expiration date

59
src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Userinfo.cs

@ -35,7 +35,8 @@ public static partial class OpenIddictClientWebIntegrationHandlers
* Userinfo response extraction:
*/
NormalizeContentType.Descriptor,
UnwrapUserinfoResponse.Descriptor
UnwrapUserinfoResponse.Descriptor,
MapNonStandardResponseParameters.Descriptor,
]);
/// <summary>
@ -323,10 +324,22 @@ public static partial class OpenIddictClientWebIntegrationHandlers
response.Content.Headers.ContentType = context.Registration.ProviderType switch
{
// Mixcloud returns JSON-formatted contents declared as "text/javascript".
ProviderTypes.Mixcloud => new MediaTypeHeaderValue(MediaTypes.Json)
{
CharSet = Charsets.Utf8
},
ProviderTypes.Mixcloud when string.Equals(
response.Content.Headers.ContentType?.MediaType,
"text/javascript", StringComparison.OrdinalIgnoreCase)
=> new MediaTypeHeaderValue(MediaTypes.Json)
{
CharSet = Charsets.Utf8
},
// Wikimedia returns JSON-formatted contents declared as "text/html".
ProviderTypes.Wikimedia when string.Equals(
response.Content.Headers.ContentType?.MediaType,
"text/html", StringComparison.OrdinalIgnoreCase)
=> new MediaTypeHeaderValue(MediaTypes.Json)
{
CharSet = Charsets.Utf8
},
_ => response.Content.Headers.ContentType
};
@ -429,5 +442,41 @@ public static partial class OpenIddictClientWebIntegrationHandlers
return default;
}
}
/// <summary>
/// Contains the logic responsible for mapping non-standard response parameters
/// to their standard equivalent for the providers that require it.
/// </summary>
public sealed class MapNonStandardResponseParameters : IOpenIddictClientHandler<ExtractUserinfoResponseContext>
{
/// <summary>
/// Gets the default descriptor definition assigned to this handler.
/// </summary>
public static OpenIddictClientHandlerDescriptor Descriptor { get; }
= OpenIddictClientHandlerDescriptor.CreateBuilder<ExtractUserinfoResponseContext>()
.UseSingletonHandler<MapNonStandardResponseParameters>()
.SetOrder(UnwrapUserinfoResponse.Descriptor.Order + 1_000)
.SetType(OpenIddictClientHandlerType.BuiltIn)
.Build();
/// <inheritdoc/>
public ValueTask HandleAsync(ExtractUserinfoResponseContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(context.Response is not null, SR.GetResourceString(SR.ID4007));
// Note: Wikimedia returns a non-standard "sub" claim formatted as an integer instead of a string.
if (context.Registration.ProviderType is ProviderTypes.Wikimedia)
{
context.Response[Claims.Subject] = (string?) context.Response[Claims.Subject];
}
return default;
}
}
}
}

21
src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationProviders.xml

@ -1765,6 +1765,27 @@
<Environment Issuer="https://www.webex.com/" ConfigurationEndpoint="https://webexapis.com/v1/.well-known/openid-configuration" />
</Provider>
<!--
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
██ ███ █▄ ▄██ █▀▄█▄ ▄██ ▄▀▄ ██ ▄▄▄██ ▄▄▀█▄ ▄█ ▄▄▀██
██ █ █ ██ ███ ▄▀███ ███ █ █ ██ ▄▄▄██ ██ ██ ██ ▀▀ ██
██▄▀▄▀▄█▀ ▀██ ██ █▀ ▀██ ███ ██ ▀▀▀██ ▀▀ █▀ ▀█ ██ ██
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
-->
<Provider Name="Wikimedia" Id="84afac40-28e3-4072-b9cb-c94c883e0951"
Documentation="https://api.wikimedia.org/wiki/Authentication">
<Environment Issuer="https://www.wikimedia.org/">
<Configuration AuthorizationEndpoint="https://meta.wikimedia.org/w/rest.php/oauth2/authorize"
TokenEndpoint="https://meta.wikimedia.org/w/rest.php/oauth2/access_token"
UserinfoEndpoint="https://meta.wikimedia.org/w/rest.php/oauth2/resource/profile">
<GrantType Value="authorization_code" />
<GrantType Value="client_credentials" />
<GrantType Value="refresh_token" />
</Configuration>
</Environment>
</Provider>
<!--
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
██ ███ ██ ▄▄▄ ██ ▄▄▀██ ▄▄▀██ ▄▄ ██ ▄▄▀██ ▄▄▄██ ▄▄▄ ██ ▄▄▄ ██

Loading…
Cancel
Save