Backend & Databases Comparisonbeginner

Authentication vs Authorization

Authentication checks who you are. Authorization checks what you may do. Learn both with office, web app and API examples.

7 min read

Our verdict in 30 seconds

Authentication proves who you are, such as by checking a password or passkey. Authorization decides what you may do, such as whether you can delete a post. Authentication usually comes first. In an HTTP API, missing or invalid credentials normally return 401, while a known user without permission normally gets 403.

On This Page

Authentication vs authorization: authentication asks "Who are you?" and authorization asks "What may you do?" If you log in to a college portal, the portal first checks your identity. Then it checks whether your account may see marks, change marks or add a new student.

The names look alike, but the checks are different. Passing the first one should never mean you can use every feature.

Verdict: authentication vs authorization at a glance

Point Authentication Authorization
Main question Who are you? What can you do?
Simple meaning Identity check Permission check
Usual order First After identity is known
Example input Password, passkey, OTP Role, owner, policy
Short name AuthN AuthZ
Common HTTP failure 401 403
Result A trusted identity Allow or deny an action

In one line: authentication opens the front door, and authorization decides which rooms you may enter.

Authentication vs authorization meaning with a simple example

Think of an office building.

At the gate, a guard checks your ID card. This is authentication. The guard wants to know whether you are the person named on the card.

You then try to enter the server room. The door checks whether your card has access. This is authorization. Your identity may be real, but the room can still be closed to you.

Here is an authentication vs authorization example on a college website:

Person Identity check Allowed actions
Visitor No login Read public notices
Student Student account Read own marks
Teacher Teacher account Add marks for own class
Administrator Admin account Manage users

Two students may both log in correctly. Student A still should not read Student B's marks. That rule is based on ownership, not only on being logged in.

Common mistake: A common mistake beginners make is to hide a button and assume the action is protected. A user can call the API without your button. Check permission on the server every time.

How authentication works

Authentication uses something to prove identity. There are three common kinds of proof, called factors:

  1. Something you know: a password or PIN.
  2. Something you have: a phone, security key or code app.
  3. Something you are: a fingerprint or face check.

Multi-factor authentication, or MFA, uses two or more different kinds. A password plus a second password is still one kind. A password plus a security key uses two.

A website should not save plain passwords. It should save a slow, salted hash made with a suitable tool. A hash is a one-way value. A salt is random data added so that the same password does not always give the same stored result.

After login, the app needs to remember you. Two common choices are:

  • Server session: The server keeps login data. The browser sends a session id in a cookie.
  • Access token: The client sends a token with each request. The API checks it.

Neither is always better. Cookies need protection against attacks such as CSRF, where another site tricks your browser into sending a request. Tokens must be stored with care. Keep all login traffic on HTTPS.

Passkeys are another choice. They use a pair of digital keys. The website stores the public key, and you keep the private key. There is no password to steal.

How authorization works

Authorization compares a user, an action and a resource. A resource is the thing being used, such as a file or order.

Common models are:

  • Role-based: An editor can update posts. This is called RBAC.
  • Attribute-based: A manager can read a report if the department matches. This is called ABAC.
  • Owner-based: A user can edit only their own profile.
  • Permission-based: A user has a permission such as order:read.

Real systems can mix these. For example, an editor may change posts, but only in their own department.

The safest starting rule is deny by default. If no rule clearly allows an action, reject it. Also use least privilege, which means giving only the access needed.

Here is the owner rule in JavaScript:

function canDelete(user, post) {
  if (!user) return 401;
  if (user.role === "admin" || user.id === post.ownerId) {
    return 204;
  }
  return 403;
}

const post = { id: 9, ownerId: 7 };
console.log(canDelete(null, post));
console.log(canDelete({ id: 8, role: "user" }, post));
console.log(canDelete({ id: 7, role: "user" }, post));

The output is:

401
403
204

The first request has no known user. The second user is known but does not own the post. The third user is the owner. This example returns codes to show the idea. A real route must also load the post from a trusted database and delete it.

Authentication vs authorization in API requests

A protected API usually follows this order:

  1. Receive a request over HTTPS.
  2. Find the session cookie or token.
  3. Check that it is valid and not expired.
  4. Load the user and needed permission data.
  5. Check if the user may do this action on this resource.
  6. Run the action and return a response.

Here is a request with a bearer token:

