Beta

Create a tenant

A new tenant starts with its own users, OAuth settings, audit history and logs. You are its first Tenant Admin.

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 server gives that application an access token for the photo API. 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
uPTDoQ9NdH0Sbu5lEwjHHKle47mulJBQovYKtw

A JSON Web Token (JWT) is a set of claims written as JSON and packed into a string that can sit in a header, a URL 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 Encryption, 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 base64url, 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:

  • typ names the kind of token. at+jwt is the registered name for an access token written as a JWT, and plain JWT is the generic value. One issuer 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 requires at+jwt can't be handed an ID token that happens to carry a good signature.
  • crit lists header parameters the receiver must understand. A receiver that meets a name in crit it 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.

Registered JWT claims
ClaimMeaning
issThe issuer: who made and signed the token. The receiver maps it to the key set it trusts for that issuer.
subThe subject: who or what the claims are about. It is unique only within its issuer.
audThe audience: who the token is for. A single string, or an array when the token names several recipients.
expExpiry: the token must be refused at or after this time.
nbfNot before: the token must be refused before this time.
iatIssued at: when the token was made.
jtiA 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:

  1. The format: three base64url parts, with a header and payload that are JSON.
  2. The algorithm: alg is on the API's own list for this issuer.
  3. The type: typ is at+jwt, the kind of token this API accepts.
  4. The key: kid names a key in the key set the API trusts for https://auth.photos.example.
  5. The signature: it verifies over the signing input with that key.
  6. The claims: iss is that issuer exactly, aud contains 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.

Each value the token states is compared with something the photo API already holds.

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.

A receiver reads aud expecting a single string, but this token's aud is an array of three names, one of them the receiver's own. What should happen? 1 of 3

Choose one answer.

A service issues tokens that live 60 seconds and allows 5 minutes of clock tolerance on exp. What is the effect? 2 of 3

Choose one answer.

The photo API accepts access tokens with typ at+jwt. An ID token signed by the same issuer, with a genuine signature, is sent to it as a bearer token. What should the API do? 3 of 3

Choose one answer.

Try it in the Lab

We value your privacy

We use cookies and similar technologies to enhance your browsing experience, and analytics to understand our traffic. By clicking "Allow all", you consent to optional analytics. Cookie Policy

Learn identity