JwtSecurityTokenHandler wrong message on exception
See original GitHub issueJust hit this today, there seems to be a bug with this line:
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:
- Created 3 years ago
- Comments:7 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.