[PII of type 'System.String' is hidden. For more details, see https://aka.ms/IdentityModel/PII.] inside a JWT error is not the error itself: it is IdentityModel hiding the value that would tell you what went wrong. On a development machine, setting IdentityModelEventSource.ShowPII = true at start-up made the IDX10400 line of the next failure print the value; the token itself stayed behind another placeholder, and an audience failure printed the same line as before.

Read the IDX code in front of the placeholder first; it names the failure. Switch the values on only while you debug locally, and switch them off again: in this test the value shown was the start of the request's token (its header), straight from the Authorization header.

The error

The server console for a request whose Authorization header was Bearer Bearer followed by a valid token (the client got only WWW-Authenticate: Bearer error="invalid_token"):

info: Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler[1]
      Failed to validate the token.
      System.ArgumentException: IDX14102: Unable to decode the header '[PII of type 'Microsoft.IdentityModel.Logging.SecurityArtifact' is hidden. For more details, see https://aka.ms/IdentityModel/PII.]' as Base64Url encoded string.
       ---> System.FormatException: IDX10400: Unable to decode: '[PII of type 'System.String' is hidden. For more details, see https://aka.ms/IdentityModel/PII.]' as Base64url encoded string.
...

Why it happens

IdentityModel puts this placeholder where a value it treats as personal data would go, until you allow those values; the setting that allowed them in this test is below. In the log above both values are hidden, so the line says that decoding failed but not what it tried to decode.

The fix

For development only: the line the test added at the top of Program.cs, behind a configuration switch:

if (builder.Configuration["Lab:ShowPII"] == "true")
{
    IdentityModelEventSource.ShowPII = true;
}

IdentityModelEventSource lives in Microsoft.IdentityModel.Logging, which the JWT bearer package already brings in. The same request against an instance started with --Lab:ShowPII=true on port 15602:

curl.exe -i http://127.0.0.1:15602/patients -H "Authorization: Bearer Bearer $token"
HTTP/1.1 401 Unauthorized
...
WWW-Authenticate: Bearer error="invalid_token"
      System.ArgumentException: IDX14102: Unable to decode the header '[Security Artifact of type 'Microsoft.IdentityModel.Logging.SecurityArtifact' is hidden. For more details, see https://aka.ms/IdentityModel/SecurityArtifactLogging.]' as Base64Url encoded string.
       ---> System.FormatException: IDX10400: Unable to decode: 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9' as Base64url encoded string.

The IDX10400 line now shows the text it could not decode, and the stray Bearer in front of the token header is plain to see. The response to the client did not change. Note what stayed hidden: the IDX14102 line now says Security Artifact ... is hidden, with a link to https://aka.ms/IdentityModel/SecurityArtifactLogging instead of the PII page. This test did not follow that link or change anything else.

Not every message gains a value. In the same test, an audience failure (IDX10214) printed the identical line with and without ShowPII. In your own app, put the line under builder.Environment.IsDevelopment() rather than a switch that could be set in production.

How it was reproduced

A dotnet new web -f net10.0 API with Microsoft.AspNetCore.Authentication.JwtBearer 10.0.15 (Microsoft.IdentityModel.Logging 8.19.2) and one endpoint protected with RequireAuthorization(), run on 127.0.0.1:15600 (defaults) and 15602 (ShowPII on) with the ASP.NET Core 10.0.15 runtime, SDK 11.0.100, and the Microsoft.AspNetCore.Authentication log category at Information. The token came from a console project on System.IdentityModel.Tokens.Jwt 8.19.2 with a made-up test key; requests went through curl 8.22.0 on Windows.

Frequently asked

How do I see the hidden PII values in an IdentityModel error?
Set Microsoft.IdentityModel.Logging.IdentityModelEventSource.ShowPII = true at start-up, on a development machine only. In the test the IDX10400 line then printed the text it could not decode.
Does ShowPII show the whole JWT in the log?
Not in the test. With ShowPII on, the token was still replaced by a Security Artifact is hidden placeholder that links to aka.ms/IdentityModel/SecurityArtifactLogging.
Is it safe to turn ShowPII on in production?
No. In the test the value it revealed was the header part of the caller's token, taken from the request. Keep it behind a development check and remove it when the bug is found.

More decoded errors in the Fixes category. The doubled prefix used here is explained in JWT is not well formed (IDX14100).