question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JwtSecurityTokenHandler wrong message on exception

See original GitHub issue

Just hit this today, there seems to be a bug with this line:

https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/blob/e4f8a0c3cd1d7d0e62a2e48be7bdc91a7fdddb24/src/System.IdentityModel.Tokens.Jwt/JwtSecurityTokenHandler.cs#L1437

Where it prints the object type instead of the actual message in the StringBuilder.

Microsoft.IdentityModel.Tokens.SecurityTokenInvalidSignatureException: IDX10503: Signature validation failed. Keys tried: 'System.Text.StringBuilder'.
Exceptions caught:
 'System.Text.StringBuilder'.
token: 'System.IdentityModel.Tokens.Jwt.JwtSecurityToken'.
   at System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.ValidateSignature(String token, TokenValidationParameters validationParameters)
   at System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.ValidateToken(String token, TokenValidationParameters validationParameters, SecurityToken& validatedToken)

The fix should be as simple as calling .ToString() before:

throw LogHelper.LogExceptionMessage(new SecurityTokenDecryptionFailedException(LogHelper.FormatInvariant(TokenLogMessages.IDX10603, keysAttempted.ToString(), exceptionStrings.ToString(), jwtToken.RawData)));

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
senylitycommented, Jun 8, 2020

It happens on expired tokens as well

IDX10223: Lifetime validation failed. The token is expired. ValidTo: 'System.DateTime', Current time: 'System.DateTime'

Any time frame on a fix?

1reaction
thinkardscommented, May 20, 2021

It happens on expired tokens as well

IDX10223: Lifetime validation failed. The token is expired. ValidTo: 'System.DateTime', Current time: 'System.DateTime'

Any time frame on a fix?

FYI, I was able to work around this with:

Microsoft.IdentityModel.Logging.IdentityModelEventSource.ShowPII = true;

in the first line of ConfigureServices in my Startup.cs file. I’m using .NET 5.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JwtSecurityToken returning wrong expiration time
Validation fails: Microsoft.IdentityModel.Tokens.SecurityTokenExpiredException: IDX10223: Lifetime validation failed. The token is expired.
Read more >
Access Token validating fails with JWTSecurityTokenHandler
Check the new token from azure with jwt.io. If the aud is equal the registered application id the token can be successfull validated....
Read more >
IDX10223: Lifetime validation failed #7951
Hi App in dev mode keeps failing with the following thrown exception: IDX10223: Lifetime validation failed. The token is expired.
Read more >
Unable to parse JWT through JwtSecurityTokenHandler
I always get an exception on the ValidateToken method: IDX12709: CanReadToken() returned false. JWT is not well formed: '[PII is hidden]'.
Read more >
.NET 6.0 - Create and Validate JWT Tokens + Use Custom ...
This is a quick example of how to create and validate JWT tokens in .NET 6.0 using the JwtSecurityTokenHandler class which is part...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found