What it is
A backend receives requests, checks input and permissions, performs business work, and returns a response. HTTP does not automatically remember that a previous request logged someone in. Authentication establishes the caller’s identity; authorization decides whether that caller may perform this action on this resource.
Why you need it
A signed-in customer should be able to read their own invoice, but being signed in should not grant access to every invoice. Separating identity from permission keeps this distinction visible in the design.
How it works
- The browser requests GET /invoices/42.
- The server identifies the caller from a validated session or credential.
- It loads the invoice and checks the caller’s right to read it.
- It returns allowed data or a documented denial response.
A protected request pipeline
caller = authenticate(request)
if caller is missing: return 401
invoice = findInvoice(request.invoiceId)
if invoice is missing: return 404
if not canRead(caller, invoice): return 403
return 200 with invoiceEach function represents a server-side responsibility. Some APIs deliberately use 404 for inaccessible resources to avoid revealing existence. The browser never gets to declare its own trusted identity.
Download the file and run node backend-auth.mjs with Node.js 22 or newer. It tests an in-memory auth model; it is not a production login server.
Good practices and why
- Validate both identity and resource-specific permission on the server, including download and bulk endpoints.
- Return only needed fields and use consistent error semantics so clients can handle failures.
Common mistakes
- Treating a hidden button as an access-control check.
- Trusting a userId or organizationId supplied in the request body.
Try it yourself
Draw the request pipeline for viewing your own profile and editing someone else’s profile. Mark where identity is established and where permission is decided.
What a successful result looks like
Your diagram contains distinct authentication and authorization decisions, and the second operation is denied without an explicit permission.
0 / 6000 characters · Saved on this device. Do not include passwords or private data.
Check your understanding
Answer the understanding check correctly to record exercise completion.
Related interview practice
These scenarios add constraints and follow-up questions to the concepts you just learned.
Further reading
- OWASP: authentication ↗
- OWASP: password storage ↗
- OWASP: session management ↗
- MDN: Set-Cookie ↗
- IETF: JWT best current practices ↗
Selected primary references · reviewed 2026-10-09. Examples are educational; use your framework’s documented integration guidance when building a deployed system.