Skip to content

Azure App Service ClaimsIdentity.RoleClaimType wrong if using Microsoft Identity Provider #1983

@mr-sven

Description

@mr-sven

Microsoft.Identity.Web Library

Microsoft.Identity.Web

Microsoft.Identity.Web version

1.25.9

Web app

Sign-in users

Web API

Protected web APIs (validating scopes/roles)

Token cache serialization

In-memory caches

Description

I'm using an Azure App Service with .NET Core 7.

As soon as I enable App Service authentication with Microsoft Identity Provider, the property ClaimsIdentity.RoleClaimType is http://schemas.microsoft.com/ws/2008/06/identity/claims/role what causes User role checking is failing.
In case the App Service authentication is disabled, the property ClaimsIdentity.RoleClaimType is roles so the role checking is working.

I tried the sample: https://github.com/Azure-Samples/active-directory-aspnetcore-webapp-openidconnect-v2/tree/master/5-WebApp-AuthZ/5-1-Roles it is se same.

I've striped down the code to a simple app: https://github.com/mr-sven/AzureAppRoleTest
Page run without App Service Auth:

Page with App Service Auth:
app_run_on_azure.png

I've found varous issues:

At the moment I'm using this Middleware to get around the issue: https://blog.johnnyreilly.com/2021/01/17/azure-easy-auth-and-roles-with-net-and-microsoft-identity-web/

Reproduction steps

  1. Create Azure App Service
  2. Register App
  3. Enable App Service authentication using the registered app
  4. Checkout https://github.com/mr-sven/AzureAppRoleTest
  5. Deploy Code
  6. Open index page,

Error message

No response

Id Web logs

No response

Relevant code snippets

WebApplicationBuilder builder = WebApplication.CreateBuilder(args);

JwtSecurityTokenHandler.DefaultMapInboundClaims = false;

builder.Services.AddMicrosoftIdentityWebAppAuthentication(builder.Configuration)
        .EnableTokenAcquisitionToCallDownstreamApi(new string[] { "user.read" })
        .AddInMemoryTokenCaches();

// configure Open ID claims
builder.Services.Configure<OpenIdConnectOptions>(OpenIdConnectDefaults.AuthenticationScheme, options =>
{
    options.TokenValidationParameters.RoleClaimType = "roles";
});

Regression

No response

Expected behavior

ClaimsIdentity.RoleClaimType shoud also be roles if using App Service authentication.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions