Track 07 · Lesson 1 of 18Identity and login
- 01Authentication vs authorization
- 02Browser storage compared
- 03Sessions versus tokens
- 04Inside a JWT
- 05Access and refresh tokens
- 06Where to keep tokens
- 07Choosing a design
- 08The login lifecycle
- 09The token clock
- 10Dead or just unlucky? Refresh decisions
- 11Inside a secure session cookie
- 12Five tabs, one refresh
- 13“Log in with Google”: OAuth and PKCE
- 14Two-factor login
- 15Storing passwords
- 16Logging out properly
- 17Trade-offs and common mistakes
- 18Compare the designs
Authentication vs authorization
Lesson 1 of 18· 6 min
Two questions sit behind every login. Authentication asks “who are you?”. Authorization asks “what are you allowed to do?”. Many serious bugs are authorization bugs on users who logged in perfectly correctly.
Who may do what?
Switch callers, then turn checks off
Who is calling
What the API checks
GET /me200✓ Allowed, correctlyGET /brands/123/invoices200✓ Allowed, correctlyGET /brands/124/invoices200✕ Shouldn’t be allowedDELETE /users/7200✕ Shouldn’t be allowed
The button is gone from the page, which is nice. But curl -X DELETE https://api.example.com/users/7 skips the page and reaches the API directly. Only the role check above decides.
Authentication: who are you?#
Proving identity: a password, a Google account, a passkey, a one-time code. In practice, password login, social sign-in, two-factor and email verification should all end in one place in your code that issues the session or tokens. Several slightly different copies drift apart, and one of them always ends up missing a check.
Authorization: what may you do?#
Checked after identity is known, on every request, by the server. Two kinds come up constantly:
- Roles: is this person an admin? Hiding the admin page in the browser is only cosmetic. Anyone can call the API directly with
curl, skipping the page. - Ownership: does this object belong to them? An endpoint that takes
brandId=123and returns it without checking the caller owns brand 123 is an IDOR (insecure direct object reference). Changing 123 to 124 shows someone else’s data.
HTTP forgets you#
Every request a browser makes is independent. The server doesn’t remember that you logged in a second ago. So after login, it gives you something to show on every later request instead of your password: a session ID or a signed token. The rest of this track is about that “something”: what it is, where it lives, how it’s refreshed, and how it ends.
Check yourself