From ad3cb994c2bdc9827b49bea32d56dce671fc95e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Chalet?= Date: Fri, 23 Feb 2024 22:05:57 +0100 Subject: [PATCH] Add Meetup to the list of supported providers --- ...ctClientWebIntegrationHandlers.Userinfo.cs | 17 ++++++--- .../OpenIddictClientWebIntegrationHandlers.cs | 28 ++++++++------ ...penIddictClientWebIntegrationProviders.xml | 38 +++++++++++++++++++ 3 files changed, 65 insertions(+), 18 deletions(-) diff --git a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Userinfo.cs b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Userinfo.cs index ca2737d7..0d42ede3 100644 --- a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Userinfo.cs +++ b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Userinfo.cs @@ -69,8 +69,9 @@ public static partial class OpenIddictClientWebIntegrationHandlers request.Method = context.Registration.ProviderType switch { - // SubscribeStar's userinfo implementation is based on GraphQL, which requires using POST. - ProviderTypes.SubscribeStar => HttpMethod.Post, + // The userinfo endpoints exposed by these providers + // are based on GraphQL, which requires using POST: + ProviderTypes.Meetup or ProviderTypes.SubscribeStar => HttpMethod.Post, _ => request.Method }; @@ -266,10 +267,10 @@ public static partial class OpenIddictClientWebIntegrationHandlers request.Content = context.Registration.ProviderType switch { - // SubscribeStar's userinfo implementation is based on GraphQL, - // which requires sending the request parameters as a JSON payload. - ProviderTypes.SubscribeStar => JsonContent.Create(context.Transaction.Request, - new MediaTypeHeaderValue(MediaTypes.Json) + // The userinfo endpoints exposed by these providers are based on GraphQL, + // which requires sending the request parameters as a JSON payload: + ProviderTypes.Meetup or ProviderTypes.SubscribeStar + => JsonContent.Create(context.Transaction.Request, new MediaTypeHeaderValue(MediaTypes.Json) { CharSet = Charsets.Utf8 }), @@ -398,6 +399,10 @@ public static partial class OpenIddictClientWebIntegrationHandlers => new(context.Response["data"]?.GetNamedParameters() ?? throw new InvalidOperationException(SR.FormatID0334("data"))), + // Meetup returns a nested "self" object that is itself nested in a GraphQL "data" node. + ProviderTypes.Meetup => new(context.Response["data"]?["self"]?.GetNamedParameters() ?? + throw new InvalidOperationException(SR.FormatID0334("data/self"))), + // Nextcloud returns a nested "data" object that is itself nested in a "ocs" node. ProviderTypes.Nextcloud => new(context.Response["ocs"]?["data"]?.GetNamedParameters() ?? throw new InvalidOperationException(SR.FormatID0334("ocs/data"))), diff --git a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.cs b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.cs index 78a3cff1..ff21f513 100644 --- a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.cs +++ b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.cs @@ -885,6 +885,15 @@ public static partial class OpenIddictClientWebIntegrationHandlers context.UserinfoRequest["fields"] = string.Join(",", settings.Fields); } + // Meetup's userinfo endpoint is a GraphQL implementation that requires + // sending a proper "query" parameter containing the requested user details. + else if (context.Registration.ProviderType is ProviderTypes.Meetup) + { + var settings = context.Registration.GetMeetupSettings(); + + context.UserinfoRequest["query"] = $"query {{ self {{ {string.Join(" ", settings.UserFields)} }} }}"; + } + // Patreon 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. @@ -1118,12 +1127,6 @@ public static partial class OpenIddictClientWebIntegrationHandlers context.UserinfoResponse?.HasParameter("last_name") is true => $"{(string?) context.UserinfoResponse?["first_name"]} {(string?) context.UserinfoResponse?["last_name"]}", - // These providers return the username as a custom "name" node: - ProviderTypes.Deezer or ProviderTypes.Facebook or ProviderTypes.GitHub or - ProviderTypes.Reddit or ProviderTypes.SubscribeStar or ProviderTypes.Twitter or - ProviderTypes.Vimeo - => (string?) context.UserinfoResponse?["name"], - // FitBit returns the username as a custom "displayName" node: ProviderTypes.Fitbit => (string?) context.UserinfoResponse?["displayName"], @@ -1189,12 +1192,13 @@ 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.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 + 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.Meetup 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: diff --git a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationProviders.xml b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationProviders.xml index f8dbd062..3462ba96 100644 --- a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationProviders.xml +++ b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationProviders.xml @@ -779,6 +779,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + +