I have a user with the following claims:
role: ["Admin","Tester"]
I want a controller method to only be accessible with the role claim value 'Admin'. For that I have added a policy like this:
services.AddAuthorization(options => {
options.AddPolicy("Admin", policy => policy.RequireClaim("role", "Admin"));
});
and added the [Authorize(Policy = "Admin")]
attribute on top of my controller method.
Unfortunately, when starting the application, the user does not have access.
If I remove the role Tester
from his claims so that he only has Admin (role: "Admin"
) and it isn't an array anymore, he does have access.
As I understood, the policy should check like a "contains", but somehow that doesn't seem to work.
Am I doing something wrong?