STACK
Ch 08 · AuthN & AuthZ
Chapter 08 · Identity & access

AuthN & AuthZ — OAuth, OIDC, passkeys, RBAC / ABAC / ReBAC

Authentication says who you are. Authorization says what you can do. Get either wrong and the rest of the stack doesn't matter.

8.1 · Vocabulary

TermMeaning
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.
FederationTrusting another IdP via SAML / OIDC.
SSOOne login → many apps.
SCIMStandard for provisioning/deprovisioning users across SaaS.

8.2 · OAuth 2.1 — the modern flows

FlowUse caseNotes
Authorization Code + PKCESPAs, mobile, server apps.The default for everything user-facing.
Client CredentialsService → service.No user involved.
Device CodeCLIs, 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

FormatNotes
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.
PASETOModern alternative to JWT — fewer foot-guns (no alg: none, no algorithm confusion).
DPoPDemonstrating Proof-of-Possession — binds tokens to a key the client holds. Mitigates stolen-token replay.
mTLS-boundToken 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

FactorStrength
Passkey / hardware key (FIDO2)Phishing-resistant. Best.
TOTP (Authenticator app)Strong, phishable.
Push notification (number-match)Strong with prompt-bombing mitigations.
SMSWeak — SIM swap risk. Last resort.
Email magic linkDepends 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 (or Strict / None with care).
  • CSRF: SameSite + double-submit token or origin checks.
  • Don't store JWTs in localStorage for high-value apps — XSS reads it.

8.8 · Authorization models

ModelDefinitionUse when
RBACRoles → permissions ("admin can delete").Few roles; small surface.
ABACAttributes (user, resource, context) → policy.Complex rules ("doctors can read patients in their hospital, during shift").
ReBACRelationships ("X is owner of Y").Sharing, multi-tenant, graphs (Google Zanzibar).
PBAC / Policy-as-codeDecisions in a separate engine (OPA, Cedar, Topaz, Oso).Auditable, externalised policies.
CapabilitiesUnforgeable tokens granting specific access.Distributed systems, capability URLs.

8.9 · Policy-as-code engines

EngineLanguageUse
OPA / RegoRego DSLK8s admission, gateway, infra.
CedarCedar (AWS)AWS Verified Permissions; app authz.
TopazRego + ReBACOpen-source authorizer.
OsoPolar DSLEmbedded in app code.
SpiceDB / Permify / WarrantZanzibar-styleReBAC at scale.

8.10 · Provider map

ProviderSweet spot
Auth0 (Okta)Enterprise; rich integrations.
ClerkPolished UI components for B2C apps.
WorkOSB2B SSO + SCIM + Directory Sync.
CognitoAWS-native; cheap; rough DX.
KeycloakOSS, self-hosted, full-featured.
Ory (Kratos / Hydra / Keto)OSS modular stack.
Supabase AuthEmbedded in the Supabase stack.
Firebase AuthMobile-first; Google ecosystem.
FusionAuthSelf-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