Browse Source

Add Bungie.net to the list of supported providers

pull/2345/head
Kévin Chalet 8 months ago
parent
commit
714bbe5a54
  1. 14
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Userinfo.cs
  2. 9
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.cs
  3. 23
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationProviders.xml

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

@ -116,9 +116,17 @@ public static partial class OpenIddictClientWebIntegrationHandlers
var request = context.Transaction.GetHttpRequestMessage() ??
throw new InvalidOperationException(SR.GetResourceString(SR.ID0173));
// Bungie.net requires sending a static API key.
if (context.Registration.ProviderType is ProviderTypes.BungieNet)
{
var settings = context.Registration.GetBungieNetSettings();
request.Headers.Add("X-API-Key", settings.ApplicationKey);
}
// Notion requires sending an explicit API version (which is statically set
// to the last version known to be supported by the OpenIddict integration).
if (context.Registration.ProviderType is ProviderTypes.Notion)
else if (context.Registration.ProviderType is ProviderTypes.Notion)
{
request.Headers.Add("Notion-Version", "2022-06-28");
}
@ -403,6 +411,10 @@ public static partial class OpenIddictClientWebIntegrationHandlers
["accounts"] = context.Response["accounts"]
},
// Bungie.net returns a nested "bungieNetUser" object that is itself nested in a "Response" object.
ProviderTypes.BungieNet => new(context.Response["Response"]?["bungieNetUser"]?.GetNamedParameters() ??
throw new InvalidOperationException(SR.FormatID0334("Response/bungieNetUser"))),
// Calendly returns a nested "resource" object.
ProviderTypes.Calendly => new(context.Response["resource"]?.GetNamedParameters() ??
throw new InvalidOperationException(SR.FormatID0334("resource"))),

9
src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.cs

@ -1442,15 +1442,15 @@ public static partial class OpenIddictClientWebIntegrationHandlers
context.UserInfoResponse?.HasParameter("last_name") is true
=> $"{(string?) context.UserInfoResponse?["first_name"]} {(string?) context.UserInfoResponse?["last_name"]}",
// BungieNet and FitBit return the username as a custom "displayName" node:
ProviderTypes.BungieNet or ProviderTypes.Fitbit => (string?) context.UserInfoResponse?["displayName"],
// These providers don't return a username so one is created using the "firstName" and "lastName" nodes:
ProviderTypes.Contentful or ProviderTypes.Smartsheet
when context.UserInfoResponse?.HasParameter("firstName") is true &&
context.UserInfoResponse?.HasParameter("lastName") is true
=> $"{(string?) context.UserInfoResponse?["firstName"]} {(string?) context.UserInfoResponse?["lastName"]}",
// FitBit returns the username as a custom "displayName" node:
ProviderTypes.Fitbit => (string?) context.UserInfoResponse?["displayName"],
// Huawei returns the username as a custom "display_name" in the backchannel identity token:
ProviderTypes.Huawei => context.BackchannelIdentityTokenPrincipal?.GetClaim("display_name"),
@ -1544,6 +1544,9 @@ public static partial class OpenIddictClientWebIntegrationHandlers
// Bitly returns the user identifier as a custom "login" node:
ProviderTypes.Bitly => (string?) context.UserInfoResponse?["login"],
// BungieNet returns the user identifier as a custom "membershipId" node:
ProviderTypes.BungieNet => (string?) context.UserInfoResponse?["membershipId"],
// Calendly returns the user identifier (formatted as a URI) as a custom "uri" node:
ProviderTypes.Calendly => (string?) context.UserInfoResponse?["uri"],

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

@ -384,6 +384,29 @@
</Environment>
</Provider>
<!--
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
██ ▄▄▀██ ██ ██ ▀██ ██ ▄▄ █▄ ▄██ ▄▄▄█████ ▀██ ██ ▄▄▄█▄▄ ▄▄██
██ ▄▄▀██ ██ ██ █ █ ██ █▀▀██ ███ ▄▄▄█▀▀██ █ █ ██ ▄▄▄███ ████
██ ▀▀ ██▄▀▀▄██ ██▄ ██ ▀▀▄█▀ ▀██ ▀▀▀█▄▄██ ██▄ ██ ▀▀▀███ ████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
-->
<Provider Name="BungieNet" DisplayName="Bungie.net" Id="30dc52f6-84b0-49ca-b48a-f843fcd81e79"
Documentation="https://github.com/Bungie-net/api/wiki/OAuth-Documentation">
<Environment Issuer="https://www.bungie.net/">
<Configuration AuthorizationEndpoint="https://www.bungie.net/en/OAuth/Authorize"
TokenEndpoint="https://www.bungie.net/Platform/App/OAuth/token/"
UserInfoEndpoint="https://www.bungie.net/Platform/User/GetMembershipsForCurrentUser/">
<GrantType Value="authorization_code" />
<GrantType Value="refresh_token" />
</Configuration>
</Environment>
<Setting PropertyName="ApplicationKey" ParameterName="key" Type="String" Required="true"
Description="The application key used to communicate with the Bungie.net API" />
</Provider>
<!--
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
██ ▄▄▀█ ▄▄▀██ █████ ▄▄▄██ ▀██ ██ ▄▄▀██ █████ ███ ██

Loading…
Cancel
Save