Authentication vs Authorization: Essential Guide for Backend Engineers

Authentication vs Authorization: Complete Backend Engineer's Guide

Core Concepts

Authentication answers "Who are you?" - the process of verifying identity in a given context (platform, OS, or device). For a deeper dive into these foundational identity verification processes, see our guide on Understanding AAA Framework: Authentication, Authorization, and Accounting Explained.

Authorization answers "What can you do?" - determining permissions and capabilities within that context.

Historical Evolution of Authentication

Pre-Industrial Era

  • Implicit trust based authentication (village elders vouching)
  • Human contextual trust systems
  • Failed to scale beyond familiar circles

Medieval Period

  • Wax seals as first authentication tokens
  • "Something you have" principle
  • First recorded authentication bypass attacks (seal forgery)
  • Led to watermarks and encrypted codes

Industrial Revolution

  • Telegraph systems introduced pass phrases (shared secrets)
  • Shift from "something you have" to "something you know"
  • Static passwords emerged as primitive authentication

Digital Age Milestones

1961 - MIT's Project MAC

  • Compatible Time-Sharing System (CTSS)
  • First computer passwords for multi-user systems
  • Passwords stored in plaintext (critical vulnerability)
  • Password file printing incident sparked secure storage revolution

1970s - Cryptographic Revolution

  • Diffie-Hellman key exchange introduced asymmetric cryptography
  • Kerberos introduced ticket-based authentication
  • PKI (Public Key Infrastructure) became backbone of modern protocols

1990s - Internet Era

  • MFA (Multi-Factor Authentication) emerged:
    • Something you know (passwords/PINs)
    • Something you have (cards/OTP generators)
    • Something you are (biometrics)
  • Biometric authentication introduced pattern recognition and statistical models

21st Century - Modern Authentication

  • OAuth and OAuth 2.0
  • JWT (JSON Web Tokens)
  • Zero Trust Architecture
  • Passwordless authentication (WebAuthn)

Three Core Components

1. Sessions

How Sessions Work:

Phase 1 - Creation: Server creates unique session ID and stores it with user data in persistent storage (database or Redis)

Phase 2 - Distribution: Session ID sent to client as cookie

Phase 3 - Verification: All subsequent requests include cookie with session ID for server lookup

Evolution of Storage:

  • File-based sessions (early, scalability issues)
  • Database-backed sessions (faster lookups, persistent across restarts)
  • Distributed in-memory stores (Redis, Memcached)

2. JWT (JSON Web Tokens)

Structure: Three base64-encoded parts separated by dots:

  • Header: Metadata (signing algorithm)
  • Payload: User data (sub=user ID, iat=issued at, roles, etc.)
  • Signature: Cryptographic verification

Advantages:

  • ✅ Stateless (no server-side storage)
  • ✅ Scalable for distributed systems
  • ✅ Portable (URL-friendly, works across systems)

Disadvantages:

  • ❌ Token theft enables impersonation
  • ❌ No revocation until expiration
  • ❌ Secret key change invalidates all tokens

Hybrid Approach: Combine statelessness with blacklist mechanism for revocation, though this reintroduces storage lookups.

3. Cookies

  • Server-side mechanism to store information in client browser
  • Automatically sent with subsequent requests to same server
  • Enables automated authentication token management
  • HTTP-only cookies prevent JavaScript access (security best practice)

Major Authentication Types

Stateful Authentication

Workflow:

  1. Client sends credentials to server
  2. Server validates and creates session ID
  3. Session ID + user data stored in Redis/database
  4. Session ID returned as HTTP-only cookie
  5. All subsequent requests include cookie for server lookup

Pros:

  • Centralized session control
  • Real-time active session information
  • Easy revocation and logout
  • Suitable for most web applications

Cons:

  • Scalability challenges with distributed systems
  • Higher operational complexity
  • Latency in multi-region setups

Stateless Authentication

Workflow:

  1. Client sends credentials to server
  2. Server validates and creates signed JWT with user data
  3. JWT returned to client
  4. Subsequent requests include JWT in Authorization header
  5. Server verifies JWT signature using secret key

Pros:

  • Highly scalable
  • No session store dependency
  • Ideal for distributed architectures
  • Mobile-friendly

Cons:

  • Complex token revocation
  • Token theft vulnerability
  • Payload size considerations

Recommendation: Use stateful authentication for web apps, stateless for APIs and mobile apps, or hybrid approach combining both.

API Key Authentication

Use Case: Machine-to-machine communication

Workflow:

  1. User generates API key through platform UI
  2. Key stored securely (environment variables)
  3. Key sent with each API request
  4. Server validates key and permissions

Benefits:

  • Easy to generate and manage
  • Ideal for programmatic access
  • Permission and expiry based

Example: OpenAI provides API keys for programmatic GPT model access

OAuth 2.0 & OpenID Connect

Historical Context:

  • Problem: Sharing passwords between platforms for resource access
  • Solution: Token-based delegation without password sharing

