From 080f9e6d340d229cc73b4661617f9fb58fa16e50 Mon Sep 17 00:00:00 2001 From: Gehongyan Date: Wed, 20 Aug 2025 18:01:47 +0800 Subject: [PATCH] Add HeyBoxChat to the list of supported providers Signed-off-by: Gehongyan --- ...ctClientWebIntegrationHandlers.Exchange.cs | 30 ++++++++++++++++++- ...ctClientWebIntegrationHandlers.Userinfo.cs | 12 ++++++++ ...penIddictClientWebIntegrationProviders.xml | 21 +++++++++++++ 3 files changed, 62 insertions(+), 1 deletion(-) diff --git a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Exchange.cs b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Exchange.cs index f061a2cb..e25654b3 100644 --- a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Exchange.cs +++ b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Exchange.cs @@ -12,6 +12,7 @@ using System.Net.Http.Headers; using System.Net.Http.Json; using System.Text; using System.Text.Json; +using Microsoft.Extensions.Primitives; using OpenIddict.Extensions; using static OpenIddict.Client.SystemNetHttp.OpenIddictClientSystemNetHttpConstants; using static OpenIddict.Client.SystemNetHttp.OpenIddictClientSystemNetHttpHandlerFilters; @@ -209,9 +210,17 @@ public static partial class OpenIddictClientWebIntegrationHandlers var request = context.Transaction.GetHttpRequestMessage() ?? throw new InvalidOperationException(SR.GetResourceString(SR.ID0173)); + // HeyBoxChat requires a "token" header containing the Bot token. + if (context.Registration.ProviderType is ProviderTypes.HeyBoxChat) + { + var settings = context.Registration.GetHeyBoxChatSettings(); + + request.Headers.Add("token", settings.Token); + } + // Trovo requires sending the client identifier in a non-standard "client-id" header and // the client secret in the payload (formatted using JSON instead of the standard format). - if (context.Registration.ProviderType is ProviderTypes.Trovo) + else if (context.Registration.ProviderType is ProviderTypes.Trovo) { request.Headers.Add("Client-ID", context.Request.ClientId); @@ -267,6 +276,25 @@ public static partial class OpenIddictClientWebIntegrationHandlers request.RequestUri, name: "output", value: "json"); } + // For API calls made by Bots to HeyBoxChat, a series of parameters need to be added + // to the query string to indicate that the request is coming from a Bot, rather than + // from a HeyBoxChat desktop client or web carrying user authorization information. + else if (context.Registration.ProviderType is ProviderTypes.HeyBoxChat) + { + request.RequestUri = OpenIddictHelpers.AddQueryStringParameters( + uri: request.RequestUri, + parameters: new Dictionary + { + ["chat_os_type"] = "bot", + ["chat_version"] = "1.30.0", + ["client_type"] = "heybox_chat", + ["os_type"] = "web", + ["x_app"] = "heybox_chat", + ["x_client_type"] = "web", + ["x_os_type"] = "bot" + }); + } + return default; } } diff --git a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Userinfo.cs b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Userinfo.cs index b83adfbc..7b07be45 100644 --- a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Userinfo.cs +++ b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Userinfo.cs @@ -124,6 +124,14 @@ public static partial class OpenIddictClientWebIntegrationHandlers request.Headers.Add("X-API-Key", settings.ApplicationKey); } + // HeyBoxChat requires a "token" header containing the Bot token. + else if (context.Registration.ProviderType is ProviderTypes.HeyBoxChat) + { + var settings = context.Registration.GetHeyBoxChatSettings(); + + request.Headers.Add("token", settings.Token); + } + // Notion requires sending an explicit API version (which is statically set // to the last version known to be supported by the OpenIddict integration). else if (context.Registration.ProviderType is ProviderTypes.Notion) @@ -439,6 +447,10 @@ public static partial class OpenIddictClientWebIntegrationHandlers ["accounts"] = context.Response["accounts"] }, + // HeyBoxChat returns a nested "result" object. + ProviderTypes.HeyBoxChat => new(context.Response["result"]?.GetNamedParameters() ?? + throw new InvalidOperationException(SR.FormatID0334("result"))), + // These providers return a nested "data" object. ProviderTypes.Kook or ProviderTypes.Kroger or ProviderTypes.Patreon or ProviderTypes.Pipedrive or ProviderTypes.Twitter diff --git a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationProviders.xml b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationProviders.xml index 6a7b85b6..8b1333d6 100644 --- a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationProviders.xml +++ b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationProviders.xml @@ -1121,6 +1121,27 @@ + ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ + ██ ██ █ ▄▄▄█ ███ █ ▄▄▀█ ▄▄▄ █▄▀█▀▄█ ▄▄▀█ ██ █ ▄▄▀█▄▄ ▄▄██ + ██ ▄▄ █ ▄▄▄█▄▀▀▀▄█ ▄▄▀█ ███ ███ ███ ████ ▄▄ █ ▀▀ ███ ████ + ██ ██ █ ▀▀▀███ ███ ▀▀ █ ▀▀▀ █▀▄█▄▀█ ▀▀▄█ ██ █ ██ ███ ████ + ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ + + + + + + + + + + + +