From 714bbe5a54dbb02b158c8fcd4c89bc91d29486b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Chalet?= Date: Tue, 10 Jun 2025 00:56:29 +0200 Subject: [PATCH] Add Bungie.net to the list of supported providers --- ...ctClientWebIntegrationHandlers.Userinfo.cs | 14 ++++++++++- .../OpenIddictClientWebIntegrationHandlers.cs | 9 +++++--- ...penIddictClientWebIntegrationProviders.xml | 23 +++++++++++++++++++ 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Userinfo.cs b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Userinfo.cs index bd21d664..b83adfbc 100644 --- a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Userinfo.cs +++ b/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"))), diff --git a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.cs b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.cs index da5ac6d1..5218a941 100644 --- a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.cs +++ b/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"], diff --git a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationProviders.xml b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationProviders.xml index 02b6160c..0ad5422d 100644 --- a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationProviders.xml +++ b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationProviders.xml @@ -384,6 +384,29 @@ + + + + + + + + + + + + +