Securitychapter 4 of 4 · 4 lessons
Session vs Token Authentication
Stateful sessions stored server-side vs stateless tokens carried by the client.
Somebody's laptop is stolen. They call support, and support clicks log out everywhere.
In one design, that deletes a row and the thief is locked out on their very next click. In the other, the thief keeps full access for up to an hour and there is nothing anybody can do about it.
The difference is where the answer to who is this lives. On your server, referenced by an ID in a cookie, or inside the credential itself, signed and readable without asking anyone.
Everything else, the scaling, the mobile story, the cross-domain awkwardness, follows from that one choice, and so does how fast you can revoke.
Lessons
4 in this chapter- Server-Side SessionsA random ID in a cookie pointing at server state: one lookup per request buys total control.3 min
- Stateless TokensMove the truth into a signed token and the per-request lookup, and its dependencies, disappear.2 min
- The Hybrid RealityProduction systems converge on short stateless access tokens plus a small, revocable stateful core.2 min
- CSRF and Storage PitfallsCookies get attached automatically and localStorage is readable by script: pick your poison carefully.3 min