Rights-based authorization with ASP.NET Core 2.1 Identity

回眸只為那壹抹淺笑 提交于 2019-12-06 05:35:17

This is not the way claims should be used. Claims are supposed to model the identity of a user, not permissions. Please read the article Identity vs Permissions for some explanation.

In your case you can use policies.

public void ConfigureServices(IServiceCollection services)
{
    services.AddAuthorization(options =>
    {
        options.AddPolicy("AddOrEditOrder", policy =>
            policy.RequireRole("Manager", "CustomerRep"));
    });
}

And use the same attribute:

[Authorize("AddOrEditOrder")]

There are many other options to add authorization. You can also take a look at the PolicyServer.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!