Overview
Curated: · Written: · Reviewed:
Authentication vs. Authorization
In one line
Authentication establishes who the subject is. Authorization decides whether that subject may perform this action on this resource right now, and it consumes the principal that authentication produced. Reach for the split on every request, enforced at the resource server.
Key definitions
- Principal: the identifier, assurance level and context that authentication outputs. Only verified session or token state may produce one.
- PEP (policy enforcement point): the resource-side code that extracts the credential and refuses to run the handler without an allow.
- PDP and PIP: the policy decision point evaluates (principal, action, resource, context). The policy information point supplies attributes such as owner and tenant.
- Audience (aud): the API a token is meant for. An ID token's audience is the client, not your API.
- Capability: a session ID or bearer token. Whoever holds it acts as the subject.
- IDOR: an authenticated caller reaches an object because the handler never compared its owner or tenant to the principal.
How it works
- Extract the credential and verify it. Derive the principal only from verified state, never from a client-supplied user ID.
- Load the resource and read its owner and tenant.
- Ask the PDP: (principal, action, resource, context).
- Allow runs the handler. Deny returns 403. No valid principal returns 401. A PDP timeout denies.
When to use and when not to
| Option | Reach for it when | Cost you accept |
|---|---|---|
| Server-side session | Revocation must be immediate, such as admin sessions | A store read on every request |
| Stateless JWT | Many services verify locally and some revocation lag is acceptable | Valid until exp unless you add a denylist or introspection |
| Reference token (introspection) | Immediate revocation across services | A round trip to the authorization server |
| RBAC | The permission set is small and stable | Role explosion |
| ABAC | Policy depends on context such as device or classification | Policy is harder to test and explain |
| ReBAC | Data is collaborative and graph-shaped | The policy engine sits on the critical path |
Traps interviewers probe
- Using an ID token as an API credential. The API must check aud and require an access token issued for it. Fix: validate aud, iss, exp and a pinned algorithm, and reject tokens whose audience is not this API.
- Treating MFA as authorization. MFA raises authentication assurance and leaves object checks untouched. Fix: compare the object's owner and tenant to the principal on every read and write.
- Relying on hidden UI. The route is still callable. Fix: enforce at the resource, deny by default, and test the direct call.
- Trusting a client-supplied ID or an unverified role claim. Fix: derive the subject from the verified token or session, and check the specific claim the decision needs.
- Assuming logout revokes a JWT. Logout clears client state only. Fix: keep exp short, revoke refresh tokens, or denylist by jti, and state the latency you accept.
Interview tips
Opening: Authentication establishes the subject. Authorization decides this action on this object, using the subject from that step.
Follow-ups to expect:
- Which comes first, and what does authorization consume? Authentication, then a principal from a verified session or token.
- How do you revoke a JWT? Short exp plus refresh revocation, a jti denylist, or introspection for reference tokens.
- How do you stop IDOR? Load the object, compare owner and tenant to the principal, deny by default, and test the denied cases.
- Why is an ID token not an access token? It proves an authentication event to the client. Its audience keeps it from authorizing API calls.
- How do you cache decisions? Key on subject, tenant, policy version, resource, action and context, with a TTL and version-based invalidation.
- Impersonation or delegation? Audit the actor and the effective subject as separate fields, and make the grant time-bounded and revocable.
30-second outline:
- Who: verify the credential and derive the principal from verified state.
- What: load the resource, check tenant and owner, ask policy, default deny.
- Where: enforce at the resource server and fail closed.
- Trade-off: server-side sessions revoke immediately, while JWTs verify cheaply but lag until exp.
Feedback on this overview
Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.