Last Updated: Nov 11, 2024
Overview
After updating the .net core web API to .net 6, “invalid_toklen” errors are received during token validation on the API controllers marked with the [authorize] attribute.
Token validation fails even though the token payload is good and the token has not expired.
Applies To
- .NET 6
- invalid_token
- Error
Cause
This appears to be a versioning issue with the Microsoft identity packages used by the OIDC middleware.
Solution
Update the System.IdentityModel.Tokens.Jwt to the latest version.
If updating the above library does not resolve, then make sure that the following libraries are on the same version:
Microsoft.IdentityModel.JsonWebTokens
Microsoft.IdentityModel.Logging
Microsoft.IdentityModel.Protocols
Microsoft.IdentityModel.Protocols.OpenIdConnect
Microsoft.IdentityModel.Tokens
It may need to be version 6.16.0 or higher.
Related References
- The solution was found in this stack overflow question.