-
Notifications
You must be signed in to change notification settings - Fork 245
Description
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:

I've found varous issues:
ClaimsPrincipal.IsInRoledoesn't work with AAD application roles Azure/azure-functions-host#3898- Documentation: How to use EasyAuth with Azure AppService and Roles? #881
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
- Create Azure App Service
- Register App
- Enable App Service authentication using the registered app
- Checkout https://github.com/mr-sven/AzureAppRoleTest
- Deploy Code
- 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.
