Authentication vs. Authorization, 5 Common Confusions, HTTP Basic, Digest Challenge-Response, & API Keys
1 What is Authentication? (AuthN vs. AuthZ)
📥 Login Request (Credentials / Token)
2 Where Software Engineers Get Confused (5 Pitfalls)
System design interviews frequently expose critical misunderstandings around authentication mechanisms. Here are the 5 foundational confusions disambiguated:
Confusion: Conflating identity verification with permissions.
Reality: Authentication proves identity (“Who are you?”). Authorization evaluates scopes & privileges (RBAC, ABAC, ACLs).
Confusion: Saying “We use JWT authentication”.
Reality: JWT is an open standard token format/carrier (RFC 7519), not an authentication mechanism itself. It simply carries claims.
Confusion: Treating Bearer tokens and JWTs as synonymous.
Reality: Bearer is the HTTP Authorization transport scheme. A JWT is one specific structured payload carried inside the header.
Confusion: Claiming OAuth 2 is a login system.
Reality: OAuth 2 is a delegated authorization protocol. OpenID Connect (OIDC) is the identity layer on top that provides true authentication.
Confusion: Viewing Single Sign-On as an isolated protocol.
Reality: Single Sign-On (SSO) is an identity management architectural pattern orchestrated via protocols like SAML 2.0 or OIDC.
The earliest and simplest HTTP authentication scheme. The client transmits credentials inside the Authorization header using reversible Base64 encoding.
📱 Client / Browser
HTTP Request / Response Cycle
🖥️ Web Server / Proxy
GET /api/v1/protected/users HTTP/1.1(No credentials provided)HTTP/1.1 401 UnauthorizedWWW-Authenticate: Basic realm=“Internal Admin Area”🔐 ③ Browser Modal: Native prompt asks user for username & password ➔ Encodes to Base64
GET /api/v1/protected/users HTTP/1.1Authorization: Basic YWRtaW46c2VjcmV0MTIz(base64(“admin:secret123”))HTTP/1.1 200 OKatob(“YWRtaW46c2VjcmV0MTIz”) in 1 millisecond.4 2. HTTP Digest Authentication Flow (RFC 7616)
Digest Authentication was engineered to avoid transmitting plaintext passwords across the network through a Challenge-Response Nonce Hashing Scheme:
📱 Client App
Cryptographic Nonce Exchange
🖥️ Origin Server
GET /api/v1/accounts HTTP/1.1HTTP/1.1 401 UnauthorizedWWW-Authenticate: Digest realm=“users@site.com”, nonce=“dcd98b7102dd2f0e8b11d0f600bfb0c093”, qop=“auth”HA1 = MD5(username:realm:password)HA2 = MD5(method:digestURI)response = MD5(HA1:nonce:nc:cnonce:qop:HA2)GET /api/v1/accounts HTTP/1.1Authorization: Digest username=“Mufasa”, realm=“users@site.com”, nonce=“dcd98b7102dd2f0e8b11d0f600bfb0c093”, uri=“/api/v1/accounts”, response=“6629fae49393a05397450978507c4ef1”
HTTP/1.1 200 OKZero Plaintext Password Exposure: Passwords stay on the client. Server nonces provide robust protection against basic replay attacks.
MD5 Weaknesses: Vulnerable to collision attacks and MITM downgrade attacks. Superseded everywhere by HTTPS + JWT / Bearer tokens.
5 3. API Key Authentication Architecture
The standard pattern for Machine-to-Machine (M2M) communication, developer portals, external billing gateways, and third-party SaaS integrations:
① Client transmits request with API Key header:
Authorization: Bearer sk_live_51Msz92kx8921a…(or X-API-Key: sk_live_…)② Gateway hashes incoming key & looks up in fast cache:
SHA256(raw_key) is matched against Redis / Key-Value DB to retrieve Tenant ID, allowed scopes, & rate limiter tier.
③ Rate Limiting & Scope Verification:
Gateway checks token bucket (e.g. 100 req/min for Tier 1) and validates if key has permission for the requested route (e.g. write:orders).
④ Downstream proxy & 200 OK Response:
Request routed to microservice with injected X-Tenant-Id; JSON payload returned to client.
If an API key is leaked (e.g. committed to public GitHub), anyone possessing the key can execute authorized operations until the developer manually revokes it in the dashboard.
Unlike JWTs with standard exp timestamp claims, raw API keys are opaque strings without self-verifying expiration. Expiration and rotation schedules must be managed server-side.
API Keys are opaque random identifiers requiring a server-side database/Redis lookup to identify the caller and verify permissions.
In contrast, JWTs are cryptographically signed payloads carrying serialized claims (user ID, expiration, roles) that any downstream service can verify statelessly without querying a central database.
6 Protocol Comparison: Basic vs. Digest vs. API Keys
| Authentication Scheme | Credential Format | Replay Protection | State Management | Primary Modern Use Case |
|---|---|---|---|---|
| HTTP Basic | Base64 encoded user:pass | ❌ None | Stateless header; browser stores credentials in memory | Internal developer proxies, legacy appliances |
| HTTP Digest | MD5 hash with server nonce | ✅ Nonce-based | Server must maintain nonce state / timestamp | Legacy embedded devices (mostly deprecated) |
| API Keys | Opaque high-entropy secret (e.g. sk_live_…) | ⚠️ Requires HTTPS + optional HMAC signature | Stateful (requires DB/Redis lookup for identity & scopes) | Machine-to-Machine APIs, SaaS billing, rate limiting |