Skip to content

RolePrincipal.IsInRole not checking "roles" claim. #10477

Open
@ManelBH

Description

@ManelBH

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Pri3Indicates issues/PRs that are low priorityarea-System.SecurityIssues related to security practices for .NET developers.untriagedNew issue has not been triaged by the area owner

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions