The symptom
Tokens that worked an hour ago now fail, or tokens from one environment fail
in another. Libraries phrase it differently: “kid not found”, “no matching
key”, “unable to find a signing key”. They all mean the same thing: the
token’s header names a key ID (kid) that is not in the
JSON Web Key Set your verifier holds.
The fix depends on why. Retrying blindly, or switching off the check, turns a key-distribution bug into a security hole.
Five causes, from most to least common
- Stale cache after a rotation. The issuer published a new key and signs with it. Your verifier fetched the set once at startup and never again.
- Wrong key set. The token comes from another issuer than the one whose set you load: staging against production, one tenant or organization against another, or a hard-coded URL that no longer matches the issuer.
- A withdrawn key. After an emergency rotation, the issuer stops publishing the old key. Tokens it signed should fail. This one is not a bug.
- A forged or malformed token. Anyone can write any
kidinto a header. If such tokens make your verifier refetch every time, they double as a way to flood the issuer. - A failed fetch reported as a missing key. A timeout or TLS error while loading the set leaves the verifier with no keys, and some code paths report that as “kid not found”.
Finding which cause you have
- Decode header and iss → Expected issuer?
- Expected issuer? → Wrong key setno
- Expected issuer? → kid in live set?yes
- kid in live set? → Stale cache: refetchyes
- kid in live set? → Withdrawn or forged: refuseno
A decision flow. Decode the token header. If the issuer is not the one you expect, you are reading the wrong key set. If the kid is in the issuer's current key set, your cache is stale. If the kid was in an earlier key set and is gone, the key was withdrawn and the refusal is correct. Otherwise the token names a key the issuer never published.
Check it in two minutes
Decode the header without verifying it, then compare with what the issuer publishes. Replace the placeholders with your token and issuer.
# 1. What the token claims: kid and alg in the header, iss in the payload
TOKEN='<your token>'
for part in 1 2; do
s=$(printf %s "$TOKEN" | cut -d. -f"$part" | tr '_-' '/+')
while [ $(( ${#s} % 4 )) -ne 0 ]; do s="$s="; done
printf %s "$s" | base64 -d; echo
done
# 2. What the issuer publishes right now
ISSUER='<issuer URL from your configuration>'
JWKS_URI=$(curl -fsS "$ISSUER/.well-known/openid-configuration" | jq -r .jwks_uri)
curl -fsS "$JWKS_URI" | jq -r '.keys[].kid'
issdiffers from your configured issuer: cause 2.- The
kidis in the live set: cause 1, or cause 5 if your logs show a failed fetch. - The
kidis not in the live set: cause 3 or 4. Refuse the token.
Fix the verifier, not the incident
- Refetch once on an unknown
kid, rate limited. A rotation then heals itself on the first new token, and a forged one cannot make you fetch on demand. - Take the key set location from configuration or discovery. Read the
issuer from your configuration and the
jwks_urifrom its discovery document. Never from the token. - Check
issbefore you look up the key. A token from an issuer you do not trust should fail as such, not as a missing key. - Report fetch failures as unavailable. “I could not load the keys” and “this token is invalid” need different alerts and different retries.
- On the issuer side, overlap keys. Publish the new key before signing with it, and keep the old one until its last token expires, unless you are withdrawing it on purpose.
A verifier that survives rotation
- 1Verifier → VerifierKnown kid: verify from cacheNo request
- 2Verifier → Issuer key setUnknown kid: fetch once
- 3Issuer key set → VerifierCurrent keys, new kid included
- 4Verifier → VerifierForged token: refuseNo further fetch
A sequence between a verifier and an issuer's key set. The verifier verifies a token whose kid it holds from cache, with no request. The issuer rotates. A token arrives naming the new kid; the verifier fetches the key set once and verifies. A forged token arrives; it is refused on the key it names, without fetching again.
How QuorumAuth avoids it
QuorumAuth signs the tokens and runs the verifier side in its SDK, so the behaviour above is built in. In its tested behaviour:
- One issuer per organization. Each organization is its own OpenID
Provider, with an issuer that never changes when the organization is
renamed and a
jwks_uriholding exactly the keys that organization publishes. An organization that does not exist has no issuer and no key set. - Known keys cost nothing. A key ID the SDK already holds is answered without contacting the authority, and later verifications for the same organization come from cache.
- Unknown keys cost one fetch. After a rotation, a key the SDK has never seen costs exactly one immediate discovery round-trip.
- Forged tokens cost no fetch. A tampered token is refused on the key it names, and the SDK fetches no further keys.
- Withdrawal is explicit. An emergency rotation names the key it withdraws, and the published key set no longer contains it. A refused rotation withdraws nothing.
- Failures say what failed. Discovery refuses a key set carrying private key material, refuses a peer that is not the expected authority, and when discovery is unreachable it fails closed and names the connection failure.
Keys are only half of token trust. To stop a token whose key is still valid, see how to revoke a JWT before it expires.
Where to go next
For the key set format and rotation routine, read what a JWKS is. For services that sign their own requests, read about JWT client assertions. For the whole machine-to-machine picture, see the machine-to-machine authentication platform.
Frequently asked questions
Why does "kid not found" start right after a key rotation?
Your verifier cached the old key set and does not refetch when a token names a key it has never seen. Refetch once on an unknown kid, with a rate limit.
Should I refetch the JWKS every time verification fails?
No. A forged token can name any kid it likes, so unlimited refetching lets anyone make you hammer the issuer. Refetch once per unknown kid, rate limited, and refuse after that.
Can I read the JWKS URL from the token?
No. Take it from your configuration or the issuer's discovery document. A key location chosen by the token lets the token choose who it trusts.
Is "kid not found" ever the right answer?
Yes. After an emergency rotation, tokens signed with the withdrawn key should fail. So should tokens from an issuer you do not trust.