Course navigationPhase 16
Volume 05 · Phase 16

Authentication Fundamentals

Understand identity primitives before using a vendor: credentials, password hashing, sessions, JWTs, cookies, CSRF, expiration, renewal, and revocation.

15lessons + labs
6klesson words
5source references
What you will ship

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.

Figure 16.1 — Where this phase lives in TaskFlow
credential/sign-in
identity provider
session/token
browser storage/cookie
API verification
authenticated identity
Trace the flow left-to-right for implementation and right-to-left for debugging. At every arrow, ask what data crosses the boundary and what proves it is trustworthy.
Instructor mental model

Principles to keep while coding

01

Authentication establishes who a caller is; authorization decides what that identity may do.

02

Passwords, sessions, tokens, and cookies solve different parts of identity management and have different risks.

03

Treat credentials and tokens as secrets in transit, storage, logs, and browser code.

04

Design authentication flows around expiration, revocation, renewal, and failure states rather than only the happy path.

Code-along path

Guided phase lab

Do these in order. Each step should end with evidence before the next one starts.

  1. 01

    Draw password login without writing code and mark where plain-text password may exist temporarily.

  2. 02

    Compare opaque sessions and JWT access tokens by state, revocation, and verification model.

  3. 03

    Explain secure/httpOnly/sameSite cookie attributes and when browser JS should not read a token.

  4. 04

    Trace token expiration and refresh as a state machine rather than a happy-path callback.

  5. 05

    Separate authentication (who) from authorization (may do what) with concrete TaskFlow examples.

  6. 06

    Write abuse cases: stolen token, CSRF, XSS, replay, brute force, user ID spoofing.

Debugging studio

Failures you should know how to diagnose

Failure drill 1

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.

Failure drill 2

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.

Failure drill 3

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.

Failure drill 4

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.

Watch-order style

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.

01

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

2 min
02

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

2 min
03

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

2 min
04

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

2 min
05

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

2 min
06

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

2 min
07

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

2 min
08

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

2 min
09

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

2 min
10

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

2 min
11

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 &

3 min
LAB

Guided Build Lab

Purpose Understand identity primitives before using a vendor: credentials, password hashing, sessions, JWTs, cookies, CSRF, expiration, renewal, and revocation.

3 min
LAB

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.

2 min
LAB

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?

2 min
LAB

Mastery Capstone Lab

Integrate Phase 16 without following a transcript.

2 min
Practice ladder

Exercises that increase independence

Guided

Draw password login without writing code and mark where plain-text password may exist temporarily.

Practice

Explain secure/httpOnly/sameSite cookie attributes and when browser JS should not read a token.

Debug

reproduce and diagnose — Treating base64 JWT content as proof of authenticity.

Independent

deliver Authentication threat/flow diagram explaining what the browser stores, what servers verify, and what happens when credentials expire.

Explain-back

Can explain session vs token and Can identify browser storage risks.

Mastery gate

Do not leave the phase only because you reached the bottom

Phase exit criteria

Knowledge check

Scenario and concept quiz

These questions test engineering choices rather than whether you remember a lesson title.

0/0 correct · 0/8 answered
01Which practice best matches Phase 16's engineering goal?
02Which practice best matches Phase 16's engineering goal?
03Which practice best matches Phase 16's engineering goal?
04Which practice best matches Phase 16's engineering goal?
05You are working through the Phase 16 lab. Which next action is the most disciplined step?
06You are working through the Phase 16 lab. Which next action is the most disciplined step?
07You are working through the Phase 16 lab. Which next action is the most disciplined step?
08You are working through the Phase 16 lab. Which next action is the most disciplined step?
Source snapshot

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.