← Cheat Sheets
JWT, OAuth and Auth Basics
How token-based authentication fits together.
# JWT, OAuth and Auth Basics
How token-based authentication fits together.
**JWT structure:** `header.payload.signature`, each Base64URL-encoded. The payload is readable by anyone; the signature only proves it was not altered. Never store secrets in it.
| Claim | Meaning |
|---|---|
| `iss` | Issuer |
| `sub` | Subject (user id) |
| `aud` | Audience |
| `exp` | Expiry (Unix seconds) |
| `iat` | Issued at |
**OAuth 2.0 authorization code flow:** the app redirects to the provider, the user consents, the provider returns a code, the app's server exchanges the code for tokens. Use PKCE for public clients.
**Good practice:** short-lived access tokens, HTTPS only, `HttpOnly` cookies for browser sessions, validate `exp`, `iss` and `aud`.