Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
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;
Expand Down Expand Up @@ -209,9 +210,17 @@ public ValueTask HandleAsync(PrepareTokenRequestContext context)
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);

Expand Down Expand Up @@ -267,6 +276,20 @@ public ValueTask HandleAsync(PrepareTokenRequestContext context)
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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,10 @@ ProviderTypes.Fitbit or ProviderTypes.Todoist or ProviderTypes.VkId or ProviderT
["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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>

<!--
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
██ ██ ██ ██ █ ▄▄▀██ ███ ██ ▄▄▄█▄ ▄█
Expand Down
Loading