Skip to content
AI360Xpert

Authentication vs Authorization

Authentication vs Authorization architecture
Authentication vs Authorization architecture

Overview

Authentication (AuthN) and Authorization (AuthZ) are the foundational pillars of system security. They are distinct concepts that answer two different questions: "Who are you?" and "What are you allowed to do?"

🧠 Mental model: Authentication is checking a passenger's passport at airport security to verify their identity. Authorization is checking their boarding pass at the gate to ensure they are allowed to get on that specific flight.

Key Concepts

Authentication (AuthN)

Verifies the identity of a user, device, or service. It usually happens first. Mechanisms include:

  • Something you know: Passwords, PINs.
  • Something you have: Authenticator apps (TOTP), SMS codes, physical security keys (YubiKey).
  • Something you are: Biometrics (FaceID, fingerprint).

Authorization (AuthZ)

Determines whether an authenticated entity has permission to access a specific resource or perform a specific action. Mechanisms include:

  • Role-Based Access Control (RBAC): Permissions are tied to roles (e.g., "Admin", "Editor"), and users are assigned roles. Best for standard business apps.
  • Attribute-Based Access Control (ABAC): Permissions depend on attributes (e.g., "Can edit if document.owner == user.id AND time < 5pm"). More flexible but harder to compute.
  • Access Control Lists (ACL): A list attached directly to a resource explicitly stating who can access it.
Aspect Authentication (AuthN) Authorization (AuthZ)
Question Who are you? What can you do?
Timing Happens first Happens second
Failure Result 401 Unauthorized (Identity unknown) 403 Forbidden (Identity known, access denied)
Protocols OpenID Connect (OIDC), SAML OAuth 2.0

Trade-offs

Strong authentication (like MFA) adds friction to the user experience but vastly improves security against credential stuffing. Fine-grained authorization (ABAC) gives perfect control but adds significant computational overhead to every database query compared to simple RBAC. In distributed systems, centralizing AuthN at an API Gateway is easy, but AuthZ must often be pushed down to individual microservices because only the microservice knows the business logic required to make the access decision.

Interview Tips

  • Never confuse the two terms. If asked about security, explicitly state "First we authenticate the user, then we authorize the action."
  • Know the HTTP status codes: 401 means "I don't know who you are" (AuthN failed). 403 means "I know who you are, but you can't do this" (AuthZ failed).
  • In a microservices architecture, propose authenticating once at the API Gateway and passing identity (usually via JWT) to downstream services to perform their own authorization.

Summary

  • Authentication (AuthN) verifies identity ('Who are you?').
  • Authorization (AuthZ) verifies permissions ('What can you do?').
  • AuthN failure results in 401; AuthZ failure results in 403.
  • RBAC is the most common authorization model, assigning permissions to roles rather than users.
  • In distributed systems, AuthN is often centralized at the gateway, while AuthZ is decentralized to microservices.