Security

What Is a JSON Web Token (JWT)? Architecture & Claims Explained

A deep dive into RFC 7519: how header, payload, and signature work together, standard registered claims, and vital security precautions for developers.

## What Is a JWT? A **JSON Web Token (JWT)**, defined under **RFC 7519**, is a compact, URL-safe means of representing claims to be transferred between two parties. JWTs are commonly used for stateless user authentication and OAuth 2.0 authorization grants. A JWT consists of three distinct parts separated by periods (`.`): ``` header.payload.signature ``` --- ## The Three Components of a JWT ### 1. The Header The header typically consists of two parts: the token type (`JWT`) and the signing algorithm being used, such as HMAC SHA256 (`HS256`) or RSA (`RS256`). ```json { "alg": "HS256", "typ": "JWT" } ``` ### 2. The Payload The payload contains the claims. Claims are statements about an entity (typically, the user) and additional metadata. There are three types of claims: registered, public, and private claims. Standard registered claims include: - `iss` (issuer): Identifies who created the token. - `sub` (subject): The user ID or principal. - `exp` (expiration time): Unix timestamp after which the token is invalid. - `iat` (issued at): Unix timestamp when the token was created. - `aud` (audience): The intended recipient service. ```json { "sub": "usr_99812", "name": "Sarah Connor", "role": "admin", "iat": 1772640000, "exp": 1772643600 } ``` ### 3. The Signature To create the signature part you must take the encoded header, the encoded payload, a secret key, and the algorithm specified in the header, and sign that: ``` HMACSHA256( base64UrlEncode(header) + "." + base64UrlEncode(payload), secretKey ) ``` The signature guarantees that the sender of the JWT is who it says it is and verifies that the message wasn't changed along the way. --- ## Critical Security Guidelines 1. **Decoding Is NOT Verification**: Anyone can decode the Base64URL string of a JWT and view the payload claims. **Decoding does not prove authenticity** unless the digital signature is cryptographically verified against your server secret or public key. 2. **Never Store Passwords in Claims**: Because payloads are merely Base64URL-encoded (not encrypted), never store sensitive secrets, passwords, or credit card numbers inside JWT claims. 3. **Always Check the Expiration (`exp`) Claim**: Applications must reject tokens whose `exp` timestamp is in the past. Inspect and decode your tokens safely using the [LABSTACK JWT Decoder](/tools/jwt-decoder).