From 26be4d95a70df60d65b3194d677f90067e95a26e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Chalet?= Date: Fri, 23 Feb 2024 15:14:06 +0100 Subject: [PATCH] Add Disqus to the list of supported providers --- ...ctClientWebIntegrationHandlers.Userinfo.cs | 4 +++ .../OpenIddictClientWebIntegrationHandlers.cs | 28 ++++++++++++------- ...penIddictClientWebIntegrationProviders.xml | 19 +++++++++++++ 3 files changed, 41 insertions(+), 10 deletions(-) diff --git a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Userinfo.cs b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Userinfo.cs index 82403717..ca2737d7 100644 --- a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Userinfo.cs +++ b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Userinfo.cs @@ -374,6 +374,10 @@ public static partial class OpenIddictClientWebIntegrationHandlers ["accounts"] = context.Response["accounts"] }, + // Disqus returns a nested "response" object. + ProviderTypes.Disqus => new(context.Response["response"]?.GetNamedParameters() ?? + throw new InvalidOperationException(SR.FormatID0334("response"))), + // Exact Online returns a "results" array nested in a "d" node and containing a single element. ProviderTypes.ExactOnline => new(context.Response["d"]?["results"]?[0]?.GetNamedParameters() ?? throw new InvalidOperationException(SR.FormatID0334("d/results/0"))), diff --git a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.cs b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.cs index 6aa8be65..78a3cff1 100644 --- a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.cs +++ b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.cs @@ -868,6 +868,13 @@ public static partial class OpenIddictClientWebIntegrationHandlers context.UserinfoRequest["fields"] = string.Join(",", settings.UserFields); } + // Disqus requires sending the client identifier (called "public + // API key" in the documentation) as part of the userinfo request. + else if (context.Registration.ProviderType is ProviderTypes.Disqus) + { + context.UserinfoRequest["api_key"] = context.Registration.ClientId; + } + // Facebook limits the number of fields returned by the userinfo endpoint // but allows returning additional information using special parameters that // determine what fields will be returned as part of the userinfo response. @@ -1100,9 +1107,9 @@ public static partial class OpenIddictClientWebIntegrationHandlers context.MergedPrincipal.SetClaim(ClaimTypes.Name, issuer: issuer, value: context.Registration.ProviderType switch { // These providers return the username as a custom "username" node: - ProviderTypes.ArcGisOnline or ProviderTypes.Dailymotion or ProviderTypes.Discord or - ProviderTypes.DeviantArt or ProviderTypes.Lichess or ProviderTypes.Mixcloud or - ProviderTypes.Trakt or ProviderTypes.WordPress + ProviderTypes.ArcGisOnline or ProviderTypes.Dailymotion or ProviderTypes.DeviantArt or + ProviderTypes.Discord or ProviderTypes.Disqus or ProviderTypes.Lichess or + ProviderTypes.Mixcloud or ProviderTypes.Trakt or ProviderTypes.WordPress => (string?) context.UserinfoResponse?["username"], // Basecamp and Harvest don't return a username so one is created using the "first_name" and "last_name" nodes: @@ -1182,12 +1189,12 @@ public static partial class OpenIddictClientWebIntegrationHandlers => (string?) context.UserinfoResponse?["username"], // These providers return the user identifier as a custom "id" node: - ProviderTypes.Basecamp or ProviderTypes.Dailymotion or ProviderTypes.Deezer or - ProviderTypes.Discord or ProviderTypes.Facebook or ProviderTypes.GitHub or - ProviderTypes.Harvest or ProviderTypes.Kroger or ProviderTypes.Lichess or - ProviderTypes.Nextcloud or ProviderTypes.Patreon or ProviderTypes.Reddit or - ProviderTypes.Smartsheet or ProviderTypes.Spotify or ProviderTypes.SubscribeStar or - ProviderTypes.Twitter or ProviderTypes.Zoom + ProviderTypes.Basecamp or ProviderTypes.Dailymotion or ProviderTypes.Deezer or + ProviderTypes.Discord or ProviderTypes.Disqus or ProviderTypes.Facebook or + ProviderTypes.GitHub or ProviderTypes.Harvest or ProviderTypes.Kroger or + ProviderTypes.Lichess or ProviderTypes.Nextcloud or ProviderTypes.Patreon or + ProviderTypes.Reddit or ProviderTypes.Smartsheet or ProviderTypes.Spotify or + ProviderTypes.SubscribeStar or ProviderTypes.Twitter or ProviderTypes.Zoom => (string?) context.UserinfoResponse?["id"], // Bitbucket returns the user identifier as a custom "uuid" node: @@ -1408,7 +1415,8 @@ public static partial class OpenIddictClientWebIntegrationHandlers { // The following providers are known to use comma-separated scopes instead of // the standard format (that requires using a space as the scope separator): - ProviderTypes.Deezer or ProviderTypes.Shopify or ProviderTypes.Strava + ProviderTypes.Deezer or ProviderTypes.Disqus or + ProviderTypes.Shopify or ProviderTypes.Strava => string.Join(",", context.Scopes), // The following providers are known to use plus-separated scopes instead of diff --git a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationProviders.xml b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationProviders.xml index b3ad8e9d..14e85645 100644 --- a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationProviders.xml +++ b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationProviders.xml @@ -393,6 +393,25 @@ + + + + + + + + + + +