JWT & OAuth 2.0 Syntax Cheat Sheet
Quick reference guide for JWT & OAuth 2.0: Structure, authorization code grant + PKCE, client credentials, and claims.
Security Tools
jwt
oauth2
auth
JSON Web Tokens (JWT) and OAuth 2.0 provide standardized authentication and authorization frameworks for web applications and APIs.
JWT Token Structure
A JWT consists of three Base64URL-encoded parts separated by dots (.):
header.payload.signature
text
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.
eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.
SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
Standard Registered JWT Claims
Table
| Claim Key | Name | Purpose / Example Value |
|---|---|---|
iss | Issuer | Principal issuing token ("https://auth.example.com") |
sub | Subject | User or principal ID ("user_123") |
aud | Audience | Recipient target for token ("https://api.example.com") |
exp | Expiration Time | Unix timestamp after which token is invalid (1750000000) |
nbf | Not Before | Unix timestamp before which token must not be accepted |
iat | Issued At | Unix timestamp when token was created |
jti | JWT ID | Unique identifier for the token (nonce/replay protection) |
OAuth 2.0 Grant Types Summary
Table
| Grant Type | Best Use Case | Flow Overview |
|---|---|---|
| Authorization Code + PKCE | SPA & Mobile Apps | User logs in in browser -> Auth code returned -> Exchanged for Tokens with Code Verifier |
| Client Credentials | Server-to-Server APIs | Backend server authenticates with client_id & client_secret directly |
| Refresh Token | Token Renewal | Exchange long-lived refresh_token for new short-lived access_token |
Common Pitfalls & Tips
[!WARNING] Never store sensitive private keys or plain passwords inside JWT payloads! JWT payloads are Base64 encoded, not encrypted, and can be read by anyone.
[!TIP] Always enforce algorithm verification on the backend to prevent
alg: "none"token forgery attacks.