DEV Community

Cover image for The Difference Between Authentication and Authorization
Soumyajit Mukherjee
Soumyajit Mukherjee

Posted on

The Difference Between Authentication and Authorization

Authentication and authorization are often confused.

They answer two completely different questions.

Authentication

Authentication asks:

Who are you?

Examples include:

  • Passwords
  • Passkeys
  • OAuth
  • Multi-factor authentication
  • Biometrics When a user logs in, the system authenticates their identity.

Authorization

Authorization asks:

What are you allowed to do?

Suppose Alice is authenticated.

That doesn't mean Alice should be able to:

Delete every user
View financial reports
Modify system settings
Enter fullscreen mode Exit fullscreen mode

The application needs authorization rules.

Example

Imagine an API:

DELETE /users/123
Enter fullscreen mode Exit fullscreen mode

Authentication determines:

Is this request associated with Alice?
Enter fullscreen mode Exit fullscreen mode

Authorization determines:

Is Alice allowed to delete user 123?
Enter fullscreen mode Exit fullscreen mode

Role-Based Authorization

A simple system might define:

const roles = {
  USER: ["read"],
  ADMIN: ["read", "write", "delete"]
};
Enter fullscreen mode Exit fullscreen mode

Then middleware can enforce permissions.

Why This Matters

A common security mistake is:

User is logged in
        ↓
Allow everything
Enter fullscreen mode Exit fullscreen mode

Authentication isn't authorization.

Resource Ownership

Authorization can also depend on ownership.

For example:

GET /users/123/profile
Enter fullscreen mode Exit fullscreen mode

might be allowed only if:

request.user.id === 123
Enter fullscreen mode Exit fullscreen mode

or the user has an administrative permission.

Final Thoughts

Remember the distinction:

Authentication = Who are you?
Authorization  = What can you do?
Enter fullscreen mode Exit fullscreen mode

Keeping these concepts separate leads to much safer application designs.

Top comments (0)