Skip to content

L18 Authentication and authorization

21 minSuggested first: L17 Timeouts and retries

Outcome

Identify the evidence for identity and the evidence for permission at a resource boundary.

Learn

Authentication establishes who is making the request. Authorization decides whether that identity may perform this action on this resource. Hiding a button in the browser is a convenience, not enforcement.

When you read the code, follow the identity from a verified session to the server-side check on the resource.

Worked example

Three people ask for one document. Who gets which answer?

A toy document policyText
session invalid → 401
session valid and user is not owner → 403
session valid and user is owner → read document
Predict first, then show the worked explanation

A missing or invalid session gets 401; a valid user who doesn't own the document gets 403; a valid owner reaches the read. This assumes the document exists and the authentication protocol supplies whatever challenge a 401 needs. Some production systems deliberately answer 404 to hide that a resource exists.

Practice and check

Guided practice

Practice, not scored

A valid user asks for someone else's document. What is the outcome?

Choose one answer

Exit check

Counts toward completion

Which change would wrongly let a signed-in user who isn't the owner read the document?

Choose one answer

Common mistake

Treating a user id from the request body as a verified identity. Trace the trusted session, and check that the ownership rule applies to the resource being read.

Practice on a real repository

Try the puzzle below to look at protection at a different boundary, credential forwarding.

Related topics: Auth and security

Practice is optional. Solving a puzzle doesn't complete a lesson, and lessons never change a puzzle's points.

References