GET /orders/42 HTTP/1.1
Host: example.com
Authorization: Bearer <access-token>

The header name is Authorization, even though its token is also used to authenticate the caller. That old name causes a lot of confusion.

A bearer token can be used by whoever holds it. So keep it out of URLs, logs and public code. A short life and limited access reduce damage if it leaks.

An API key may identify an app or project. It does not always identify a person. Do not treat every key as proof of a human user.

Authentication vs authorization in REST API design

Take an order API. Reading your own order needs both checks.

Request No valid login Logged in, not owner Owner
GET /orders/42 401 403 or 404 200
DELETE /orders/42 401 403 or 404 Depends on your rules

401 Unauthorized has a confusing name. In HTTP, it means valid authentication is missing. The response must include a WWW-Authenticate header that tells the client how to authenticate. 403 Forbidden means the server understood the request but refuses it.

Some APIs return 404 for a private item, so a stranger cannot learn that it exists. Keep this choice consistent.

Do not trust an order id just because it came from a logged-in user. Suppose a user changes /orders/42 to /orders/43. The server must check that order 43 belongs to them. Failing to do this is called broken object level authorization.

If you are new to routes, read what is a REST API. The difference between read and submit methods is in get vs post.

OAuth, OpenID Connect and JWT: where they fit

These terms are related, but they do different jobs.

Term Simple job
OAuth 2.0 Lets an app get limited access to a resource
OpenID Connect Adds login and identity to OAuth 2.0
JWT A compact token format that carries claims
SSO Lets you use one login across related apps

OAuth can let a photo print app read selected photos without getting your photo account password. That is delegated authorization. OpenID Connect helps an app know which user logged in.

Anyone who has a normal signed JWT can read its content. The signature helps detect changes. It does not hide anything. Do not put a password inside it. The server must check the signature, the expiry, who issued it and who it is for.

Pro tip: When you see a "log in with" button, ask two questions. How does the app prove who I am? What access did I allow? The answers separate identity from permission.

Choose the right check: use both when needed

Choose authentication if the app needs to know who is using it.

Choose authorization if different users may see or change different things. A logged-in app nearly always needs both.

Use neither check if a page is truly public, such as a company home page. You still need other web security.

The authentication vs authorization difference is a difference in job. One cannot replace the other.

For freshers: how to explain it

Say: "Authentication checks identity. Authorization checks permission. Authentication normally happens first. In a REST API, missing or invalid credentials usually give 401. A known user without permission usually gets 403. I check ownership and roles on the server."

Interview note: If the interviewer mentions the Authorization header, explain that a bearer token in it lets the server authenticate the caller too. The server still makes a separate permission decision.

For Java practice, study Spring Security interview questions and building a Spring Boot REST API. Build a small notes app with two users. Let each user read and delete only their own notes. Then test it by changing a note id in the request. If the second user can see the note, your authentication works but your authorization does not.

Frequently Asked Questions

Which comes first, authentication or authorization?
Authentication usually comes first, because the system must know who is asking before it checks that user's permission. Public pages are an exception. They may allow a visitor without a login.
What is the difference between 401 and 403?
A 401 response means the request lacks valid authentication. A 403 response means the server understood the request but refuses it, commonly because the user has no permission. Some systems use 404 to avoid showing that a private item exists.
Is OAuth authentication or authorization?
OAuth 2.0 is mainly for delegated authorization. It lets an app get limited access without receiving your main password. OpenID Connect adds an identity layer for login on top of OAuth 2.0.
Is JWT authentication?
A JWT is a token format, not a full login system. A signed JWT may carry claims about a user. The server must check its signature, expiry and other needed rules before trusting it.
What is role-based access control?
Role-based access control gives permissions to roles, then assigns roles to users. For example, an editor can update posts and a viewer can only read them. It is often shortened to RBAC.

Want to Build Your Career in Java Full Stack with AI?

Join CodeBegun and train with working industry engineers — See the Java Full Stack course in Hyderabad

Apply for Demo Class →
Siva Prasad Galaba
Founder, CodeBegun · Staff Engineer

Founder of CodeBegun. 15+ years building Java systems at companies like Crunchyroll. Teaches Java, Spring Boot and system design the way the industry actually works, and mentors students through projects, mock interviews and placement preparation.

Technically reviewed by CodeBegun Technical TeamLast reviewed 3 December 2026 LinkedIn

More comparisons

View all
Chat with us