Browse Source

Add HeyBoxChat to the list of supported providers

pull/2376/head
Ge 5 months ago
committed by GitHub
parent
commit
9385b24ff8
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 25
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Exchange.cs
  2. 4
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Userinfo.cs
  3. 21
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationProviders.xml

25
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,20 @@ 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"
});
}
return default;
}
}

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

@ -439,6 +439,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