Bookmarks

JWT — JSON Web Token

A compact token in the form of a string of three Base64url parts — header, set of claims and signature — which services use to pass information about a user.

Also: JWT, web token, JOT

checked 9 Nov

All terms

The format is described in RFC 7519 (IETF, May 2015). The server that issues a token signs it with its key, and any service holding the verification key can confirm that the claims have not been forged — without querying a database or the server that issued the token. In OpenID Connect the ID token is built this way; for OAuth 2.0 access tokens, the JWT format is fixed by the RFC 9068 profile.

How a token is built

A JWT is a single string of three parts separated by dots: a header, a set of claims and a signature. Each part is encoded in Base64url — a variant of Base64 without characters that are unsafe in URLs, so the token travels safely in an HTTP header, an address or a request body.

bash
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VyLTQyIn0.K_mvT7ZlE # header:    {"alg": "HS256", "typ": "JWT"}# claims:    {"sub": "user-42"}# signature: HMAC-SHA256(header + "." + claims, secret key)#            (the base64url-encoded input is what gets signed, RFC 7515)

The header names the signing algorithm: HS256 is HMAC with SHA-256 and a secret shared by issuer and verifier, while RS256 and ES256 are signatures made with a private key and checked with a public key. Asymmetric algorithms suit microservices: services verify the signature with the public key and never hold the issuer’s secret.

Registered claims

Claims are arbitrary name–value pairs, but the standard defines a set of registered names:

ClaimMeaning
iss (issuer)who issued the token
sub (subject)whom the claims are about — usually a user identifier
aud (audience)the recipients the token is intended for
exp (expiration)the time, in seconds, from which the token is no longer valid
nbf (not before)the time before which the token must not be accepted
iat (issued at)when the token was issued
jti (JWT ID)a unique identifier for the token

The verifying party checks iss, aud and the validity period: a correctly signed token whose exp has passed must not be accepted. A single JWT cannot be revoked before it expires; to handle that, systems keep lists of revoked tokens or issue short-lived ones.

Signed, not encrypted

The payload of a JWT is only encoded, not encrypted: anyone who obtains the token can read the claims with an ordinary Base64 decoder. The signature guarantees something else — that the content has not changed since issue and that the token was issued by someone holding the key. Never put secret data inside. If the content must be hidden, use JWE (RFC 7516), the encrypted variant of the same format; a standard signed token is called a JWS (RFC 7515).

Sources

the term is written from these pages

Verified 9 Nov

Not to be confused with

what it is mixed up with and how it differs

  • OAuth 2.0

    OAuth 2.0 is a protocol for delegating access, while a JWT is just a token format that the protocol can exchange.

  • TLSTLS protocol

    TLS encrypts the transport channel, not the token itself: a signed JWT can be read by anyone who receives it.

In depth in the references

where the topic is covered in detail