Skip to the page

Authentication and authorization · core

Authentication vs authorization, RBAC and ownership

Authentication proves who the caller is; authorization decides what that caller may do with a specific resource, and both must be checked on the server for every request.

The notes

What you must know

  • Authentication (authn): login with a password, OTP, passkey or SSO, then a session or token on later requests. Failure -> 401.
  • Authorization (authz): roles (RBAC: admin, support, user), attributes and ownership (ABAC: this order belongs to this user; this doctor is assigned to this patient). Failure -> 403 (or 404 to hide existence).
  • Broken Object Level Authorization (BOLA/IDOR) is the top API risk in the OWASP API Security Top 10 (2023): changing an id in the URL must not reveal another user's data.
  • Least privilege: give each user, service and API key only the permissions it needs; deny by default.
  • Put rules in one policy layer (can(user, action, resource)) and test it; do not scatter if (user.role === 'admin') across handlers.
  • After login: create a session or tokens, regenerate the session id, record the login, maybe notify on a new device.

The red pen

Common traps: mistake → fix

  • Mistake: Hiding UI elements is authorization

    Fix: the API must check every request.

  • Mistake: Authorization is checked once at login

    Fix: it is checked on every request, for the specific object.

  • Mistake: Roles alone are enough

    Fix: most real rules also need ownership or tenant checks.

Easy to hard

Questions interviewers ask, easy to hard

  1. Authentication vs authorization?
  2. What should happen right after a user logs in?
  3. RBAC vs ABAC: give an example of each.
  4. How do you prevent IDOR across hundreds of endpoints?

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview