API end point returning “Authorization has been denied for this request.” when sending bearer token

前端 未结 3 1100
清酒与你
清酒与你 2021-02-04 05:08

I\'ve followed a tutorial to protect a Web API with OAuth in C#.

I\'m doing some tests and so far I\'ve been able to get the access token successfully from /token

3条回答
  •  别跟我提以往
    2021-02-04 05:22

    You have to add a claim with this schema:

    http://schemas.microsoft.com/ws/2008/06/identity/claims/role
    

    best thing to do is to use the pre-defined set of claims:

    identity.AddClaim(new Claim(ClaimTypes.Role, "User"));
    

    You can find ClaimTypes in System.Security.Claims.

    Another thing you have to consider is filter roles in your Controller/Action:

    [Authorize(Roles="User")]
    

    You can find a simple sample app, self-hosted owin with a jquery client here.

提交回复
热议问题