Browse Source

Add Streamlabs to the list of supported providers

pull/1721/head
Kévin Chalet 3 years ago
parent
commit
bd72f47db0
  1. 30
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Userinfo.cs
  2. 19
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationProviders.xml

30
src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Userinfo.cs

@ -7,7 +7,6 @@
using System.Collections.Immutable;
using System.Diagnostics;
using System.Net.Http.Headers;
using System.Text.Json;
using static OpenIddict.Client.SystemNetHttp.OpenIddictClientSystemNetHttpConstants;
using static OpenIddict.Client.SystemNetHttp.OpenIddictClientSystemNetHttpHandlerFilters;
using static OpenIddict.Client.SystemNetHttp.OpenIddictClientSystemNetHttpHandlers;
@ -250,24 +249,29 @@ public static partial class OpenIddictClientWebIntegrationHandlers
context.Response = context.Registration.ProviderName switch
{
// Fitbit returns a nested "user" object.
Providers.Fitbit => (JsonElement) context.Response["user"]
is { ValueKind: JsonValueKind.Object } element ?
new(element) : throw new InvalidOperationException(SR.FormatID0334("user")),
Providers.Fitbit => new(context.Response["user"]?.GetNamedParameters() ??
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")),
Providers.Patreon => new(context.Response["data"]?["attributes"]?.GetNamedParameters() ??
throw new InvalidOperationException(SR.FormatID0334("data/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 ?
new(element[0]) : throw new InvalidOperationException(SR.FormatID0334("items")),
Providers.StackExchange => new(context.Response["items"]?[0]?.GetNamedParameters() ??
throw new InvalidOperationException(SR.FormatID0334("items/0"))),
// Streamlabs splits the user data into multiple service-specific nodes (e.g "twitch"/"facebook").
//
// To make claims easier to use, the parameters are flattened and prefixed with the service name.
Providers.Streamlabs => new(
from parameter in context.Response.GetParameters()
from node in parameter.Value.GetNamedParameters()
let name = $"{parameter.Key}_{node.Key}"
select new KeyValuePair<string, OpenIddictParameter>(name, node.Value)),
// Twitter returns a nested "data" object.
Providers.Twitter => (JsonElement) context.Response["data"]
is { ValueKind: JsonValueKind.Object } element ?
new(element) : throw new InvalidOperationException(SR.FormatID0334("data")),
Providers.Twitter => new(context.Response["data"]?.GetNamedParameters() ??
throw new InvalidOperationException(SR.FormatID0334("data"))),
_ => context.Response
};

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

@ -594,6 +594,25 @@
Description="The type of the Stripe account (by default, 'standard', but can also be set to 'express')" />
</Provider>
<!--
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
██ ▄▄▄ █▄▄ ▄▄██ ▄▄▀██ ▄▄▄█ ▄▄▀██ ▄▀▄ ██ ████ ▄▄▀██ ▄▄▀██ ▄▄▄ ██
██▄▄▄▀▀███ ████ ▀▀▄██ ▄▄▄█ ▀▀ ██ █ █ ██ ████ ▀▀ ██ ▄▄▀██▄▄▄▀▀██
██ ▀▀▀ ███ ████ ██ ██ ▀▀▀█ ██ ██ ███ ██ ▀▀ █ ██ ██ ▀▀ ██ ▀▀▀ ██
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
-->
<Provider Name="Streamlabs" Documentation="https://dev.streamlabs.com/docs/oauth-2">
<Environment Issuer="https://streamlabs.com/">
<Configuration AuthorizationEndpoint="https://streamlabs.com/api/v2.0/authorize"
TokenEndpoint="https://streamlabs.com/api/v2.0/token"
UserinfoEndpoint="https://streamlabs.com/api/v2.0/user">
<GrantType Value="authorization_code" />
<GrantType Value="refresh_token" />
</Configuration>
</Environment>
</Provider>
<!--
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
█▄▄ ▄▄██ ▄▄▀█ ▄▄▀██ █▀▄█▄▄ ▄▄██

Loading…
Cancel
Save