About JSON Web Tokens (JWT)
A JSON Web Token (JWT, pronounced "jot") is a compact, URL-safe means of representing claims to be transferred between two parties. Defined by RFC 7519, JWTs have become the de facto standard for authentication and authorization in modern web applications, mobile apps, and APIs.
Every JWT consists of three parts separated by dots (.), each part being a Base64URL-encoded string:
- Header: Contains metadata about the token, including the signing algorithm (like HS256, RS256) and the token type (JWT).
- Payload: Contains the claims - statements about the user and additional metadata. Standard claims include exp (expiration), iat (issued at), sub (subject/user ID), iss (issuer), and aud (audience).
- Signature: Created by encoding the header and payload, then signing them with a secret key (for HMAC algorithms) or a private key (for RSA/ECDSA). This ensures the token hasn't been tampered with.