Handle Authentication and Authorization in xAiMcpServer ...
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
using xIdentityHelper;
|
||||
using xModels.Extensions;
|
||||
using xCommons.Extensions;
|
||||
using xAiModels.Attributes;
|
||||
using xAiService.Interfaces;
|
||||
using System.Threading.Tasks;
|
||||
using xIdentityService.Interfaces;
|
||||
|
||||
namespace xAiMcpServer.Tools
|
||||
{
|
||||
[XAiMcpToolType]
|
||||
public class XUserTools
|
||||
{
|
||||
//
|
||||
private readonly IXPersonService personService;
|
||||
private readonly IXAiMcpUserContext userContext;
|
||||
|
||||
public XUserTools(
|
||||
IXAiMcpUserContext userContext,
|
||||
IXPersonService personService
|
||||
)
|
||||
{
|
||||
//
|
||||
this.userContext = userContext;
|
||||
this.personService = personService;
|
||||
}
|
||||
|
||||
[XAiMcpTool(
|
||||
RequiresAuthentication = true,
|
||||
RequiredPolicy = XPolicies.EnabledUser,
|
||||
Description = "Get information about the currently logged-in user.")]
|
||||
public async Task<string> WhoAmI()
|
||||
{
|
||||
//
|
||||
var user = userContext.UserInfo;
|
||||
if (user.IsNullOrDefault())
|
||||
{
|
||||
return "Anonymous";
|
||||
}
|
||||
|
||||
//
|
||||
var person = await personService.GetPerson(user.UserId);
|
||||
|
||||
//
|
||||
return person?.GetFullname() ?? user.UserId;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user