Authentication establishes who a caller is; authorization decides what that identity may do.
Course navigationPhase 16⌄
Authentication Fundamentals
Understand identity primitives before using a vendor: credentials, password hashing, sessions, JWTs, cookies, CSRF, expiration, renewal, and revocation.
Phase outcome and project increment
Learning outcome
Understand identity primitives before using a vendor: credentials, password hashing, sessions, JWTs, cookies, CSRF, expiration, renewal, and revocation.
Concrete deliverable
Authentication threat/flow diagram explaining what the browser stores, what servers verify, and what happens when credentials expire.
Principles to keep while coding
Passwords, sessions, tokens, and cookies solve different parts of identity management and have different risks.
Treat credentials and tokens as secrets in transit, storage, logs, and browser code.
Design authentication flows around expiration, revocation, renewal, and failure states rather than only the happy path.
Guided phase lab
Do these in order. Each step should end with evidence before the next one starts.
- 01
Draw password login without writing code and mark where plain-text password may exist temporarily.
- 02
Compare opaque sessions and JWT access tokens by state, revocation, and verification model.
- 03
Explain secure/httpOnly/sameSite cookie attributes and when browser JS should not read a token.
- 04
Trace token expiration and refresh as a state machine rather than a happy-path callback.
- 05
Separate authentication (who) from authorization (may do what) with concrete TaskFlow examples.
- 06
Write abuse cases: stolen token, CSRF, XSS, replay, brute force, user ID spoofing.
Failures you should know how to diagnose
Treating base64 JWT content as proof of authenticity
Predict the symptom, capture evidence at the nearest boundary, change one variable, and verify the same reproduction after the fix.
Storing long-lived secrets in localStorage by default
Predict the symptom, capture evidence at the nearest boundary, change one variable, and verify the same reproduction after the fix.
Confusing hidden UI with authorization
Predict the symptom, capture evidence at the nearest boundary, change one variable, and verify the same reproduction after the fix.
No plan for expired/revoked sessions
Predict the symptom, capture evidence at the nearest boundary, change one variable, and verify the same reproduction after the fix.
Lessons
The source chapters come first. Every phase now ends with a guided build, a debugging workshop, and an independent challenge so reading turns into transferable skill.
Identity Authentication and Authorization
Identity, Authentication & Authorization Separate who the caller is from what the caller may do Phase 16 - Authentication Fundamentals Volume 05 - Authentication & Security Architecture mile
Passwords MFA and Modern Authenticators
Passwords, MFA & Modern Authenticators Understand credential security without building a password system from scratch Phase 16 - Authentication Fundamentals Volume 05 - Authentication & Secu
Sessions Cookies and Browser Storage
Sessions, Cookies & Browser Storage Understand authenticated continuity and the security consequences of storage choices Phase 16 - Authentication Fundamentals Volume 05 - Authentication & S
JWT Structure Claims and Verification
JWT Structure, Claims & Verification Decode for inspection, verify for trust, and validate the claims your API requires Phase 16 - Authentication Fundamentals Volume 05 - Authentication & Se
Access Refresh Tokens and Bearer Risk
Access Tokens, Refresh Tokens & Bearer Risk Understand short-lived API credentials, refresh lifecycles, and replay risk Phase 16 - Authentication Fundamentals Volume 05 - Authentication & Se
Login Logout Expiry and Revocation
Login, Logout, Expiry & Revocation Treat authentication as a complete lifecycle instead of a login screen Phase 16 - Authentication Fundamentals Volume 05 - Authentication & Security Archite
XSS CSRF CORS and HTTPS
XSS, CSRF, CORS & HTTPS Separate browser threats and match mitigations to the correct security problem Phase 16 - Authentication Fundamentals Volume 05 - Authentication & Security Architectu
TaskFlow Target Authentication Architecture
TaskFlow Target Authentication Architecture Define exactly how Supabase Auth, Next.js, NestJS, and business authorization will divide responsibilities Phase 16 - Authentication Fundamentals
NestJS Guard and Protected API Mental Model
NestJS Guard & Protected API Mental Model Understand the future token-verification boundary before implementing it Phase 16 - Authentication Fundamentals Volume 05 - Authentication & Securit
Threat Modeling Observability and Debugging
Threat Modeling, Observability & Debugging Trace credentials and failures without leaking secrets or weakening security Phase 16 - Authentication Fundamentals Volume 05 - Authentication & Se
Hands On Reasoning Lab and Phase Exit
Hands-On Reasoning Lab & Phase Exit Prove that the authentication model is understood before Supabase Auth implementation Phase 16 - Authentication Fundamentals Volume 05 - Authentication &
Guided Build Lab
Purpose Understand identity primitives before using a vendor: credentials, password hashing, sessions, JWTs, cookies, CSRF, expiration, renewal, and revocation.
Debugging Workshop
Goal Learn to diagnose this phase's failures systematically instead of reinstalling packages, changing random configuration, or copying a fix without understanding it.
Phase Synthesis & Independent Challenge
Mission Rebuild the capability of Phase 16 without following the exact code line-by-line. The goal is transfer: can you use the ideas when the variable names, UI, or route shape changes?
Mastery Capstone Lab
Integrate Phase 16 without following a transcript.
Exercises that increase independence
Draw password login without writing code and mark where plain-text password may exist temporarily.
Explain secure/httpOnly/sameSite cookie attributes and when browser JS should not read a token.
reproduce and diagnose — Treating base64 JWT content as proof of authenticity.
deliver Authentication threat/flow diagram explaining what the browser stores, what servers verify, and what happens when credentials expire.
Can explain session vs token and Can identify browser storage risks.
Do not leave the phase only because you reached the bottom
Phase exit criteria
Scenario and concept quiz
These questions test engineering choices rather than whether you remember a lesson title.
Reference files
Attempt the work first. Use snapshots to compare a checkpoint, not as a substitute for understanding.
reference/TaskFlow_Auth_Fundamentals/auth-mental-model.md
# TaskFlow Authentication Mental Model Authentication answers: Who is this caller? Authorization answers: What may this authenticated caller do? Target direction for later phases: Browser -> authentication provider (Supabase Auth in Phase 17) -> authenticated session -> access token -> Next.js -> Authorization: Bearer <access-token> -> NestJS authentication guard -> verified identity -> service/business logic -> authorization/ownership checks Do not accept userId from the browser as proof of identity. Do not put credentials, refresh tokens, session identifiers, or long-lived bearer tokens in URLs.
reference/TaskFlow_Auth_Fundamentals/http-examples.txt
# Bearer token request GET /tasks HTTP/1.1 Host: api.example.com Authorization: Bearer <access-token> # Example hardened session cookie shape (illustrative) Set-Cookie: __Host-taskflow_session=<opaque-id>; Path=/; Secure; HttpOnly; SameSite=Lax # Do NOT do this GET /tasks?access_token=<token> GET /tasks?userId=<browser-supplied-id> # Do NOT log these Authorization: Bearer ... Cookie: ... password=... refresh_token=...
reference/TaskFlow_Auth_Fundamentals/jwt-claims-reference.md
# JWT Claims Reference A JWT commonly contains registered claims such as: - iss - issuer - sub - subject - aud - intended audience - exp - expiration time - nbf - not before - iat - issued at - jti - token identifier Important: Base64url decoding is not validation. A resource server must verify the cryptographic signature and enforce the claims required by its security policy. JWT payloads are not automatically confidential. Do not put secrets into ordinary signed JWT claims.
reference/TaskFlow_Auth_Fundamentals/phase17-readiness.md
# Phase 17 Readiness Before Supabase Auth integration, the learner should be able to explain: 1. Identity vs credential vs session. 2. Authentication vs authorization. 3. Access token vs refresh token. 4. Why bearer tokens are credentials. 5. Why decoding a JWT does not prove authenticity. 6. What iss, sub, aud, and exp mean. 7. Why browser token storage is a security decision. 8. HttpOnly / Secure / SameSite cookie attributes. 9. XSS vs CSRF at a high level. 10. Why NestJS must derive identity from a verified token rather than from userId supplied by the caller.
reference/TaskFlow_Auth_Fundamentals/security-checklist.md
# Authentication Security Checklist - Keep authentication and authorization conceptually separate. - Prefer a mature identity provider over writing password authentication from scratch. - Passwords must never be stored in plaintext. - Password storage uses a slow password hashing function, not a fast general-purpose hash. - Use HTTPS for authentication and authenticated requests. - Treat bearer tokens like credentials. - Validate JWT signature plus application-required claims such as issuer, audience, and expiration. - Never trust a JWT only because it can be decoded. - Keep access tokens short-lived. - Protect refresh tokens more strongly than access tokens and support rotation/revocation where the provider does. - Avoid browser localStorage/sessionStorage for authentication tokens when a safer HttpOnly cookie or BFF/session pattern is available. - Cookie-based sessions should use Secure, HttpOnly, and an intentional SameSite policy. - Cookie authentication requires CSRF reasoning. - JavaScript-readable token storage requires strong XSS reasoning. - Do not log passwords, access tokens, refresh tokens, session IDs, authorization headers, or cookies. - Logout is a lifecycle operation, not merely hiding the UI. - Re-authenticate for sensitive operations when product risk justifies it. - Rate-limit authentication endpoints and monitor suspicious behavior.