Authentication vs Authorization Explained
Short answer: authentication verifies who you are. Authorization decides what you are allowed to do. Authentication always comes first: a system must know who you are before it can decide what you may access.
A simple analogy
At an office building, showing your ID card at the front desk proves who you are: that is authentication. The card then opens only certain doors, such as your floor but not the server room: that is authorization.
What is authentication?
Authentication confirms an identity using one or more factors:
- Something you know: a password or PIN
- Something you have: a phone, hardware key or one-time code
- Something you are: a fingerprint or face scan
Using two or more factors is called multi-factor authentication (MFA) and greatly reduces the risk from stolen passwords.
What is authorization?
Authorization checks the permissions of an already-identified user. Common models:
| Model | How it decides | Example |
|---|---|---|
| Role-based (RBAC) | By role | "Admins can delete users; editors cannot" |
| Attribute-based (ABAC) | By attributes and context | "Managers may view records from their own department" |
| Ownership | By who owns the data | "You can edit only your own posts" |
| ACL | List of allowed users per resource | File permissions |
Authentication vs authorization
| Authentication | Authorization | |
|---|---|---|
| Question | Who are you? | What can you do? |
| Happens | First | After authentication |
| Based on | Credentials, factors | Roles, policies, permissions |
| Failure response | 401 Unauthorized | 403 Forbidden |
| Visible to the user | Yes (a login screen) | Often not (hidden menus, errors) |
The HTTP names are confusing: status 401 is named "Unauthorized" but really means "not authenticated", while 403 means you are authenticated but not permitted.
How they work together in a web app
- The user logs in with a password (authentication).
- The server issues a session cookie or a token such as a JWT that identifies the user.
- On every request, the server checks the token (still authentication) and then whether that user may perform the action (authorization).
// Express-style example
function requireRole(role) {
return (req, res, next) => {
if (!req.user) return res.status(401).send("Please log in"); // authentication
if (req.user.role !== role) return res.status(403).send("No access"); // authorization
next();
};
}
app.delete("/users/:id", requireRole("admin"), deleteUser);
Common technologies
- Authentication: passwords with hashing, MFA, passkeys, single sign-on, OAuth 2.0 / OpenID Connect for sign-in with another provider.
- Authorization: RBAC, policy engines, OAuth scopes, database row-level rules.
OAuth 2.0 is mainly an authorization framework (granting an app limited access), while OpenID Connect adds authentication on top. More options are covered in API authentication methods.
Common mistakes
- Checking permissions only in the front end. Hiding a button does not protect an endpoint. Always enforce rules on the server.
- Trusting the user ID in the request. If
/orders/123does not check ownership, any logged-in user can read another user's order (a broken access control flaw). - Storing passwords in plain text. Hash them with a slow algorithm such as bcrypt; try the bcrypt tool to see how hashes look.
- Giving everyone admin rights. Follow least privilege: grant only what is needed.
Weak access control is among the most common web flaws; see common web security vulnerabilities (OWASP).
FAQs
Can you have authorization without authentication?
Only in a trivial form, such as rules for anonymous visitors. Meaningful per-user permissions require knowing who the user is.
Is a login the same as authorization?
No. Logging in only proves identity. What you can do afterwards is controlled by authorization rules.
Is OAuth authentication or authorization?
OAuth 2.0 is for authorization (delegated access). "Sign in with Google" uses OpenID Connect, which builds authentication on top of OAuth.
What is the difference between 401 and 403?
401 means the request lacks valid credentials. 403 means the credentials are valid but the user is not allowed to do this.
