dotnet / dotnet/dotnet-api-docs
RolePrincipal.IsInRole not checking "roles" claim.
- Dominant language
- C#
- Stars
- 949
- Forks
- 1.7k
- Avg merge
- 3d 27m
- Merged PRs (30d)
- 49
Description
### Type of issue
Code doesn't work
### Description
I have a JWT that looks like this:
```
{
"aud": "xxx",
"iss": "https://login.microsoftonline.com/xxx/v2.0",
...,
"azp": "xxx",
"roles": [
"my_role"
],
...
"ver": "2.0"
}
```
This token is processed by the Azure Application Service Authentication layer and I can see the "roles" claim defined in my ClaimsPrincipal. Therefore when I run:
`HttpContext.User.IsInRole("my_role");`
I was expecting this to return true but it returns false. It's not really clear in the docs why this wouldn't work.
### Page URL
https://learn.microsoft.com/en-us/dotnet/api/system.web.security.roleprincipal.isinrole?view=netframework-4.8.1
### Content source URL
https://github.com/dotnet/dotnet-api-docs/blob/main/xml/System.Web.Security/RolePrincipal.xml
### Document Version Independent Id
adcabe65-9e9e-0eb4-20fc-766acfea926e
### Article author
@Rick-Anderson
Contributor guide
Assessment
This issue has not been assessed yet.