CONCEPT SHEET · Concepts

Security Basics: AuthN and AuthZ

One-liner: Authentication proves who you are, authorization decides what you may do; TLS protects the wire, hashing protects stored passwords, and secrets never live in code.

ArticleConcepts© Arthur Bernier Jr610 words1 code block

Say this#

How it works#

TEXT
browser -> /login (Authorization Code + PKCE) -> Auth Server (Auth0/Okta/Cognito/Keycloak)       <- code -> backend exchanges code -> access token (JWT, 15 min) + refresh token (rotating)browser -> API with Authorization: Bearer <JWT> -> gateway verifies signature (JWKS), checks exp/aud/iss       -> service checks authz: role/permission or policy -> resource
  1. Hash passwords with Argon2id/bcrypt (cost tuned to ~100-250 ms); compare in constant time.
  2. Issue short-lived JWT access tokens signed RS256/ES256; publish public keys via JWKS; rotate keys.
  3. Refresh tokens stored server-side (hashed), rotated on use, revocable; reuse detection kills the family.
  4. Authorize at the gateway for coarse checks (valid token, scope) and in the service for resource-level checks (is this your order).
  5. Cookies: HttpOnly; Secure; SameSite=Lax/Strict; CSRF tokens for cookie-based sessions.

Trade-offs#

ChoiceProCon
Server sessionsInstant revocation, small cookieLookup per request (Redis); sticky or shared store
JWTStateless verify, works across servicesRevocation needs blocklist or short TTL; token size; key management
RBACEasy to reason about and auditRole explosion for fine-grained needs
ABAC / policy engineExpressive, centralized policyHarder to audit "who can access X"
Own authControlYou will get something wrong; use Auth0/Okta/Cognito/Keycloak
bcryptBattle-testedMemory-cheap for GPUs vs Argon2id

Numbers#

  • Access token TTL: 5-15 min; refresh token: days to weeks with rotation.
  • bcrypt cost 10-12 (~100-300 ms); Argon2id: e.g. 64 MB memory, 3 iterations, tuned to similar time.
  • TLS 1.3 handshake: 1 RTT (0-RTT resumption possible); TLS 1.2: 2 RTT.
  • JWT verification: ~0.05-0.5 ms (ES256/RS256) per request; a Redis session lookup ~0.5 ms.

In the interview#

See also