Authentication verifies identity; authorization decides access. Web apps use sessions or JWTs, secure cookies, OAuth for third-party login, and hashed passwords never stored in plain text.
How to use this Authentication cheat sheet
Session auth stores server-side state with a session ID in an HttpOnly cookie. JWTs embed claims signed by the server; access tokens are short-lived with refresh tokens rotated in secure storage. Cookie flags Secure, HttpOnly, and SameSite reduce XSS and CSRF risk.
OAuth 2.0 delegates login to providers (Google, GitHub) via authorization code flow with PKCE for SPAs. CSRF tokens protect cookie-based forms. Passwords use bcrypt or Argon2 with per-user salt; never roll your own crypto.
Pair CSRF tokens with SameSite cookies for defense in depth.
Common mistakes
Storing JWTs in localStorage where any XSS script can exfiltrate them.
Using SameSite=None without Secure flag on cookies.
Skipping PKCE on SPA OAuth flows because the client is public.
Storing passwords with fast hashes (SHA256) instead of bcrypt/Argon2.
Key takeaways
Sessions for traditional apps; short-lived JWTs plus refresh for APIs.
HttpOnly, Secure, SameSite cookies and CSRF tokens protect cookie-based auth.
OAuth authorization code with PKCE for third-party login in browsers.
Hash passwords with bcrypt/Argon2; rotate refresh tokens and detect reuse.
Pro Tip
Use a dedicated auth library (Passport, Auth.js, or your cloud IdP SDK) instead of assembling JWT parsing, cookie flags, and OAuth flows from blog snippets.
Keep this Authentication cheat sheet open while you code, then continue with resources for deeper links and practice material.