Browse Source

Add Patreon to the list of supported providers

pull/1719/head
Kévin Chalet 3 years ago
parent
commit
ba971314fe
  1. 8
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Userinfo.cs
  2. 10
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.cs
  3. 34
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationProviders.xml

8
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 ?

10
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)

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

@ -368,6 +368,40 @@
</Environment>
</Provider>
<!--
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
██ ▄▄ █ ▄▄▀█▄▄ ▄▄██ ▄▄▀██ ▄▄▄██ ▄▄▄ ██ ▀██ ██
██ ▀▀ █ ▀▀ ███ ████ ▀▀▄██ ▄▄▄██ ███ ██ █ █ ██
██ ████ ██ ███ ████ ██ ██ ▀▀▀██ ▀▀▀ ██ ██▄ ██
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
-->
<Provider Name="Patreon" Documentation="https://docs.patreon.com/#oauth">
<Environment Issuer="https://www.patreon.com/">
<Configuration AuthorizationEndpoint="https://www.patreon.com/oauth2/authorize"
TokenEndpoint="https://www.patreon.com/api/oauth2/token"
UserinfoEndpoint="https://www.patreon.com/api/oauth2/v2/identity">
<GrantType Value="authorization_code" />
<GrantType Value="refresh_token" />
</Configuration>
</Environment>
<Setting PropertyName="UserFields" ParameterName="fields" Collection="true" Type="String"
Description="The list of user fields to expand from the userinfo endpoint (by default, all known fields are requested)">
<Item Value="about" Default="true" Required="false" />
<Item Value="created" Default="true" Required="false" />
<Item Value="email" Default="true" Required="false" />
<Item Value="first_name" Default="true" Required="false" />
<Item Value="full_name" Default="true" Required="false" />
<Item Value="image_url" Default="true" Required="false" />
<Item Value="last_name" Default="true" Required="false" />
<Item Value="social_connections" Default="true" Required="false" />
<Item Value="thumb_url" Default="true" Required="false" />
<Item Value="url" Default="true" Required="false" />
<Item Value="vanity" Default="true" Required="false" />
</Setting>
</Provider>
<!--
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
██ ▄▄ █ ▄▄▀██ ███ ██ ▄▄ █ ▄▄▀██ █████

Loading…
Cancel
Save