diff --git a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Userinfo.cs b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Userinfo.cs index 9aeefeed..b9f4d6c6 100644 --- a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Userinfo.cs +++ b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Userinfo.cs @@ -202,7 +202,8 @@ public static partial class OpenIddictClientWebIntegrationHandlers response.Content.Headers.ContentType = context.Registration.ProviderName switch { Providers.Mixcloud or // Mixcloud returns JSON-formatted contents declared as "text/javascript". - Providers.Vimeo // Vimeo returns JSON-formatted contents declared as "application/vnd.vimeo.user+json". + Providers.Patreon or // Patreon returns JSON-formatted contents declared as "application/vnd.api+json". + Providers.Vimeo // Vimeo returns JSON-formatted contents declared as "application/vnd.vimeo.user+json". => new MediaTypeHeaderValue(MediaTypes.Json) { CharSet = Charsets.Utf8 @@ -253,6 +254,11 @@ public static partial class OpenIddictClientWebIntegrationHandlers is { ValueKind: JsonValueKind.Object } element ? new(element) : throw new InvalidOperationException(SR.FormatID0334("user")), + // Patreon returns a nested "attributes" object that is itself nested in a "data" node. + Providers.Patreon => (JsonElement) context.Response["data"]?["attributes"] + is { ValueKind: JsonValueKind.Object } element ? + new(element) : throw new InvalidOperationException(SR.FormatID0334("attributes")), + // StackExchange returns an "items" array containing a single element. Providers.StackExchange => (JsonElement) context.Response["items"] is { ValueKind: JsonValueKind.Array } element && element.GetArrayLength() is 1 ? diff --git a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.cs b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.cs index f65fa7ce..7b47aa51 100644 --- a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.cs +++ b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.cs @@ -393,6 +393,16 @@ public static partial class OpenIddictClientWebIntegrationHandlers context.UserinfoRequest["projection"] = string.Concat("(", string.Join(",", options.Fields), ")"); } + // 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. + else if (context.Registration.ProviderName is Providers.Patreon) + { + var options = context.Registration.GetPatreonOptions(); + + context.UserinfoRequest["fields[user]"] = string.Join(",", options.UserFields); + } + // StackOverflow requires sending an application key and a site parameter // containing the name of the site from which the user profile is retrieved. else if (context.Registration.ProviderName is Providers.StackExchange) diff --git a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationProviders.xml b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationProviders.xml index 28ccf92c..ea1dd594 100644 --- a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationProviders.xml +++ b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationProviders.xml @@ -368,6 +368,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + +