Dev tools
Authentication vs Authorization: The Difference Explained
Authentication vs authorization: who you are vs what you can do. Examples, 401 vs 403, OAuth and OIDC, API patterns, AAA, and the mistakes behind breaches.
Authentication vs authorization comes down to two questions. Authentication asks "who are you?" and verifies identity, for example with a password, a passkey or a fingerprint. Authorization asks "what are you allowed to do?" and decides which data and actions that verified identity can access. Authentication always comes first, and every request to a protected resource should go through both: prove the identity, then check the permission.
This guide explains each one with examples, shows how they work together in a real request, clears up 401 vs 403, maps OAuth, OpenID Connect, SAML and the other standards to the job they do, covers authentication and authorization for API design, and lists the mistakes behind most access-control breaches.
Authentication vs Authorization at a Glance
| Authentication (AuthN) | Authorization (AuthZ) | |
|---|---|---|
| Question it answers | Who are you? | What can you do? |
| Purpose | Verify identity | Grant or deny access to resources and actions |
| Happens | First | After authentication (or for anonymous users) |
| Based on | Credentials: something you know, have or are | Policies: roles, attributes, relationships, ownership |
| Typical methods | Passwords, MFA, passkeys, SSO, certificates | Roles and permissions, access control lists, policy engines, OAuth scopes |
| Visible to the user? | Yes, the login step | Mostly not, until access is denied |
| Who changes it | The user (new password, new passkey) | An administrator or the resource owner |
| Main standards | OpenID Connect, SAML 2.0, WebAuthn/FIDO2 | OAuth 2.0, XACML, policy languages such as Cedar and Rego |
| HTTP failure code | 401 Unauthorized | 403 Forbidden |
| Example | Logging in to your bank | Seeing only your own accounts, not other customers' |
What Is Authentication?
Authentication is the process of proving that a user, device or service is who or what it claims to be. The system compares something the requester presents with something it trusts.
Credentials fall into three classic factors:
- Something you know: a password, PIN or security question.
- Something you have: a phone with an authenticator app, a hardware security key, a smart card, a device-bound passkey.
- Something you are: a fingerprint or face, usually used to unlock a local key rather than sent to the server.
Multi-factor authentication (MFA) combines two or more different factors, so a stolen password alone isn't enough. Passkeys, built on the WebAuthn and FIDO2 standards, go further: the device holds a private key, the website stores only the public key, and the browser only lets a passkey be used on the site it was created for, which makes it resistant to phishing.
NIST's digital identity guidelines (SP 800-63-4, finalised in 2025) grade authentication strength in three authenticator assurance levels, from single-factor at AAL1 to phishing-resistant hardware-backed authentication at AAL3. You don't need to adopt NIST's scheme to use its idea: match the strength of login to the value of what's behind it.
Machines authenticate too. Services prove their identity with API keys, client secrets, signed tokens, or mutual TLS certificates, and the same rule applies: verify the identity before doing anything else.
What Is Authorization?
Authorization decides whether an authenticated identity may perform a specific action on a specific resource. It's a policy question: given this user, this resource, this action and this context, allow or deny?
The common models are:
- Access control lists (ACLs): each resource lists who can do what with it, like file permissions.
- Role-based access control (RBAC): permissions attach to roles such as admin, editor or viewer, and users get roles.
- Attribute-based access control (ABAC): rules evaluate attributes of the user, resource and context, such as department, data classification, time or location.
- Relationship-based access control (ReBAC): access follows relationships, such as "members of the team that owns this folder", the model behind Google's Zanzibar system.
Good authorization follows the principle of least privilege: every user and service gets only the access it needs, for as long as it needs it. And it's enforced on the server for every request, not just by hiding buttons in the interface.
OAuth 2.0 belongs here too. Despite how often it's described as a login system, OAuth is a framework for delegated authorization: it lets a user grant an application limited access (scopes) to their resources without sharing their password. Our OAuth vs JWT guide explains how OAuth, JWTs and OpenID Connect fit together.
Authentication vs Authorization Example
The classic authentication vs authorization example is a hotel. At the front desk you show ID and the clerk confirms your booking: that's authentication. The key card they hand you opens your room, the gym and the lift to your floor, but not other guests' rooms or the staff office: that's authorization. The card encodes what you may do; showing your passport again wouldn't get you into someone else's room.
In software, take a project-management app:
- Priya signs in with her email and a passkey. The app verifies the passkey and starts a session. Authentication succeeded: the app knows this is Priya.
- Priya opens Project Apollo. The app checks whether Priya is a member of that project. She is, so she can see it. Authorization succeeded for "view".
- Priya clicks "Delete project". The app checks whether her role on Project Apollo includes deletion. She's an editor, not an owner, so the server refuses. Authorization failed, even though authentication is still valid.
- Priya's session expires overnight. Her next request carries no valid session, so the app asks her to sign in again. Authentication failed, and no authorization check even runs.
AuthN vs AuthZ: How They Work Together
You'll often see the shorthand authn vs authz, which developers use in code, docs and logs. In practice the two run as a pipeline on every request:
- Identify: the request claims an identity (a session cookie, a bearer token, an API key).
- Authenticate: the server verifies the claim (checks the session, validates the token's signature and expiry, looks up the key).
- Authorize: the server evaluates the policy for this identity, action and resource.
- Act and log: if allowed, it performs the action and records who did what.
Here's that pipeline as a small Express-style example. verifyToken stands in for whatever validates your sessions or tokens:
function authenticate(req, res, next) {
const header = req.headers.authorization || "";
const user = verifyToken(header.replace("Bearer ", "")); // null if missing, expired or forged
if (!user) {
return res.status(401).set("WWW-Authenticate", "Bearer").end();
}
req.user = user;
next();
}
function authorize(permission) {
return (req, res, next) =>
req.user.permissions.includes(permission) ? next() : res.status(403).end();
}
app.delete("/projects/:id", authenticate, authorize("projects:delete"), deleteProject);Notice what's still missing: this checks that the user may delete projects in general, not that they may delete this project. Real authorization also checks the resource, usually by confirming ownership or membership inside deleteProject or in a policy engine. Skipping that check is the single most common access-control bug in APIs.
401 vs 403: The Status Codes Explained
HTTP has a well-known naming quirk. The code called "401 Unauthorized" is really about authentication, and "403 Forbidden" is about authorization. RFC 9110, the current HTTP semantics standard, defines them like this:
| Status | RFC 9110 meaning | When to return it | What the client should do |
|---|---|---|---|
| 401 Unauthorized | The request lacks valid authentication credentials for the target resource; the response must include a WWW-Authenticate header | No token, expired token, bad signature, wrong password | Sign in or refresh the token, then retry |
| 403 Forbidden | The server understood the request but refuses to fulfil it | Valid identity, but no permission for this action or resource | Don't retry with the same identity; request access |
| 404 Not Found | The resource doesn't exist, or the server won't reveal that it does | Hiding the existence of resources the user can't see | Nothing to retry |
Returning 404 instead of 403 for private resources is a legitimate choice when even confirming that a resource exists would leak information, such as private repositories or other customers' invoices.
Standards and Protocols: Which Job Each One Does
Much of the confusion between authentication and authorization comes from protocol names. Here's what each standard is actually for:
| Standard | Does authentication? | Does authorization? | What it's for |
|---|---|---|---|
| OAuth 2.0 (RFC 6749) | No | Yes, delegated | Lets apps get scoped access tokens to call APIs on a user's behalf |
| OpenID Connect | Yes | No (adds identity on top of OAuth) | Sign-in with an ID token describing who logged in |
| SAML 2.0 | Yes | Carries attributes used for authorization | Enterprise single sign-on with XML assertions |
| WebAuthn / FIDO2 | Yes | No | Passkeys and hardware security keys |
| JWT (RFC 7519) | Neither by itself | Neither by itself | A signed token format used by OIDC, OAuth and sessions |
| Kerberos | Yes | Carries group data used for authorization | Network authentication in Windows domains and enterprise networks |
| LDAP | Supports it (bind) | Stores groups and attributes | Directory of users and groups |
| RADIUS (RFC 2865), TACACS+ (RFC 8907) | Yes | Yes | Network device access with accounting (AAA) |
| XACML, Cedar, OPA/Rego | No | Yes | Policy languages and engines for fine-grained decisions |
Single sign-on (SSO) is an authentication pattern: you prove your identity once to an identity provider, and many applications trust that proof. Each application still makes its own authorization decisions.
Authentication and Authorization for API Design
Authentication and authorization for API work follows the same two steps, with a few patterns of its own.
Authenticating API callers:
- API keys identify the calling application. They're simple, but they're long-lived shared secrets with no user context, so treat them like passwords: hash them at rest, scope them and rotate them.
- OAuth 2.0 access tokens are the standard when an app calls an API for a user. For machine-to-machine calls, the client credentials grant gives a service its own token.
- Mutual TLS authenticates both sides with certificates, common inside service meshes and for high-security integrations.
Authorizing API calls:
- Check scopes on the token for coarse permissions (read:orders, write:orders).
- Check the object on every request: does this user own order 1234? The OWASP API Security Top 10 (2023) ranks broken object level authorization as API1, the top risk, ahead of broken authentication at API2.
- Check the function: regular users shouldn't reach admin endpoints just because they guessed the URL (broken function level authorization, API5).
- Check properties: don't let users set fields they shouldn't, such as
roleorprice, through mass assignment.
AI agents add a new twist. An agent calling tools on a user's behalf should get delegated, narrowly scoped and short-lived access, the same way an OAuth app does, rather than a powerful shared key. The Model Context Protocol, for example, uses OAuth for remote servers for this reason.
Authentication vs Authorization vs Accounting
Network engineers group the two with a third A. In authentication vs authorization vs accounting, often called the AAA framework:
- Authentication verifies who is connecting.
- Authorization decides what they can do: which network, which commands on a router, which VLAN.
- Accounting records what they did: session start and end, data used, commands run.
AAA is implemented by protocols such as RADIUS (common for Wi-Fi and VPN access) and TACACS+ (common for administering network devices, because it can authorize and log individual commands). Outside networking, accounting is usually called audit logging, and it matters just as much: when something goes wrong, the log is how you find out who had access and what they did with it.
Related Terms: Identification, Verification and Encryption
- Identification is claiming an identity, such as typing a username. Authentication is proving it.
- Verification is a general word; identity verification often means checking real-world documents during sign-up (know-your-customer checks), which is different from logging in.
- Validation checks that input is well formed. It's a security control, but it doesn't establish identity or permission.
- Encryption protects data from being read by the wrong party. It works alongside authentication (TLS does both for servers) but answers neither "who" nor "what may they do".
Common Mistakes That Cause Breaches
Broken access control is the number one category in the OWASP Top 10 for 2025, as it was in 2021, and authentication failures rank seventh. The usual causes:
- Authorization only in the UI. Hiding the delete button doesn't stop someone from calling the delete endpoint.
- Insecure direct object references. Changing
/invoices/1234to/invoices/1235returns someone else's invoice because the server never checked ownership. - Trusting client-side claims. A role stored in local storage or an unsigned cookie can be edited by the user.
- Using OAuth access tokens as proof of login. An access token says an app may call an API; it isn't an identity assertion. Use OpenID Connect's ID token for sign-in.
- Mixing up 401 and 403, which confuses clients into retrying logins that will never work, or never re-authenticating when they should.
- Long-lived, broad credentials, such as API keys that never expire and can do everything.
- Missing checks in generated code. AI assistants often produce endpoints that authenticate but skip the per-object authorization step; our guide to AI-generated code security covers that pattern.
Should You Build Auth Yourself?
For authentication, usually not. Identity providers and well-maintained libraries handle password storage, MFA, passkeys, SSO, account recovery and breach protection, and mistakes here are costly. Authorization is different: it's tied to your data model and business rules, so you'll write at least part of it yourself, often with help from a policy engine. A sensible split is to buy or adopt a standard for authentication, keep authorization logic close to your domain, and log both.
FAQ
Which comes first, authentication or authorization?
Authentication. The system has to know who is asking before it can decide what they're allowed to do. Even anonymous access is an authorization decision about the "unauthenticated" identity.
Is OAuth authentication or authorization?
OAuth 2.0 is an authorization framework: it issues access tokens that let an app call APIs with limited scopes. OpenID Connect adds authentication on top of OAuth, which is what "Sign in with Google" uses.
Is MFA authentication or authorization?
Authentication. MFA strengthens the proof of identity by requiring more than one type of factor. It doesn't change what the user is allowed to do.
Is SSO authentication or authorization?
SSO is authentication: one login with an identity provider that many apps trust. Each app still decides what the user can do, often using groups or roles the identity provider passes along.
Can you have authorization without authentication?
Yes, in a limited way. Public pages are authorized for anonymous users, and signed URLs or share links grant access to whoever holds the link. Anything sensitive should require authentication first.