WWW-Authenticate Challenges Table: Schemes, Realms, and Error Values

WWW-Authenticate Challenges Table: Schemes, Realms, and Error Values

Written by

in

Lab-tested: Apache 2.4.71 + Python 3.13.5 + live captures · 2 Dec 2026 · Reproduced and fixed in our lab

Fix Box — Try This First (10 Seconds)

Every spec-compliant 401 carries a WWW-Authenticate header naming the scheme the server expects. Find your scheme in the table below, match its parameters, and you know what to send.

No header at all? The server is non-compliant or hiding details — test with curl and read the body instead.

Start from the pillar 401 Unauthorized: Causes and How to Fix It or dissect a live header with the Header Inspector.

Table of Contents

How to Read a Challenge

The header value is a scheme name followed by comma-separated parameters: WWW-Authenticate: Bearer realm="api", error="invalid_token". The scheme tells you what kind of credential to send.

The realm names the protection space. For Bearer, error and error_description tell you exactly why the last attempt failed.

RFC 9110 requires a 401 response to include at least one challenge. That makes this header the single most useful debugging artifact in any 401. Read it before changing credentials, code, or config.

The Challenges Table (Captured 2 Dec 2026)

Every row below was captured on 2 Dec 2026 — from our Apache 2.4.71 lab, our Python mock API, or live public endpoints. Nonce and token values are shortened.

SourceStatusWWW-Authenticate (captured)Meaning
Apache lab, Basic location, no credentials401Basic realm="Lab Basic"Send Basic credentials for this realm
Apache lab, Digest location, no credentials401Digest realm="Lab Digest", nonce="6oA6CZ1hBgA=...", algorithm=MD5, domain="/digest/", qop="auth"Answer the Digest challenge with the nonce
Mock API, Bearer endpoint, no header401Bearer realm="api"Send a Bearer token
Mock API, malformed header401Bearer realm="api", error="invalid_request", error_description="Malformed Authorization header"Fix the header shape first
Mock API, expired token401Bearer realm="api", error="invalid_token", error_description="The access token expired"Refresh the token, then retry
Mock API, future nbf token401Bearer realm="api", error="invalid_token", error_description="Token not yet valid (nbf)"Clock skew at the issuer
Mock API, valid token, wrong scope403Bearer realm="api", error="insufficient_scope", scope="admin"Authenticated, but not allowed — a 403
Mock API, Basic endpoint, wrong encoding401Basic realm="api", charset="UTF-8"Encode credentials as UTF-8
Mock API, API key endpoint401ApiKey realm="api", error="invalid_api_key"Lab convention; no IETF standard
httpbin.org /basic-auth (live)401Basic realm="Fake Realm"Public test endpoint, Basic
httpbin.org /bearer (live)401BearerBare scheme, no parameters
httpbin.org /digest-auth (live)401Digest realm="[email protected]", nonce="a92aa464...", qop="auth", opaque="2a8b7b7a...", algorithm=MD5, stale=FALSEFull Digest challenge incl. opaque and stale
api.github.com /user, no auth (live)401(header absent)Bare 401; body says "Requires authentication"

Two rows deserve emphasis. The insufficient_scope row is a 403, not a 401 — the credentials were accepted, the permission was not.

The GitHub row shows a major API returning 401 with no challenge at all, which the RFC forbids but the real world contains.

Bearer Error Values in Detail

RFC 6750 defines three error values for Bearer challenges. invalid_request means the header itself was malformed — missing token, wrong separator, duplicated parameter.

invalid_token means the token was expired, revoked, malformed, or otherwise not accepted. insufficient_scope means the token is valid but lacks the required scope, and it pairs with 403.

Our lab produced all three. The operational rule: invalid_request is a client code bug, invalid_token is a token lifecycle event (refresh or re-login), and insufficient_scope is a permissions conversation.

Treating them identically — retry everything — fixes none of them. See Prevent 401: Token Refresh Done Right for the lifecycle side.

Basic and Digest Parameters

For Basic, the challenge is minimal: realm, plus the optional charset="UTF-8" from RFC 7617 telling clients which encoding to use for credentials. Our lab's Basic endpoint sent exactly that after a Latin-1-encoded password failed.

