JWKs, key sets, and key IDs
A verifier needs the issuerThe party that creates and signs a token, assertion, or certificate, named in a token's iss claim. A recipient must check that the issuer is exactly the one it expected and trusts.'s public keyThe half of a key pair that can be shared freely. It checks signatures made with the matching private key and can encrypt data that only that private key can decrypt. written in a form it can read and pick from. This lesson reads one key as JSON, explains the members that decide how it may be used, shows why a verifier never takes its key from the tokenA piece of data issued by a trusted service that a client presents as a credential, for example to call an API or to report a sign-in. Some tokens carry readable claims; others are random strings that only the issuer can interpret., and covers the caching that lets a rollover work.
A key written as JSON
Storing and using keys showed Lab Photos publishing its public keys at an address verifiers read, as a JSON Web Key Set. A JSON Web Key (JWK) is a single public key written as JSON, and a JWK Set (JWKS) is the keys array that holds several. This is the entry for the key that signed Ava's token in Inside a JWT:
{
"kty": "EC",
"crv": "P-256",
"x": "iIUYwDjgHwDpHukFHekD8AktnF6NISSc0f1vuntIkyE",
"y": "kVMlGl5cOYhMPJYgfH0ab2MvuFatOFlfG51SViuAu88",
"use": "sig",
"alg": "ES256",
"kid": "photos-2026-10"
}The kty, the key type, decides which other members carry the key itself. An EC key, the elliptic-curve type ES256 uses, has a curve name crv and the two point coordinates x and y. An RSA key carries the modulus n and exponent e instead. EdDSA keys use the type OKP, which carries crv and a single coordinate x. What a public JWK never carries is a private member: the d value, the secret number that signs. A d in a published set is a leaked private keyThe half of a key pair that its owner keeps to themselves and uses to create signatures or decrypt data. Anyone who obtains it can act as its owner..
What the other members say
The remaining members describe how the key may be used, and a verifier should honour them.
useseparates signing keys (sig) from encryptionTransforming data so that only someone holding the right key can read it. It protects confidentiality and, unlike hashing, is designed to be reversed by the key holder. keys (enc). A verifier checking a signatureA value made with a private key that lets anyone holding the matching public key check that a message came from the key's holder and has not been changed. It proves origin and integrity; it does not hide the message. must pick asigkey and never anencone.key_opsis a finer version of the same idea, listing the exact operations a key is for, such asverify; a key should carryuseorkey_ops, not both.alg, when present, pins the key to one algorithm. With the allowlist from Choosing and enforcing algorithms, this is what stops a public RSA key being misused as an HMAC secret.kidis the key identifier a token's header names, so a verifier can pick the matching entry without trying each key in turn.
A kid is only a label the issuer chose, and it means nothing outside that issuer's own set. Two unrelated providers can both label a key photos-2026-10. So a verifier never selects a key by kid alone: it decides whose set it is reading first, from the issuer it trusts, then finds the kid inside that set.
A more durable name for a key is its thumbprint: a hashTurning data into a short, fixed-size value called a hash, in a way that cannot be reversed and where changing one character changes the result completely. Services store password hashes instead of passwords, and signatures are made over a hash. computed from the key's own members by the fixed recipe in RFC 7638. The recipe takes only the members that define the key, in a fixed order with no extra spaces, and hashes them with SHA-256. The same public key always gives the same thumbprint, whatever kid anyone attaches, so a thumbprint is how a verifier can pin a specific key or recognize the same key across sets.
Headers that offer their own key
A JWSThe JOSE format for signed content, defined in RFC 7515. A signed JWT is a JWS: a header, a payload and a signature, each base64url-encoded and joined by dots. header can carry a key, or an address to fetch one from, instead of a plain kid. These parameters exist for narrow, agreed uses, and they are a classic trap when a verifier honours them from a token it hasn't yet trusted:
| Header | What it offers | The trap |
|---|---|---|
jwk | A public key, embedded in the header | The token supplies the key that checks it, so any token verifies against its own key. |
jku | A URL to fetch a key set from | The verifier fetches a key set the sender controls, and can be steered into requests to internal addresses. |
x5u | A URL to fetch a certificate from | The same, with a certificate. |
x5c | A certificate chain, embedded in the header | The token supplies a chain; a verifier that doesn't check it against a trusted root trusts whatever is there. |
The rule follows from the earlier lessons: a token must not choose its own judge. A verifier finds the key from the issuer it already trusts, at that issuer's configured key-set address, and ignores a key or URLA web address, such as https://photos.example/api/albums/42?limit=10. It names how to connect (https), the domain, the path to a particular page or resource, and any extra parameters after the question mark. the token hands it. Where x5c or a remote set is genuinely part of a profile, the verifier accepts it only after checking it against a trust anchor it already holds, exactly as Validating a certificate checks a chain against a trusted root.
Caching the key set
Fetching the key set on every token would be slow and would tie the verifier's health to the issuer's, so a verifier keeps a copy and reuses it. The question a cache raises is how it learns a new key. Storing and using keys described the rotation stages: the issuer publishes the new key, keeps the old one until its last token expires, then retires it. The cache is what lets a verifier follow those stages without being told.
When a token names a kid the cached set doesn't hold, the verifier fetches the set again, once, from the issuer's configured address. That refetch finds the newly published key. Two limits keep it safe. The refetch is bounded, so a flood of tokens carrying made-up kid values can't become a flood of requests to the issuer. And the key is added only from the issuer's own configured set, never from a jku or jwk in the token, so the refresh discovers announced keys without ever changing whose keys the verifier trusts. A token whose kid is in neither the cache nor the refetched set is refused, which is exactly what happens to the old key once the issuer retires it.
Check your understanding
Try these questions before moving on. If an answer isn't right, use the feedback and try again.
Try it in the Lab
- Select a public key within its trusted issuerRead a key set, check it carries no private member, find the key a token names and compute its thumbprint by hand, then switch the signer and watch a saved copy of the set refuse the new key until it refetches.