8.1 · Vocabulary
| Term | Meaning |
|---|---|
| Authentication (AuthN) | Verifying identity — "who are you?" |
| Authorization (AuthZ) | Granting / denying access — "what can you do?" |
| Identity provider (IdP) | Service that authenticates users (Okta, Auth0, Google). |
| Service provider (SP) | Your app that trusts the IdP. |
| Federation | Trusting another IdP via SAML / OIDC. |
| SSO | One login → many apps. |
| SCIM | Standard for provisioning/deprovisioning users across SaaS. |
8.2 · OAuth 2.1 — the modern flows
| Flow | Use case | Notes |
|---|---|---|
| Authorization Code + PKCE | SPAs, mobile, server apps. | The default for everything user-facing. |
| Client Credentials | Service → service. | No user involved. |
| Device Code | CLIs, TVs, kiosks. | User logs in on phone, device polls. |
| Refresh Token (rotating) | Renew access without re-auth. | Always rotate; revoke on suspicion. |
| Token Exchange (RFC 8693) | Service A → service B on behalf of user. | Replaces older "delegation" hacks. |
Implicit and ROPC (password) flows are deprecated.
8.3 · OIDC — OpenID Connect
OIDC is an identity layer on top of OAuth 2. The flow returns an ID Token (JWT) describing who the user is, alongside an Access Token for API calls. The userinfo endpoint returns extra claims.
8.4 · Tokens — JWT, opaque, PASETO
| Format | Notes |
|---|---|
| JWT (JWS / JWE) | Self-contained signed claims; verify with the IdP's JWKS. Easy to inspect, hard to revoke before expiry. |
| Opaque (reference) | Random ID; server looks up state. Easy to revoke; extra round trip to the IdP. |
| PASETO | Modern alternative to JWT — fewer foot-guns (no alg: none, no algorithm confusion). |
| DPoP | Demonstrating Proof-of-Possession — binds tokens to a key the client holds. Mitigates stolen-token replay. |
| mTLS-bound | Token is only valid from a specific client cert. |
Best practice: short-lived access tokens (5–15 min) + rotating refresh tokens + revocation list / introspection endpoint.
8.5 · Passkeys / WebAuthn / FIDO2
- Public-key auth bound to the relying-party domain — phishing-resistant.
- Synced via OS / password manager; user unlocks with biometric.
- Standard in 2026 — replace passwords + TOTP where you can.
- iOS, Android, Windows, macOS, Chrome, Safari, Firefox all support.
8.6 · Multi-factor authentication
| Factor | Strength |
|---|---|
| Passkey / hardware key (FIDO2) | Phishing-resistant. Best. |
| TOTP (Authenticator app) | Strong, phishable. |
| Push notification (number-match) | Strong with prompt-bombing mitigations. |
| SMS | Weak — SIM swap risk. Last resort. |
| Email magic link | Depends on email security; OK as a fallback. |
8.7 · Sessions & cookies
- Server-side sessions are still fine for first-party apps; simpler than JWT.
- Cookies:
HttpOnly·Secure·SameSite=Lax(orStrict/Nonewith care). - CSRF: SameSite + double-submit token or origin checks.
- Don't store JWTs in
localStoragefor high-value apps — XSS reads it.
8.8 · Authorization models
| Model | Definition | Use when |
|---|---|---|
| RBAC | Roles → permissions ("admin can delete"). | Few roles; small surface. |
| ABAC | Attributes (user, resource, context) → policy. | Complex rules ("doctors can read patients in their hospital, during shift"). |
| ReBAC | Relationships ("X is owner of Y"). | Sharing, multi-tenant, graphs (Google Zanzibar). |
| PBAC / Policy-as-code | Decisions in a separate engine (OPA, Cedar, Topaz, Oso). | Auditable, externalised policies. |
| Capabilities | Unforgeable tokens granting specific access. | Distributed systems, capability URLs. |
8.9 · Policy-as-code engines
| Engine | Language | Use |
|---|---|---|
| OPA / Rego | Rego DSL | K8s admission, gateway, infra. |
| Cedar | Cedar (AWS) | AWS Verified Permissions; app authz. |
| Topaz | Rego + ReBAC | Open-source authorizer. |
| Oso | Polar DSL | Embedded in app code. |
| SpiceDB / Permify / Warrant | Zanzibar-style | ReBAC at scale. |
8.10 · Provider map
| Provider | Sweet spot |
|---|---|
| Auth0 (Okta) | Enterprise; rich integrations. |
| Clerk | Polished UI components for B2C apps. |
| WorkOS | B2B SSO + SCIM + Directory Sync. |
| Cognito | AWS-native; cheap; rough DX. |
| Keycloak | OSS, self-hosted, full-featured. |
| Ory (Kratos / Hydra / Keto) | OSS modular stack. |
| Supabase Auth | Embedded in the Supabase stack. |
| Firebase Auth | Mobile-first; Google ecosystem. |
| FusionAuth | Self-hosted alternative to Auth0. |
8.11 · Self-check
Q1 · A bearer token stolen via XSS keeps working until it expires. Best mitigation?
Longer expiry
Bind the token to a client key (DPoP / mTLS)
Larger token
Base64-encode it twice