74 lines
2.5 KiB
C#
74 lines
2.5 KiB
C#
using xCommons.Constants;
|
|
using xCommons.Extensions;
|
|
using xAiModels.Constants;
|
|
using xIdentityModels.Models;
|
|
using xCommons.Configurations;
|
|
using System.Collections.Generic;
|
|
using xIdentityService.Constants;
|
|
|
|
namespace xAiModels.Helpers
|
|
{
|
|
/// <summary>
|
|
/// a Helper Class for Prepare Headers of MCP Client ...
|
|
/// </summary>
|
|
public static class XAiMcpHeaderBuilder
|
|
{
|
|
/// <summary>
|
|
/// Build Headers for MCP Client Connection ...
|
|
/// </summary>
|
|
/// <param name="appConfiguration"></param>
|
|
/// <param name="sessionId"></param>
|
|
/// <param name="connectionId"></param>
|
|
/// <param name="userInfo"></param>
|
|
/// <param name="protocolVersion"></param>
|
|
/// <returns></returns>
|
|
public static Dictionary<string, string> Build(
|
|
XAppConfiguration appConfiguration,
|
|
string sessionId = null,
|
|
string connectionId = null,
|
|
XUserClaimsInfoDto userInfo = null,
|
|
string protocolVersion = XAiMcpConstants.XAiMcpProtocol
|
|
)
|
|
{
|
|
//
|
|
var headers = new Dictionary<string, string>
|
|
{
|
|
//
|
|
["Accept"] = "application/json, text/event-stream",
|
|
["Content-Type"] = "application/json",
|
|
[XAiMcpConstants.XAiMcpProtocolIdentifier] = protocolVersion,
|
|
[XAuthorization.XPoweredBy] = appConfiguration.XPoweredValue ?? "xAiApi"
|
|
};
|
|
|
|
//
|
|
// Adding Authorization Headers ...
|
|
if (!userInfo.IsNullOrDefault() && !userInfo.AccessToken.IsNullOrEmpty())
|
|
{
|
|
//
|
|
headers[XAuthorization.Header] = $"{XAuthorization.TokenIdentifier} {userInfo.AccessToken}";
|
|
headers[XAuthorization.ExpiresAt] = userInfo.ExpiresAt.ToString();
|
|
|
|
//
|
|
if (!userInfo.RefreshToken.IsNullOrEmpty())
|
|
{
|
|
headers[XAuthorization.RefreshToken] = userInfo.RefreshToken;
|
|
}
|
|
}
|
|
|
|
//
|
|
// شناسه اتصال (برای Push Notification ها)
|
|
if (!connectionId.IsNullOrEmpty()) {
|
|
headers[XHeader.ConnectionId.GetStringValue()] = connectionId;
|
|
}
|
|
|
|
//
|
|
// Session Id ...
|
|
if (!sessionId.IsNullOrEmpty()) {
|
|
headers[XAiMcpConstants.XAiMcpSessionIdentifier] = sessionId;
|
|
}
|
|
|
|
//
|
|
return headers;
|
|
}
|
|
}
|
|
} |