Browse Source

Add HeyBoxChat to the list of supported providers

Signed-off-by: Gehongyan <gehongyan1996@126.com>
pull/2374/head
Gehongyan 6 months ago
parent
commit
080f9e6d34
  1. 30
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Exchange.cs
  2. 12
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Userinfo.cs
  3. 21
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationProviders.xml

30
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<string, StringValues>
{
["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;
}
}

12
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

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

@ -1121,6 +1121,27 @@
</Environment>
</Provider>
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
██ ██ █ ▄▄▄█ ███ █ ▄▄▀█ ▄▄▄ █▄▀█▀▄█ ▄▄▀█ ██ █ ▄▄▀█▄▄ ▄▄██
██ ▄▄ █ ▄▄▄█▄▀▀▀▄█ ▄▄▀█ ███ ███ ███ ████ ▄▄ █ ▀▀ ███ ████
██ ██ █ ▀▀▀███ ███ ▀▀ █ ▀▀▀ █▀▄█▄▀█ ▀▀▄█ ██ █ ██ ███ ████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
<Provider Name="HeyBoxChat" Id="b1b84538-0487-4106-bf53-4d0390523686"
Documentation="https://s.apifox.cn/43256fe4-9a8c-4f22-949a-74a3f8b431f5/7145802m0">
<Environment Issuer="https://chat.xiaoheihe.cn/">
<Configuration AuthorizationEndpoint="https://www.xiaoheihe.cn/account/bot_oauth"
TokenEndpoint="https://chat.xiaoheihe.cn/chatroom/api/token"
UserInfoEndpoint="https://chat.xiaoheihe.cn/chatroom/api/account/info">
<GrantType Value="authorization_code" />
<GrantType Value="refresh_token" />
</Configuration>
</Environment>
<Setting PropertyName="Token" ParameterName="token" Type="String" Required="true"
Description="The HeyBoxChat Bot token" />
</Provider>
<!--
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
██ ██ ██ ██ █ ▄▄▀██ ███ ██ ▄▄▄█▄ ▄█

Loading…
Cancel
Save