I have implemented a token based authentication web Api 2 application using OWIN middleware, authentication is made successfully where I can retrieve token and use it to get to the method of the web Api.
However when I tried to add roles authorization, it doesn't work, I've searched thoroughly and found that I have to add in the "GrantResourceOwnerCredentials " in the oAuthorization provider the following:
identity.AddClaim(new Claim(ClaimTypes.Role, "the role that i need to add"));
The above line is all that I can get, it is also found in Authorization roles WebAPI oauth owin
However still whenever I use a token to get to any method(even authorized ones with different role) it still retrieve results normally.
I mean when for example in the API Controller: it is like the following:
[Authorize(Roles = "Admin")]
// GET api/Patient
public IQueryable<Patient> GetPatients()
while in the "GrantResourceOwnerCredentials" method i have added only an Employee role:
var oAuthIdentity = new ClaimsIdentity(context.Options.AuthenticationType);
oAuthIdentity.AddClaim(new Claim(ClaimTypes.Role, "Employee"));
Also, the Table in the server explorer that holds the roles "AspNetUserRoles" is not updated.
What I'm missing???