Spring Security rejects the Entra ID token: invalid claims
Error occurred while attempting to decode the Jwt. The ID Token contains invalid claimsShort answer
Spring checks the ID token's claims against your client registration. With Entra the failure is nearly always the issuer: the token's iss does not equal the issuer from your configured metadata, because of v1.0 versus v2.0 or a common tenant. Next suspects are the audience and the clock.
Fix it fast
1Find out which cause you have
Decode the ID token your app received (a test sign-in is fine) and compare its iss and aud claims with your configuration.
echo "$ID_TOKEN" | cut -d. -f2 | tr '_-' '/+' | base64 -d 2>/dev/null2Match what you see, then jump to its fix
- 1
iss starts with https://sts.windows.net/ or contains a tenant id that is not the one in issuer-uriiss in the token differs from the issuer in your configured metadataFix - 2
aud in the decoded token is a different application's IDaud does not match your client IDFix - 3
iat, nbf or exp is outside the allowed time, or the nonce differsThe nonce or the timestamps fail validationFix
- 1
What does the error look like?
Error occurred while attempting to decode the Jwt. The ID Token contains invalid claims
Cause 1 of 3
iss in the token differs from the issuer in your configured metadata
1Check
The ID token version follows the endpoint it came from: the oauth2/authorize endpoint gives v1.0, oauth2/v2.0/authorize gives v2.0. The v2.0 issuer has the form https://login.microsoftonline.com/{tenantid}/v2.0, and a token must carry exactly the issuer of the metadata used to validate it. A metadata path with common returns a template, not a real tenant issuer.
grep -rn "issuer-uri\|authorization-uri" src/main/resources/2Fix
Use the v2.0 endpoints with your real tenant id.
spring:
security:
oauth2:
client:
provider:
azure:
issuer-uri: https://login.microsoftonline.com/<tenant-id>/v2.03Verify
Sign in again; the redirect completes and a session is created.
curl -s https://login.microsoftonline.com/<tenant-id>/v2.0/.well-known/openid-configuration | grep '"issuer"'Confirmed by learn.microsoft.com
Cause 2 of 3
aud does not match your client ID
1Check
An ID token must carry your own application's ID as audience. A mismatch usually means the client-id in the properties belongs to another app registration.
grep -rn "client-id" src/main/resources/2Fix
Set client-id to the Application (client) ID of the registration that is doing the sign-in.
spring:
security:
oauth2:
client:
registration:
azure:
client-id: <application-client-id>3Verify
Decode a new ID token: aud equals the configured client-id.
echo "$ID_TOKEN" | cut -d. -f2 | tr '_-' '/+' | base64 -d 2>/dev/null | grep -o '"aud":"[^"]*"'Confirmed by learn.microsoft.com
Cause 3 of 3
The nonce or the timestamps fail validation
1Check
iat, nbf and exp must fall before or after the current time as appropriate, and the nonce must be the one sent in the authorize request. A wrong server clock breaks the timestamps.
timedatectl status | grep -i 'synchronized'2Fix
Sync the server clock (NTP) and start the sign-in from a fresh page.
sudo timedatectl set-ntp true3Verify
The clock reports synchronized, and a new sign-in works.
timedatectl status | grep -i 'synchronized'Confirmed by learn.microsoft.com
How do I stop it coming back?
- Keep the tenant id in the issuer-uri; avoid common for ID-token validation.
- Keep one app registration per environment and one client-id per Spring profile.
- Run NTP on every server that validates tokens.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Security
A Microsoft Entra access token shows Invalid Signature when you check it yourself
Tokens that a Microsoft API receives might not always be a JWT that can be decoded
A token issued for Microsoft Graph is not meant for you to validate, so a failed signature check is expected.
2 causes, each with a fixSecurity
Azure Databricks REST API returns 403 with a Microsoft Entra token
Error 403 User not authorized when calling the Azure Databricks API
A 403 means the token was accepted but the identity in it is not allowed in that workspace.
4 causes, each with a fixSecurity
DelegateAuthenticationProvider no longer exists in the Microsoft Graph .NET SDK
The type or namespace name 'DelegateAuthenticationProvider' could not be found
Microsoft Graph .NET SDK v5 removed DelegateAuthenticationProvider.
3 causes, each with a fixSecurity
Jwts.parserBuilder() no longer compiles after upgrading JJWT
setSigningKey / parseClaimsJws / getBody shown as deprecated
JJWT 0.12.0 removed Jwts.parserBuilder() because Jwts.parser() now returns the builder itself.
3 causes, each with a fixSecurity
Spring Boot cannot find a ClientRegistrationRepository bean for OAuth2 login
APPLICATION FAILED TO START
Boot creates the ClientRegistrationRepository from spring.security.oauth2.client.registration properties.
3 causes, each with a fixSecurity
Spring resource server: 'An error occurred while attempting to decode the Jwt'
An error occurred while attempting to decode the Jwt: Malformed Jwk set
The resource server downloaded something from jwk-set-uri that is not a valid JWK Set.
2 causes, each with a fix