Authentication & authorization
Sessions vs JWTs, OAuth2/OIDC flows, MFA, and the difference between authN and authZ. Broken access control is the #1 web risk — start here.
The mental model
Walking into a secured office building involves two completely different checks that people blur into one word, "security." First, the front desk verifies *who you are* — you show ID, maybe scan a fingerprint. That is authentication (authN): proving identity. Second, your badge decides *which doors open for you* — the server room stays locked even though you are a verified employee. That is authorization (authZ): deciding what an authenticated identity may do. They are separate systems: the guard who confirmed your face is not the lock that guards the vault, and confusing the two is the root of the most common serious web vulnerability.
The distinction matters because they fail differently and are attacked differently. An authentication failure means an attacker becomes *you* (credential theft, session hijacking). An authorization failure means an already-authenticated attacker reaches data that is not theirs — the classic "I changed the id in the URL from 123 to 124 and saw someone else's invoice." That second bug, broken access control, is the number-one risk in the OWASP Top 10, and it exists precisely because developers check "are you logged in?" (authN) and forget to check "is this yours?" (authZ).
The third pillar people forget is session management — the bridge between the two. Authentication happens once (you log in); authorization happens on every request. Something must carry your proven identity across the many stateless HTTP requests in between. That something is a session (a server-side session ID in a cookie) or a token (a JWT the client holds). Get the session wrong — a predictable ID, a token that never expires, a cookie readable by JavaScript — and you have undone the authentication no matter how strong the login was.
Authentication, authorization, and session management exist because HTTP is stateless and the network is hostile: every request arrives naked, from an unknown party, and the server must decide who sent it and what they may do using only what the request carries. Everything below is machinery for answering those two questions safely, request after request.
- Deep dive
- Internal architecture
- Real-world use cases
- Best practices
- Common mistakes
- Performance
- Security
- Production troubleshooting
- Advantages & disadvantages
- Alternatives
- Interview expectations
- Interview questions
- Facts to remember
- Cheat sheet
- Quick revision