Pronounced "jot"
Open standard (RFC 7519) for authorization
Often paired with OAuth for Single Sign On
The authorization token is generated by Identity Provided (IdP) for Customer Identity and Access Management (CIAM)
Generally included in "Authorization" header: Authorization: Bearer <token>
Contains header, payload, signature base64 encoded and separated by a dot (.)
The header typically ocontains "typ": "JWT" and "alg" (usually HMAC SHA256 or RSA) E.g.,
{
"alg": "HS256",
"typ": "JWT"
}The payload contains claims, including: 1. registered claims: recommended (but not required) claims; e.g., iss, exp, aud, etc 2. public claims: claims that are either registered in a registry or expressed as URIs 3. private claims: custom claims
E.g.,
{
"sub": "1234567890",
"name": "John Doe",
"admin": true
}Authorization tokens expire in minutes, often paired with refresh tokens
Pros:
- portable
- efficient (less chatty, e.g., less db calls)
- compact
- verifiable (digitally signed)
- stateless (not tracked in server)
- CORS compatible (unlike cookies, which must be configured)
- JSON naturally maps to programming objects
Cons:
- hard to revoke (e.g., log out, block or terminate account)
- can’t be too big (some servers have 8 KB header limits)
Best Practices:
- use HTTPS to avoid MITM attacks
- always validate
- Use asymetric encryption (e.g., RSA)
- avoid HMAC (symmetic, too efficient)
- don’t accept
"alg": "none" - use short-lived access tokens
Alternatives:
- Sessions (e.g., login, server returns session ID as cookie)
- Simple Web Tokens (SWT, only symmetrically signed)
- SAML (XML, so verbose; compex)