A deep dive into JSON Web Tokens — how they're structured, what claims mean, and why they're the backbone of modern authentication.
A JSON Web Token (JWT) is a compact, URL-safe token for securely transmitting information between parties. It's the standard for stateless authentication — your server doesn't need to store sessions because the token itself carries all the info.
A JWT looks like this:
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIn0.dozjgNryP4J3jVmNHl0w5N_XgL0n3I9PlFUP0THsR8U
Three Base64URL-encoded parts separated by dots: header.payload.signature.
{
"alg": "HS256",
"typ": "JWT"
}
alg: The signing algorithm — HS256 (HMAC-SHA256), RS256 (RSA), ES256 (ECDSA)typ: Always JWT{
"sub": "user_123",
"name": "Trong Ngo",
"roles": ["admin"],
"iat": 1716239022,
"exp": 1716325422
}
Registered claims: sub (subject), iss (issuer), aud (audience), iat (issued at), exp (expiration).
HMACSHA256(base64UrlEncode(header) + "." + base64UrlEncode(payload), secret)
The signature ensures the token hasn't been tampered with. Without the secret, an attacker can't forge a valid token.
Authorization: Bearer <token>exp to ensure it hasn't expiredUse the JWT Decoder to inspect any token instantly.