dotnet / dotnet/dotnet-api-docs

RolePrincipal.IsInRole not checking "roles" claim.

Open
#10,477 8 comments 0 reactions 0 assignees View on GitHub
area-System.Security Pri3 untriaged
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.