WWW-Authenticate: Sent with 401 Unauthorized — tells the client what auth scheme is required. WWW-Authenticate is sent with a 401 Unauthorized response to tell the client how to authenticate. WWW-Authenticate: Bearer realm="api", error="invalid_token" says a bearer token is required and the one sent was invalid. Browsers react to Basic in this header by showing a login dialog, which is how simple password protection on staging sites works.
What should you keep in mind with WWW-Authenticate?
For APIs, including this header with a clear error code helps clients understand what went wrong: missing token, expired token or insufficient scope. That lets an app refresh its token automatically instead of logging the user out. Note that Basic authentication sends credentials in an easily decoded form, so only use it over HTTPS, and prefer proper login or token-based authentication for anything beyond a temporary barrier.
What does an example of WWW-Authenticate look like?
Master authentication and authorization patterns including JWT, OAuth2, session management, and RBAC to build secure, scalable access control systems. Use when implementing auth systems, securing APIs, or debugging security issues.
Use when reviewing or setting HTTP response headers for a web app or API - security headers (Content-Security-Policy, Strict-Transport-Security, X-Frame-Options, X-Content-Type-Options, Referrer-Policy, Permissions-Policy), CORS headers, caching headers (Cache-Control, ETag, Last-Modified, Vary) and cookies (Set-Cookie flags). Also use when a security scan reports missing headers.
OWASP Top 10 security audit and secure coding guidelines for Laravel + React/Inertia.js applications. Use when auditing for vulnerabilities ("run OWASP audit", "security review", "check my app security") or writing secure Laravel code involving auth, payments, file uploads, or API design. Triggers on security-related tasks, payment handling, authentication, or any request to audit a Laravel codeba