我尝试使用基于策略的授权 https://docs.microsoft.com/en-us/aspnet/core/security/authorization/policies
我有这样的政策
p.AddPolicy("GroupMembership", policy =>
{
policy.RequireAuthenticatedUser();
policy.RequireClaim(ClaimTypes.Name);
policy.AddRequirements(new GroupMemberRequirement(
ServiceConstants.Admin
));
});
虽然我有RequireAuthenticatedUser()要求,但我的处理程序中的用户是匿名的!
不工作:
[Authorize("GroupMembership")]
[Route("[controller]")]
public class HomeController : Controller
{
[HttpGet("About")]
public async Task<IActionResult> About()
{
protected method
}
但确实工作
[Authorize]
[Route("[controller]")]
public class HomeController : Controller
{
[Authorize("GroupMembership")]
[HttpGet("About")]
public async Task<IActionResult> About()
{
protected method
}