ENES

JWT

A signed, self-contained pass that tells a server who you are and what you may do.

A token split into three colored parts separated by dots: header, payload and signature, with the payload showing a user id and an expiry time

A JWT (JSON Web Token, often pronounced "jot") is a compact string that carries a few facts about a user, called claims, plus a cryptographic signature. It has three parts separated by dots: a header that names the signing algorithm, a payload with the claims (for example sub for the user id and exp for the expiry time) and the signature. Each part is base64url-encoded JSON, so it travels easily in an HTTP header like Authorization: Bearer eyJ.... The format is defined in RFC 7519.

The point is that a server can check a JWT without looking anything up. The login service signs the token with a secret key (HMAC, as in HS256) or a private key (as in RS256 or ES256), and any API that holds the matching key can verify that nobody changed a single character. That makes JWTs popular in microservices and in OpenID Connect, where the ID token you get after "Sign in with Google" is a JWT.

Two traps catch beginners. First, a signed JWT is not encrypted: anyone who grabs it can decode the payload and read it, so it must never hold secrets, and it should only travel over HTTPS. Second, because verification needs no database, a stolen JWT keeps working until it expires. The usual answer is short lifetimes (minutes) plus a separate refresh token that the server can revoke. Libraries must also reject tokens whose header says "alg": "none" or switches the algorithm, a classic source of vulnerabilities.

Keep in mind

Go deeper

Related terms

More in Security