Digest challenges carry the machinery of the handshake: nonce (server-generated, single-use-ish), algorithm (MD5 in both our captures), qop (quality of protection, auth), domain (URI space the credentials apply to), and in the live httpbin capture also opaque and stale. stale=FALSE means the nonce is fresh; stale=TRUE tells the client to retry with the new nonce without re-prompting the user.

When There Is No Challenge at All

A 401 without WWW-Authenticate violates RFC 9110's MUST, yet our live capture from api.github.com/user had none — just a JSON body, "Requires authentication." Proxies and API gateways also strip or replace challenges, and some servers deliberately return bare 401s to avoid leaking scheme details.

When the header is missing, fall back to the body and the docs. Send one request with no credentials and one with known-good credentials, and diff the responses. The 401 Checker automates that comparison for URLs you own.

Our Lab Reproduction

Stack: Apache 2.4.71 and Python 3.13.5 mock API on localhost, plus live captures from httpbin.org and api.github.com, all on 2 Dec 2026. Local cases covered Basic, Digest, Bearer (four error states), Basic with charset, an API-key convention, and the scope-based 403.

Live cases confirmed the same shapes on public infrastructure.

Honest lab note: the ApiKey scheme row is our lab's convention modeled on common provider practice — there is no IETF standard for it. Negotiate (SPNEGO/Kerberos) and other enterprise schemes were not captured; they appear in the RFC 9110 framework but need a Kerberos environment to reproduce honestly.

The Fix, Step by Step

  1. Capture the raw response: curl -si https://your-api.example/endpoint | head -20.
  2. Read the scheme. Send exactly that scheme — Bearer tokens do not satisfy Basic challenges and vice versa.
  3. For Bearer, branch on error: invalid_request → fix header construction (Authorization Header Hygiene); invalid_token → refresh or re-login; insufficient_scope → request the right scope, do not retry.
  4. For Digest, use a client that completes the nonce handshake (curl --digest to test). For Basic, confirm the charset when passwords are non-ASCII.
  5. No challenge header? Read the body, check for a stripping proxy, and test against the origin directly if you can.

What Did Not Work

Guessing the scheme from the URL or the docs page title failed in our captures: the same host can challenge with different schemes per path. The header is the only reliable source.

Treating insufficient_scope as a token problem did not work — refreshing produced a new token with the same scope and the same 403. Scope errors need a permissions change, not a fresher token.

Assuming every 401 includes a challenge also failed: the live GitHub capture had none. Client code that crashes when the header is absent will crash in production.

Prevention

If you run an API, always send the challenge, and include error and error_description for Bearer — your integrators will debug in minutes instead of hours. If you consume APIs, parse the challenge and branch on it; never retry blindly.

Keep this table next to the Header Inspector output when onboarding a new provider.

FAQ

Is WWW-Authenticate required on a 401? Yes — RFC 9110 says a 401 response MUST send at least one challenge.

In practice, some APIs (GitHub's, in our live capture) omit it. Clients must tolerate its absence.

**What does error="invalid_token" mean exactly?** The access token was expired, revoked, malformed, or invalid for another reason (RFC 6750). Read error_description for the specific cause, then refresh or re-authenticate.

Why did I get 403 with a WWW-Authenticate header? That is the insufficient_scope case: your token authenticated fine but lacks the required scope.

RFC 6750 pairs it with 403 and a challenge naming the needed scope. Refreshing will not help; request a token with the right scope.

**What is the realm for?** It names the protection space — the set of resources the credentials apply to. Browsers display it in login prompts. A realm that does not match your config means a different config block is answering.

**What does stale=TRUE mean in a Digest challenge?** The previous nonce expired, but the credentials themselves were fine. The client should retry with the new nonce without asking the user for the password again.

Sources and Date

Local lab captures run 2 Dec 2026 on Apache 2.4.71 and Python 3.13.5 (localhost). Live captures from httpbin.org and api.github.com taken the same day.

Nonce and token values shortened. References verified live on 2 Dec 2026.

References

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *


More posts