Skip to main content
⚡ OpenDevDocs
Backend Concepts
backendbackend-conceptsCore ConceptBeginner

Authentication vs Authorization

Understand the differences between Authentication (AuthN) and Authorization (AuthZ), RBAC, ABAC, and access control patterns.

Verified: 2026-09-30
Tested on:node 22.x
Platforms:
webnode
#backend#auth#authentication#authorization#rbac#security

Overview

Though often used interchangeably, Authentication and Authorization represent two distinct security checkpoints in backend architectures.

Incoming Request
      │
      ▼
[ 1. Authentication (AuthN) ] ──(Invalid credentials)──> 401 Unauthorized
      │ (Valid User)
      ▼
[ 2. Authorization (AuthZ) ]  ──(Insufficient rights)──> 403 Forbidden
      │ (Permitted)
      ▼
[ Business Logic Handler ]

Direct Comparison

FeatureAuthentication (AuthN)Authorization (AuthZ)
Core Question"Who are you?""What are you allowed to do?"
Verification MethodPasswords, OTPs, Biometrics, SSORoles, Permissions, Policies, Ownership
Failure Status Code401 Unauthorized403 Forbidden
TimingFirst step of every requestEvaluated after identity is verified

Common Authorization Models

1. Role-Based Access Control (RBAC)

Permissions are assigned to roles, and users are assigned one or more roles (e.g. guest, member, admin).

function requireRole(role: string) {
  return (req, res, next) => {
    if (!req.user || req.user.role !== role) {
      return res.status(403).json({ error: 'Forbidden: Insufficient privileges' });
    }
    next();
  };
}

2. Attribute-Based Access Control (ABAC) & Resource Ownership

Access is evaluated dynamically based on attributes of the user, the resource, and the context (e.g. "A user can edit an article ONLY IF article.authorId === user.id OR user.role === 'admin'"):

function canEditArticle(user, article) {
  if (user.role === 'admin') return true;
  return article.authorId === user.id;
}

Best Practices

  • Never Trust Client Role Claims: Always evaluate permissions against verified server-side session data or a cryptographically signed token.
  • Fail Closed (Deny by Default): Explicitly require granted permissions rather than checking if access is forbidden.
  • Audit Logging: Log authorization failures (403) to detect privilege escalation attempts.

On this page