Quick revision
The short answer
Spring Security compares the token's iss claim with the configured issuer as an exact string, so a different scheme, host, port, path or even one trailing slash makes every token fail. We check what the identity provider really puts in iss, compare it character by character with issuer-uri, and then fix the configuration, the provider's public hostname, or trust several issuers when there are several tenants.
What to remember
In this answer, we saw that "The iss claim is not valid" means the token's iss and the configured issuer are not the same string. We decoded a token locally to see the real value, found the usual causes in proxies with different hostnames, realms and tenants that change the issuer, and small differences such as a trailing slash, and fixed them by configuring the exact issuer, separating jwk-set-uri from issuer-uri, or trusting a fixed list of issuers with JwtIssuerAuthenticationManagerResolver.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Spring Security compares the token's iss claim with the configured issuer as an exact string, so a different scheme, host, port, path or even one trailing slash makes every token fail. We check what the identity provider really puts in iss, compare it character by character with issuer-uri, and then fix the configuration, the provider's public hostname, or trust several issuers when there are several tenants.
Why this question is asked
This error looks alarming because it hits every request at once, but it is almost never a broken identity provider. It is a mismatch between two strings that people assume are the same. Interviewers ask it because the cause is often hidden behind proxies, realms and tenants, and a good engineer finds it by looking at the token instead of guessing. In this answer, we will recap what the issuer check does, decode a token safely to see the real value, walk through the usual reasons the two strings differ, and fix each case, including services that must trust more than one issuer.
1A Quick Recap of the Issuer Check
A resource server is an API that accepts access tokens and decides whether to serve the request. When the token is a JWT, a JSON Web Token with a signed JSON payload, Spring Security checks the signature first and then runs a list of validators over the claims, the fields inside the payload. One of them is JwtIssuerValidator. It reads the iss claim, which names the identity provider that issued the token, and compares it with the issuer we configured in spring.security.oauth2.resourceserver.jwt.issuer-uri.
The comparison is a plain string comparison. Spring does not normalise URLs, so https://login.example.com and https://login.example.com/ are two different issuers. When the strings differ, the validator fails with the message "The iss claim is not valid" and the request gets a 401 with invalid_token. Because every token from that provider carries the same iss, every request fails, which is exactly the symptom in the question.
2Look at the Real iss Value
Before changing anything, we need the exact iss value from a real token. A JWT is three base64url parts separated by dots, and the middle part is the payload. We should not paste a production token into a public website, because the token is a working credential until it expires. Decoding it locally takes a few lines.
Now the problem is visible. The token says https://auth.example.com/realms/shop and the service is configured with an internal http address. Notice that only the payload is decoded; we do not need the signature to read it. We compare scheme, host, port, path and the final slash one by one, because any single difference is enough to fail.
3Why the Two Strings Differ
The first common cause is a proxy. The identity provider sits behind a load balancer with a public name, and it writes that public name into iss because that is the address browsers use. Inside the cluster, our service reaches the provider through an internal name such as keycloak.internal:8080. If we copy the internal address into issuer-uri, the check can never pass. Keycloak, for example, builds iss from its configured hostname setting, so a wrong or missing hostname setting after a redeploy changes iss for every token.
The second cause is tenants and realms. Multi-tenant providers put the tenant into the issuer. Keycloak has one issuer per realm (/realms/shop and /realms/admin are different issuers), and Microsoft Entra ID includes the tenant id in the path, with a different format for its v1 and v2 endpoints. A token from another realm or another endpoint version is perfectly valid and still has a different iss.
The third cause is small formatting: a trailing slash, an explicit :443 port, http against https, or upper-case letters in the host. These look identical to a person reading quickly, which is why we compare the strings precisely.
| Token iss | Configured issuer-uri | Cause |
|---|---|---|
| https://auth.example.com/realms/shop | http://keycloak.internal:8080/realms/shop | internal address behind a proxy |
| https://auth.example.com/realms/shop | https://auth.example.com/realms/admin | different realm or tenant |
| https://login.example.com/ | https://login.example.com | trailing slash |
| https://login.example.com:443 | https://login.example.com | explicit default port |
4Fix 1: Configure the Issuer the Token Really Uses
When the provider's public name is correct, we set issuer-uri to exactly that value. If the service cannot reach the public name from inside the network, we can still keep the check correct: we give Spring the internal address only for downloading keys, through jwk-set-uri, and keep issuer-uri as the public value used for validation.
With both properties set, Spring Boot builds the decoder from the JWK set URI and adds the issuer validator for issuer-uri, so it does not need to call the discovery document at the public address. If instead the provider writes the wrong name into iss, the right fix is on the provider side, for example Keycloak's hostname setting, because every other client will meet the same problem.
5Fix 2: Trust Several Issuers Deliberately
If the service must accept tokens from several realms or tenants, a single issuer-uri is the wrong tool. Spring Security offers JwtIssuerAuthenticationManagerResolver, which reads iss from the token, checks it against a list we trust, and uses a decoder built for that issuer. Tokens from issuers not on the list are rejected before any key is fetched.
Notice that the list is explicit. We must never accept any issuer the token names, because then an attacker could run their own provider and point iss at it. The factory method name has changed between versions, so check your version of Spring Security.
6Follow-up questions
Why does Spring not just ignore a trailing slash?
Because the OpenID Connect specification requires the issuer to match exactly, and a lenient comparison would make it unclear which issuer is trusted. Treating near matches as equal also opens the door to tricks with similar-looking URLs. The fix is to configure the exact value once, not to loosen the check.
The service fails at startup instead, saying the issuer in the metadata does not match. Is that the same problem?
It is the same mismatch found earlier. With only issuer-uri set, Spring calls the discovery document under that address at startup and checks that its issuer field equals the configured value. If the provider reports a different name, startup fails. The same diagnosis applies: compare the strings and fix the configured value or the provider's hostname.
Can I disable the issuer check to get unblocked?
We could replace the validators, but we should not. The issuer check is what stops tokens from another provider, realm or tenant, signed with keys we might also trust, from being accepted. Removing it to fix a configuration typo trades a visible outage for a silent security hole.
7Conclusion
In this answer, we saw that "The iss claim is not valid" means the token's iss and the configured issuer are not the same string. We decoded a token locally to see the real value, found the usual causes in proxies with different hostnames, realms and tenants that change the issuer, and small differences such as a trailing slash, and fixed them by configuring the exact issuer, separating jwk-set-uri from issuer-uri, or trusting a fixed list of issuers with JwtIssuerAuthenticationManagerResolver.
Open with
That message comes from JwtIssuerValidator, which compares the iss claim with my configured issuer-uri as an exact string, so I start by looking at a real token. I decode the payload locally, not on a public website, and compare scheme, host, port, path and trailing slash character by character.
Then, if they want more
The usual causes are three. First, the identity provider sits behind a proxy and writes its public hostname into iss, while the service was configured with the internal address. Second, the provider is multi-tenant, so each Keycloak realm or Entra tenant has its own issuer, and a token from another realm has a different iss.
Third, small things like a trailing slash or an explicit port. If the service can only reach the provider internally, I set issuer-uri to the public value and jwk-set-uri to the internal address, so keys come from inside but validation uses the right issuer. If the provider writes the wrong name, I fix its hostname setting instead.
And if the service genuinely needs several issuers, I use JwtIssuerAuthenticationManagerResolver with an explicit list of trusted issuers, never whatever the token claims. I would not disable the check, because it is what keeps tokens from other tenants out.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- RFC 6749, The OAuth 2.0 Authorization Framework, Spring Security reference, OAuth2
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "A resource server rejects every token with "The iss claim is not valid" even though...": https://scrivio-interview-library.netlify.app/spring-boot/oauth2-and-oidc/06b8887cd4/