Inside a JWT: JWS and compact serialization
A JSON Web Token carries its claims as one line of text. Taking a real one apart shows what each part holds, exactly which characters the signature protects, and what a receiver still has to check after it has read the claims.
A token on the wire
When Ava lets an application read her photos, Lab Photos' authorization serverIn OAuth, the service that handles a person's sign-in and approval and decides which tokens to issue to a client. It may belong to the same company as the API, but its job is separate. gives that application an access tokenA token that a client presents to an API to use access it has been granted, usually limited in what it allows and how long it lasts. It authorizes API calls; it does not tell the client who signed in. for the photo APIAn application programming interface: a defined way for software to interact with a service. A web API offers endpoints where other programs send HTTP requests.. Digital signatures showed a signed token like this one decoded into readable fields. This is how it actually travels, in an Authorization header, folded here onto several lines only so it fits the page:
eyJhbGciOiJFUzI1NiIsImtpZCI6InBob3Rvcy0yMDI2LTEw
IiwidHlwIjoiYXQrand0In0
.
eyJpc3MiOiJodHRwczovL2F1dGgucGhvdG9zLmV4YW1wbGUi
LCJzdWIiOiJhdmEtNDgyMTMiLCJhdWQiOiJodHRwczovL2Fw
aS5waG90b3MuZXhhbXBsZSIsInNjb3BlIjoicGhvdG9zLnJl
YWQiLCJpYXQiOjE3OTMxNzQ0MDAsImV4cCI6MTc5MzE3ODAw
MCwianRpIjoiYXQtN2YzYzIxIn0
.
GuZS6Se3GscysRlpcRop-Sttgy51m36fpF67qmpSAwOAIAqF
uPTDoQ9NdH0Sbu5lEwjHHKle47mulJBQovYKtwA JSON Web Token (JWT) is a set of claims written as JSON and packed into a string that can sit in a header, a 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. or a request body. The token above is signed, and a signed JWT written as one line like this is a JSON Web Signature (JWS) in its compact serialization. Both belong to a family of standards called JOSE, JSON Object Signing and 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., which also defines how to encrypt a token and how to write a key as JSON.
Three base64url parts
Two dots split the token into three parts, and each part is base64urlA way of encoding data as ordinary text characters so it can travel safely in headers, URLs, and JSON. Anyone can decode it, so it hides nothing; Base64url is a variant safe for URLs, used in JWTs., the URL-safe Base64 from Encoding and hashing. JOSE always leaves off the = padding, so a decoder that expects classic Base64 may refuse a part whose length is not a multiple of four. A base64url decoder, such as the one you wrote in that lesson's lab, puts the padding back first.
The first part decodes to the header:
{"alg":"ES256","kid":"photos-2026-10","typ":"at+jwt"}The second decodes to the payload, the claims themselves:
{
"iss": "https://auth.photos.example",
"sub": "ava-48213",
"aud": "https://api.photos.example",
"scope": "photos.read",
"iat": 1793174400,
"exp": 1793178000,
"jti": "at-7f3c21"
}The third part is the signature. It decodes to raw bytes, not JSON. For ES256 those bytes have a fixed size: two 32-byte numbers side by side, 64 bytes in all, which base64url always writes as 86 characters. A signature part of any other length was not made by ES256, whatever the header says.
The header
The header says how the token was protected. It never says whether to trust it. As Digital signatures explained, alg, the algorithm, and kid, the key identifier, are hints the receiver checks against its own configuration. Choosing and enforcing algorithms looks at alg in detail. Two more parameters matter for nearly every token:
typnames the kind of token.at+jwtis the registered name for an access token written as a JWT, and plainJWTis the generic value. One 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. often signs several kinds of token with the same key, such as ID tokens for applications and access tokens for APIs, so an API that requiresat+jwtcan't be handed an ID tokenIn OpenID Connect, a signed JWT from the provider, addressed to one client, saying which account authenticated, when, and in answer to which request. It reports a sign-in and is not used to call APIs. that happens to carry a good signature.critlists header parameters the receiver must understand. A receiver that meets a name incritit doesn't support refuses the token rather than ignoring the parameter.
Other header parameters can carry a key, or an address to fetch one from. JWKs, key sets, and key IDs explains why a receiver doesn't use them to find its key.
The registered claims
A handful of claim names are registered so that every issuer and receiver reads them the same way. They are the claims a receiver checks before it relies on anything else in the payload.
| Claim | Meaning |
|---|---|
iss | The issuer: who made and signed the token. The receiver maps it to the key set it trusts for that issuer. |
sub | The subject: who or what the claims are about. It is unique only within its issuer. |
aud | The audience: who the token is for. A single string, or an array when the token names several recipients. |
exp | Expiry: the token must be refused at or after this time. |
nbf | Not before: the token must be refused before this time. |
iat | Issued at: when the token was made. |
jti | A unique identifier for this token, so a receiver can notice one it has already seen. |
Beside them sit claims that a kind of token defines, such as scope in an access token, and claims an issuer adds for its own use. Unregistered names mean whatever their issuer says they mean, so a receiver reads them only from issuers it has agreed them with.
The aud claim is the one most often read carelessly. Ava's token names one API as a string, but another token may carry an array. A receiver that expects one shape breaks on the other, and one that only checks the first entry can be fooled. The rule is the same for both: the receiver's own identifier must appear, and a token addressed only to someone else is refused however good its signature.
The three time claims are NumericDate values, the seconds since the Unix epoch from Time and timestamps. Ava's token was issued at 1793174400, 08:00 UTC on 28 October 2026, and expires at 1793178000, an hour later. Clocks on different machines are never exactly aligned, so a receiver allows a small clock tolerance around exp and nbf, usually under a minute. Keep it small: on a token that lives only a few minutes, a generous allowance noticeably extends how long a stolen copy keeps working.
What the signature covers
Digital signatures established that a JWS signs the encoded header and payload exactly as they appear. In the compact form that input is easy to find: it is every character before the second dot. For Ava's token, the signing input is the first part, a dot and the second part, eyJhbGciOiJF...In0.eyJpc3MiOiJo...In0 written out in full, and the third part is the signature over those characters.
So a receiver splits the token at its dots and verifies the first two parts as they arrived. It doesn't decode the JSON, tidy it and encode it again first. Two tokens with the same claims but different spacing are different tokens with different signatures, and a gateway that reformats a payload on the way breaks its signature. Because the bytes are fixed, JWS needs none of the canonicalization that XML and XML signatures described.
One consequence comes after verification. The receiver now reads the claims from the very bytes it verified, and those bytes must mean one thing. JSON parsers disagree about a payload that names the same claim twice, some keeping the first value and some the last, so a careful receiver refuses a header or payload with a repeated name instead of guessing which one the issuer meant.
From decoded to accepted
Decoding Ava's token showed every claim without any key, and as Keys, encryption, and signatures put it, decoding proves nothing about whether the token is authentic or acceptable. The photo API gets from a decoded token to an accepted one through a series of checks, each made against something it already holds rather than something the token tells it:
- The format: three base64url parts, with a header and payload that are JSON.
- The algorithm:
algis on the API's own list for this issuer. - The type:
typisat+jwt, the kind of token this API accepts. - The key:
kidnames a key in the key setA JSON document, published at a fixed HTTPS address, that lists an issuer's current public keys so others can verify its signatures. It never contains private keys. the API trusts forhttps://auth.photos.example. - The signature: it verifies over the signing input with that key.
- The claims:
issis that issuer exactly,audcontains the API's own identifier, and the time claims fit the current time within the tolerance.
What the token states
- alg
- ES256
- typ
- at+jwt
- kid
- photos-2026-10
- Signature
- The third part
- iss
- https://auth.photos.example
- aud
- https://api.photos.example
- exp
- 1793178000
What the API already holds
- alg
- On the API's own list for this issuer
- typ
- The kind of token this API accepts
- kid
- A key in the key set the API trusts
- Signature
- Verifies over the signing input with that key
- iss
- That issuer exactly
- aud
- Contains the API's own identifier
- exp
- The current time within the tolerance
A token that fails any one check is refused
The claims are trusted only after the signature has verified, because until then anyone could have written them.
The order matters. The header checks are cheap and need no key, so a token with the wrong algorithm or type is refused before anything is fetched. The claims are trusted only after the signature has verified, because until then anyone could have written them. A token that fails any one check is refused, however many of the others it passes.
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
- Take a JWT apart and check what kind of token it isSplit a real signed token into its three parts, decode its header by hand, then hand the receiver an ID token with a genuine signature and see its type refused before any key is used.