Skip to content

ConfidentialClient does not get authenticated when role-claims empty in token #2123

@michiproep

Description

@michiproep

Microsoft.Identity.Web Library

Microsoft.Identity.Web

Microsoft.Identity.Web version

1.26.0

Web app

Not Applicable

Web API

Protected web APIs (validating tokens)

Token cache serialization

In-memory caches

Description

If I add groups as optional claims with option "Emit groups as role claims" in AzureAd Token Configuration, the resulting token for a client credential flow / confidentialClientApplication might have no roles[] claim.

When sending this token to a web-api which just "RequiresAuthenticatedUser()" the httpContext.User is not populated by the authentication middleware although I can see a valid ClaimsPrincipal within OnTokenValidated=>context.Principal.

As a result, Authorization fails.

Reproduction steps

  1. Setup AzureAd AppRegistration with optional claims "groups" and "emit groups as role claims". (do not assign any groups to the corresponding serivce principal which calls this api at the end)
  2. In code "aquireTokenAsApp"
  3. call Api
  4. =>User not authenticated

Error message

Authorize-Policy => Failure => Do not allow anonymous user

Id Web logs


Relevant code snippets

---

Regression

No response

Expected behavior

Even if a token is missing role claims, the confidentialClient should still get authenticated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions