HTTP WWW-Authenticate Header

Der HTTP-Header WWW-Authenticate ist ein Response-Header, der bei 401 Unauthorized Responses gesendet wird. Er definiert Authentication-Schemes und Parameter, die der Client für erfolgreiche Authentifizierung verwenden muss.

Typ

Response-Header

Syntax

Der Header definiert Authentication-Scheme mit optionalen Parametern.

http
WWW-Authenticate: Basic realm="Admin Area"
WWW-Authenticate: Bearer realm="API", error="invalid_token"

Direktiven

Die Direktiven definieren Authentication-Schemes und deren Parameter.

Basic
HTTP Basic Authentication mit Base64-codiertem username:password.
Bearer
OAuth 2.0 Bearer Token Authentication für API-Zugriff.
Digest
Digest Access Authentication mit MD5-Hash für Password-Schutz.
realm
Beschreibender String für geschützten Bereich, wird in Browser Auth-Dialog angezeigt.
error
Optionaler OAuth 2.0 Error-Code bei Bearer-Scheme (z.B. invalid_token, insufficient_scope).
error_description
Optionale menschenlesbare Fehlerbeschreibung für OAuth 2.0 Errors.

Beispiele

Nachfolgend finden Sie praktische Anwendungsbeispiele für den WWW-Authenticate-Header.

Beispiel 1 Basic Authentication Challenge

http
GET /admin HTTP/1.1
Host: example.com

HTTP/1.1 401 Unauthorized
WWW-Authenticate: Basic realm="Admin Dashboard"
Content-Type: text/html

<html><body>401 Unauthorized</body></html>

Server fordert Basic Authentication, Browser zeigt Login-Dialog mit "Admin Dashboard" als Bereich.

Beispiel 2 Bearer Token Invalid

http
GET /api/users HTTP/1.1
Host: api.example.com
Authorization: Bearer expired_token_xyz

HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer realm="API", error="invalid_token", error_description="Token has expired"
Content-Type: application/json

{"error": "invalid_token", "message": "Token has expired"}

API lehnt abgelaufenen Bearer-Token ab mit detaillierten OAuth 2.0 Error-Informationen.

Beispiel 3 Multiple Authentication Options

http
GET /secure HTTP/1.1
Host: example.com

HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer realm="OAuth API"
WWW-Authenticate: Basic realm="Fallback Auth"
Content-Type: application/json

{"error": "authentication_required"}

Server bietet mehrere Authentication-Schemes an, Client kann bevorzugte Methode wählen.

Authentication Challenge Flow

WWW-Authenticate Authentication-Ablauf

Vorteile für die Systemarchitektur

  • Standardisierte Auth-Flows: Browser und HTTP-Clients erkennen Authentication-Requirements automatisch
  • Flexible Scheme-Auswahl: Server können multiple Authentication-Optionen anbieten
  • OAuth 2.0 Error-Details: Bearer-Scheme übermittelt präzise Error-Codes für Client-seitige Fehlerbehandlung

Spezifikation

RFC 9110, Section 11.6.1 – HTTP Semantics https://www.rfc-editor.org/rfc/rfc9110.html#name-www-authenticate RFC 7617 – HTTP Basic Authentication https://www.rfc-editor.org/rfc/rfc7617.html

Weitere Spezifikationen

Authorization Header, HTTP Status 401 - Unauthorized, Proxy-Authenticate Header