Handle Authentication and Authorization in xAiMcpServer ...
This commit is contained in:
@@ -4,9 +4,16 @@ using xAiService.Controllers;
|
||||
using xCommons.Configurations;
|
||||
using xIdentityService.Interfaces;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using xIdentityHelper;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Threading;
|
||||
|
||||
namespace xAiMcpServer.Controllers
|
||||
{
|
||||
[Authorize]
|
||||
public class McpController : XAiMcpControllerBase
|
||||
{
|
||||
public McpController(
|
||||
@@ -17,5 +24,48 @@ namespace xAiMcpServer.Controllers
|
||||
XValidationProvider validationProvider
|
||||
) : base(mcpHandler, appConfiguration, identityProvider, logger, validationProvider)
|
||||
{ }
|
||||
|
||||
//
|
||||
#region Override ...
|
||||
/// <summary>
|
||||
/// Handle MCP ...
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||
public override async Task<IActionResult> HandleMcp(
|
||||
[FromBody] JObject request,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = await base
|
||||
.HandleMcp(
|
||||
request: request,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle SSE EndPoint ...
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("sse")]
|
||||
[AllowAnonymous]
|
||||
public override async Task SseEndpoint(
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
await base
|
||||
.SseEndpoint(cancellationToken);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user