Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot disable JWT Claims mapping using JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear()

Tags:

asp.net-core

I want to disable the JWT claims mapping in ASP.NET Core (not sure why it's there in the first place...) since the new names are much longer than the original ones (for example, instead of a simple oid claim, I need to access the http://schemas.microsoft.com/identity/claims/objectidentifier one).

According to the docs, this can be done by calling JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear() as early as possible in the Program.cs file.

However, no matter where I call this method, the claims are still mapped and I still can't access the oid claim.

What am I missing? Why doesn't the mapping get disabled?

Thanks!

like image 240
ml123 Avatar asked Jan 30 '26 17:01

ml123


1 Answers

You can set MapInboundClaims in your JwtBearerOptions to false.

So, the resulting code in your Program.cs should look something like this:

builder.Services
        .AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
        .AddJwtBearer(options =>
        {
            //other code

            options.MapInboundClaims = false;
        });
like image 85
helgez Avatar answered Feb 03 '26 06:02

helgez