How a login survives stateless HTTP. The password is sent exactly once. Afterwards a random session ID in a cookie stands in for it, and any web server can look the ID up in the shared session store.
The password is sent once. A random session ID in a cookie stands in for it afterwards
Any web server in the pool looks the ID up in the shared session store
The cookie is as good as the password while it lasts: HTTPS-only, invisible to JavaScript, re-ask for sensitive actions
This is exactly what lets stateless, load-balanced servers work
The same mechanism lets advertisers track browsers across sites: hence consent banners
Apps and APIs often use a signed token (a JSON Web Token) sent in a header instead of a cookie
Session 5 · 5.4 HTTP Basic Authentication and API keys · 1/2Book ↗
The simplest scheme, built into HTTP
Basic Authentication. The credentials ride along on every request in a trivially reversible encoding. The protection comes entirely from HTTPS.
Basic Auth sends username:password on every request, encoded in Base64, which anyone can decode
Only over HTTPS; only for staging sites, internal tools, and some APIs
Session 5 · 5.4 HTTP Basic Authentication and API keys · 2/2Book ↗
API keys are passwords for programs
A long random secret a provider issues so it knows whom to bill
Stored in server configuration (environment variables, a .env file); never in front-end code; never in Git
Bots scan GitHub constantly for leaked keys and can spend thousands within minutes
The single most important habit when building with Claude Code and the Claude API.
Session 5 · 5.5 OAuth: how "Sign in with Google" works · 1/3Book ↗
The problem OAuth solves
New apps want login without another password; apps want to use your Google Calendar or bank on your behalf
Typing your Google password into a third-party app would give it everything, forever
OAuth 2.0: the user approves a limited request at the trusted service; the app gets a valet key
Four roles: resource owner (you), client (the app), authorization server (Google login), resource server (Google's API)
Session 5 · 5.5 OAuth: how "Sign in with Google" works · 2/3Book ↗
The authorization-code flow
The OAuth authorization-code flow. Dana's Google password is typed only at Google. The bakery receives a one-time code in the browser and swaps it for a token in a private server-to-server call, so the token itself never passes through the browser.
Session 5 · 5.5 OAuth: how "Sign in with Google" works · 3/3Book ↗
Why the roundabout design
The password is typed only at Google; the app never sees it
Scopes limit what the access token can do; the user sees them on the consent screen
The one-time code is swapped for the token server-to-server, using the app's client secret
Tokens expire in about an hour; the user can revoke any app with one click
OpenID Connect adds an ID token for login; single sign-on lets employees use one company identity everywhere
Offer "Sign in with Google": higher conversion, no password liability. And always read the scopes.
Session 5 · 5.6 Security basics every product owner should knowBook ↗
Six ideas that catch most mistakes
Encrypt in transit (HTTPS) and at rest (encrypted disks)
Never trust the front end: prices, permissions, secrets live on the server
SQL injection: user text pasted into a query. Typing ' OR 1=1 -- logs in as everyone. Frameworks prevent it with parameterised queries
Least privilege: every person, program, and key gets the minimum access
Secrets out of code and out of Git; rotate anything exposed
Patch software and test that backups restore
"Have we reviewed against the OWASP Top Ten?" is a question any engineer or AI assistant can act on.
One back end, many clients. Whether the customer orders from a browser, a phone, a laptop, or the oven's own screen, the request reaches the same API and the same data. The architecture of Sessions 3 and 4 does not change.
Different front ends are different faces on the same product; the API and database do not change
An AI model is a third-party API called from your back end
AI in the architecture. The model is one more service the back end calls, after applying its own rules and adding its own data. Nothing about the tiers, hosting, or security changes.
The key and the model call stay on the server; the browser talks only to your back end