A practical JWT reference for web/mobile API authentication.
Token format
header.payload.signature (base64url parts). Signature verifies integrity; payload is not encrypted by default.
Common claims
{
"sub": "user_123",
"iss": "api.example.com",
"aud": "web",
"iat": 1710000000,
"exp": 1710003600,
"scope": "read:posts"
}
Access + refresh pattern
- Short-lived access token (e.g., 5-15 min).
- Longer refresh token rotated on use.
- Revoke refresh token server-side on logout/compromise.
Storage trade-offs
- HTTP-only secure cookies mitigate XSS token theft.
- LocalStorage is simpler but exposed to XSS.
Security checks
- Validate signature +
exp+iss+aud. - Reject
nonealgorithm. - Use HTTPS everywhere.