我使用带有[Authorize]
属性 from的 HotChocolate 获得了 GraphQL 突变,HotChocolate.AspNetCore.Authorization
以在我的 GraphQL 端点上强制执行授权。
这很好用,我只能在以管理员身份登录后调用突变......
...但现在我想检索已授权的用户,但我似乎没有找到办法。
[ExtendObjectType(Name = "Mutation")]
[Authorize(Roles = new[] { "Administrators" })]
public class MyMutations
{
public bool SomeMethod()
{
// In a regular Web API controller, you can do User.Identity.Name to fetch the user name of the current user. What is the equivalent in Hot Chocolate?
var userName = "";
return false;
}
}
有任何想法吗?