Bearer error="invalid_token", error_description="The audience '(null)' is invalid"
means the token's aud claim does not match the audience the API accepts. The
(null) is misleading: the token in this test did carry an audience, just the
wrong one. Make the token's audience equal ValidAudience and the 401 goes
away.
The server console logs the same failure as IDX10214: Audience validation
failed, without the values. Compare the aud claim of the token with the
API's configuration by hand; the error will not show you either one.
The error
The response header, from curl.exe -i:
$token = .\mint\bin\Debug\net10.0\Mint.exe "fix11-test-only-signing-key-0123456789abcdef" https://issuer.test other-api 30 0
curl.exe -i http://127.0.0.1:15600/patients -H "Authorization: Bearer $token"
HTTP/1.1 401 Unauthorized
Content-Length: 0
Date: Sat, 14 Nov 2026 01:13:01 GMT
Server: Kestrel
WWW-Authenticate: Bearer error="invalid_token", error_description="The audience '(null)' is invalid"
The server console:
info: Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler[1]
Failed to validate the token.
Microsoft.IdentityModel.Tokens.SecurityTokenInvalidAudienceException: IDX10214: Audience validation failed. See https://aka.ms/identitymodel/app-context-switches
...
Why it happens
The token maker was given other-api as the audience; the API was configured with
ValidAudience = "fix11-api". The test never set ValidateAudience,
and the audience was still checked. The response text says
'(null)' where you would expect other-api, and the log line names
no audience at all, so neither tells you which value was wrong.
Even with IdentityModelEventSource.ShowPII = true (a development-only switch,
tried on a second instance of the same API on port 15602), the IDX10214 line and the
response header stayed exactly the same.
The fix
The API's settings in the test's Program.cs:
var parameters = new TokenValidationParameters
{
ValidIssuer = "https://issuer.test",
ValidAudience = "fix11-api",
};
A token minted for that audience:
$token = .\mint\bin\Debug\net10.0\Mint.exe "fix11-test-only-signing-key-0123456789abcdef" https://issuer.test fix11-api 30 0
curl.exe -i http://127.0.0.1:15600/patients -H "Authorization: Bearer $token"
HTTP/1.1 200 OK
...
["Maria Garcia","David Chen"]
Fix the side that is wrong: if the API's name changed, update the token issuer's audience
setting; if the token was meant for another API, request one for this API. Turning ValidateAudience off also makes the 401
disappear, but then a token issued for any other API with the same signing key is accepted
too; it is not tested here and not the fix.
How it was reproduced
A dotnet new web -f net10.0 API with Microsoft.AspNetCore.Authentication.JwtBearer
10.0.15 (Microsoft.IdentityModel 8.19.2) and one endpoint protected with
RequireAuthorization(), on 127.0.0.1:15600 with the ASP.NET Core 10.0.15 runtime
and SDK 11.0.100. A console project on System.IdentityModel.Tokens.Jwt 8.19.2 made HS256
tokens with a chosen key, issuer, audience and lifetime; the signing key is a made-up test
string. Requests went through curl 8.22.0 on Windows, and the
Microsoft.AspNetCore.Authentication log category was set to Information.
Frequently asked
- Why does ASP.NET Core say the audience '(null)' is invalid when my token has an audience?
- In the test the token's aud was other-api and the response still printed (null). The value in the message is not the token's audience; compare the aud claim with ValidAudience yourself.
- What is IDX10214?
- It is the IdentityModel code for a failed audience check. The server log printed IDX10214: Audience validation failed, and the client got a 401 with The audience '(null)' is invalid.
- How do I fix a JWT audience mismatch in ASP.NET Core?
- Issue the token with the audience the API expects in ValidAudience. In the test a token for fix11-api turned the 401 into a 200.
More decoded errors in the Fixes category. The issuer check fails in the same way, with the value shown: The issuer is invalid (IDX10205).