From e1b0ea235d5d0bf5a5bdcdb56e2d0de411ffb647 Mon Sep 17 00:00:00 2001 From: Ge Date: Wed, 19 Jun 2024 23:06:50 +0800 Subject: [PATCH] Add Weibo to the list of supported providers --- ...OpenIddictClientWebIntegrationGenerator.cs | 18 ++++++++++ ...ctClientWebIntegrationHandlers.Userinfo.cs | 3 +- .../OpenIddictClientWebIntegrationHandlers.cs | 33 +++++++++++++++++-- ...penIddictClientWebIntegrationProviders.xml | 27 +++++++++++++++ ...penIddictClientWebIntegrationProviders.xsd | 1 + 5 files changed, 78 insertions(+), 4 deletions(-) diff --git a/gen/OpenIddict.Client.WebIntegration.Generators/OpenIddictClientWebIntegrationGenerator.cs b/gen/OpenIddict.Client.WebIntegration.Generators/OpenIddictClientWebIntegrationGenerator.cs index 2b759c36..58071800 100644 --- a/gen/OpenIddict.Client.WebIntegration.Generators/OpenIddictClientWebIntegrationGenerator.cs +++ b/gen/OpenIddict.Client.WebIntegration.Generators/OpenIddictClientWebIntegrationGenerator.cs @@ -688,6 +688,17 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder .OfType() .SingleOrDefault() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0066))); } + {{~ else if setting.clr_type == 'bool' ~}} + /// + /// Configures {{ setting.description }}. + /// + /// {{ setting.description | string.capitalize }}. + /// The instance. + {{~ if setting.obsolete ~}} + [Obsolete(""This option is no longer supported and will be removed in a future version."")] + {{~ end ~}} + public {{ provider.name }} Set{{ setting.property_name }}(bool {{ setting.parameter_name }}) + => Set(registration => registration.Get{{ provider.name }}Settings().{{ setting.property_name }} = {{ setting.parameter_name }}); {{~ else ~}} /// /// Configures {{ setting.description }}. @@ -772,6 +783,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder char.ToLower(description[0], CultureInfo.GetCultureInfo("en-US")) + description[1..] : null, ClrType = (string) setting.Attribute("Type") switch { + "Boolean" => "bool", "EncryptionKey" when (string) setting.Element("EncryptionAlgorithm").Attribute("Value") is "RS256" or "RS384" or "RS512" => "RsaSecurityKey", @@ -906,6 +918,11 @@ public sealed partial class OpenIddictClientWebIntegrationConfiguration { settings.{{ setting.property_name }} = new Uri(""{{ setting.default_value }}"", UriKind.RelativeOrAbsolute); } + {{~ else if setting.type == 'Boolean' ~}} + if (settings.{{ setting.property_name }} is null) + { + settings.{{ setting.property_name }} = {{ setting.default_value }}; + } {{~ end ~}} {{~ end ~}} @@ -1354,6 +1371,7 @@ public sealed partial class OpenIddictClientWebIntegrationSettings char.ToLower(description[0], CultureInfo.GetCultureInfo("en-US")) + description[1..] : null, ClrType = (string) setting.Attribute("Type") switch { + "Boolean" => "bool", "EncryptionKey" when (string) setting.Element("EncryptionAlgorithm").Attribute("Value") is "RS256" or "RS384" or "RS512" => "RsaSecurityKey", diff --git a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Userinfo.cs b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Userinfo.cs index 55852383..9db80547 100644 --- a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Userinfo.cs +++ b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Userinfo.cs @@ -176,7 +176,8 @@ public static partial class OpenIddictClientWebIntegrationHandlers // or using a non-standard authentication scheme (e.g OAuth instead of Bearer). // These providers require sending the access token as part of the request payload. - if (context.Registration.ProviderType is ProviderTypes.Deezer or ProviderTypes.Mixcloud or ProviderTypes.StackExchange) + if (context.Registration.ProviderType is + ProviderTypes.Deezer or ProviderTypes.Mixcloud or ProviderTypes.StackExchange or ProviderTypes.Weibo) { context.Request.AccessToken = request.Headers.Authorization?.Parameter; diff --git a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.cs b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.cs index 1c1d4e6d..966d6aef 100644 --- a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.cs +++ b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.cs @@ -1019,6 +1019,12 @@ public static partial class OpenIddictClientWebIntegrationHandlers context.UserinfoRequest["user.fields"] = string.Join(",", settings.UserFields); } + // Weibo requires sending the user identifier as part of the userinfo request. + else if (context.Registration.ProviderType is ProviderTypes.Weibo) + { + context.UserinfoRequest["uid"] = context.TokenResponse?["uid"]; + } + return default; } } @@ -1297,7 +1303,8 @@ public static partial class OpenIddictClientWebIntegrationHandlers ProviderTypes.Lichess or ProviderTypes.Mastodon or ProviderTypes.Meetup or ProviderTypes.Nextcloud or ProviderTypes.Patreon or ProviderTypes.Reddit or ProviderTypes.Smartsheet or ProviderTypes.Spotify or ProviderTypes.SubscribeStar or - ProviderTypes.Todoist or ProviderTypes.Twitter or ProviderTypes.Zoom + ProviderTypes.Todoist or ProviderTypes.Twitter or ProviderTypes.Weibo or + ProviderTypes.Zoom => (string?) context.UserinfoResponse?["id"], // Bitbucket returns the user identifier as a custom "uuid" node: @@ -1522,8 +1529,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.Disqus or ProviderTypes.Shopify or - ProviderTypes.Strava or ProviderTypes.Todoist + ProviderTypes.Deezer or ProviderTypes.Disqus or ProviderTypes.Shopify or + ProviderTypes.Strava or ProviderTypes.Todoist or ProviderTypes.Weibo => string.Join(",", context.Scopes), // The following providers are known to use plus-separated scopes instead of @@ -1712,6 +1719,18 @@ public static partial class OpenIddictClientWebIntegrationHandlers context.Request["team"] = settings.Team; } + // Weibo allows sending an optional "display" parameter to adjust the authorization page + // display style; an optional "forcelogin" parameter to force the user to log in again; + // and an optional "language" parameter to set the language of the authorization page. + else if (context.Registration.ProviderType is ProviderTypes.Weibo) + { + var settings = context.Registration.GetWeiboSettings(); + + context.Request["display"] = settings.Display; + context.Request["forcelogin"] = settings.ForceLogin; + context.Request["language"] = settings.Language; + } + return default; } } @@ -1802,6 +1821,14 @@ public static partial class OpenIddictClientWebIntegrationHandlers context.RevocationRequest.ClientAssertionType = null; } + // Weibo implements a non-standard client authentication method for its endpoints that + // requires sending the token as "access_token" instead of the standard "token" parameter. + if (context.Registration.ProviderType is ProviderTypes.Weibo) + { + context.RevocationRequest.AccessToken = context.RevocationRequest.Token; + context.RevocationRequest.Token = null; + } + return default; } } diff --git a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationProviders.xml b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationProviders.xml index 71d8cf56..7beaf2d6 100644 --- a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationProviders.xml +++ b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationProviders.xml @@ -1938,6 +1938,33 @@ + + + + + + + + + + + + + +