Key Terminology:

  • Resource Owner: User who owns the data
  • Client: App requesting access (e.g., Facebook)
  • Resource Server: Server holding protected data (e.g., Google)
  • Authorization Server: Issues tokens after authentication

OAuth 2.0 Flows: | Flow | Use Case | |------|----------| | Authorization Code | Server-side apps | | Implicit (deprecated) | Browser-based apps | | Client Credentials | Machine-to-machine | | Device Code | Limited input devices (Smart TVs) |

OpenID Connect (OIDC):

  • Built on top of OAuth 2.0
  • Introduced ID Token (JWT with identity information)
  • Enables "Sign in with Google/Facebook/Discord"
  • Provides user identity (name, email, profile picture)

Authorization: Role-Based Access Control (RBAC)

Core Concept: Different users get different permissions based on assigned roles

RBAC Workflow:

  1. User registers and receives a role (user/admin/moderator)
  2. Token or session carries user identification
  3. Server deduces role from token or database lookup
  4. Middleware checks permissions against role
  5. Access granted or 403 Forbidden returned

Example:

  • User role: read notes, write notes
  • Admin role: all user permissions + access to deleted notes
  • Custom roles: granular permissions per resource

Security Best Practices

Error Messages

❌ Don't:

  • "User not found" (reveals valid usernames)
  • "Incorrect password" (confirms valid username)
  • "Account locked" (reveals account existence)

✅ Do: Use generic messages for all failure cases

  • "Authentication failed"
  • "Invalid credentials"

Timing Attack Prevention

Risk: Different response times reveal authentication failure stage

  • Invalid username: faster response (fails at step 1)
  • Invalid password: slower response (fails at step 3, password hashing)

Mitigations:

  1. Constant-time comparison functions for password hashes
  2. Simulated response delays to equalize timing

Decision Framework

| Authentication Type | Best For | |---------------------|----------| | Stateful | Web applications, user session management | | Stateless | APIs, distributed systems, mobile apps | | API Keys | Machine-to-machine, server-to-server | | OAuth 2.0/OIDC | Third-party integrations, social login |

Production Recommendation: Use established authentication providers (Auth0, Clerk) for medium to complex systems. Build custom implementation only for learning or when you're confident in security expertise. For detailed guidance on securing token-based APIs, refer to Securing Your APIs in Azure API Management with OAuth.

When building these authentication systems, a solid grasp of HTTP Protocol Fundamentals: Statelessness, Methods, CORS, Caching, and Status Codes for Backend Developers is essential. For a broader architectural understanding, explore Understanding Backend Architecture: How Requests Travel and Why Backends Matter. To solidify your core backend principles, review Master Backend Engineering: First Principles for Faster Onboarding in Any Language.

Keep this summary

Save it to LunaNotes and it becomes a real note in your library — editable, searchable, and ready to turn into flashcards or a diagram. Free to start.

Save to LunaNotes

Or summarise for another video.

This summary and transcript were automatically generated using AI with the Free YouTube Transcript Summary Tool by LunaNotes.

Related summaries

HTTP Protocol Fundamentals: Statelessness, Methods, CORS, Caching, and Status Codes for Backend Developers

HTTP Protocol Fundamentals: Statelessness, Methods, CORS, Caching, and Status Codes for Backend Developers

This comprehensive guide explains core HTTP concepts every backend developer needs to know, covering stateless architecture, request/response headers, methods, status codes, CORS flow, caching strategies, content negotiation, and large data transfer. You'll learn why HTTP is stateless, how browsers handle cross-origin requests with preflight checks, and practical ways to optimize performance using caching and compression.

Understanding AAA Framework: Authentication, Authorization, and Accounting Explained

Understanding AAA Framework: Authentication, Authorization, and Accounting Explained

This video explains the AAA framework—Authentication, Authorization, and Accounting—using practical examples like VPN login and device certificates. Learn how organizations verify user identity, control access, and maintain security logs efficiently at scale.

Understanding Backend Architecture: How Requests Travel and Why Backends Matter

Understanding Backend Architecture: How Requests Travel and Why Backends Matter

This comprehensive summary explains the fundamental concepts of backend servers, tracing the journey of a web request from a browser to a server deployed on AWS, including DNS resolution, firewall filtering, reverse proxy configuration, and node server processing. It also contrasts backend and frontend roles, highlighting security, performance, and architectural reasons why backend logic cannot be fully executed in frontend environments.

Understanding Cookies: How They Simplify and Secure Your Online Experience

Understanding Cookies: How They Simplify and Secure Your Online Experience

This guide demystifies cookies, explaining their essential role in personalizing your web interactions and ensuring convenience like saved shopping carts and remembered preferences. Learn the different types of cookies, their security implications, and practical steps to manage them to protect your privacy effectively.

Securing Your APIs in Azure API Management with OAuth

Securing Your APIs in Azure API Management with OAuth

Learn how to protect your APIs in Azure API Management using OAuth. Secure your APIs effectively with our detailed guide!

Found this summary useful?

Take it with you. One click puts it in your own LunaNotes library.

Save to LunaNotes

Start taking better notes today with LunaNotes