Tech News, Tech & Coding · Free Online Tools

IT Question Answer
Tools
Back to Security
Authentication vs Authorization Explained

Authentication vs Authorization Explained

SecurityBy Muhammad Fareed
securityauthenticationauthorization

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:

ModelHow it decidesExample
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"
OwnershipBy who owns the data"You can edit only your own posts"
ACLList of allowed users per resourceFile permissions

Authentication vs authorization

AuthenticationAuthorization
QuestionWho are you?What can you do?
HappensFirstAfter authentication
Based onCredentials, factorsRoles, policies, permissions
Failure response401 Unauthorized403 Forbidden
Visible to the userYes (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

  1. The user logs in with a password (authentication).
  2. The server issues a session cookie or a token such as a JWT that identifies the user.
  3. 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/123 does 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.