Authorization header


目录

The HTTP Authorization {{Glossary("request header")}} can be used to provide credentials that authenticate a user agent with a server, allowing access to protected resources.

The Authorization header is usually, but not always, sent after the user agent first attempts to request a protected resource without credentials. The server responds with a {{HTTPStatus("401", "401 Unauthorized")}} message that includes at least one {{HTTPHeader("WWW-Authenticate")}} header. This header indicates the authentication schemes that can be used to access the resource and any additional information needed by the client to use them. The user-agent should select the most secure authentication scheme that it supports from those offered, prompt the user for their credentials, and then re-request the resource with the encoded credentials in the Authorization header.

This header is stripped from cross-origin redirects.

[!NOTE] This header is part of the General HTTP authentication framework. It can be used with a number of authentication schemes.

Header type {{Glossary("Request header")}}
{{Glossary("Forbidden request header")}} No

Syntax

Authorization: <auth-scheme> <authorization-parameters>

// Basic authentication
Authorization: Basic <credentials>

// Digest authentication
Authorization: Digest username=<username>,
    realm="<realm>",
    uri="<url>",
    algorithm=<algorithm>,
    nonce="<nonce>",
    nc=<nc>,
    cnonce="<cnonce>",
    qop=<qop>,
    response="<response>",
    opaque="<opaque>"

Directives

Other than <auth-scheme>, the remaining directives are specific to each authentication scheme. Generally, you will need to check the relevant specifications for these (keys for a small subset of schemes are listed below).

Basic authentication

Digest authentication

Examples

Basic authentication

For Basic authentication, the credentials are constructed by first combining the username and the password with a colon (e.g., aladdin:opensesame), and then by encoding the resulting string in base64 (e.g., YWxhZGRpbjpvcGVuc2VzYW1l).

Authorization: Basic YWxhZGRpbjpvcGVuc2VzYW1l

[!WARNING] {{Glossary("Base64")}}-encoding can easily be reversed to obtain the original name and password, so Basic authentication offers no cryptographic security. {{Glossary("HTTPS")}} is always recommended when using authentication, but is even more so when using Basic authentication.

See also HTTP authentication for examples on how to configure Apache or Nginx servers to password protect your site with HTTP basic authentication.

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also


版本号 #2
由 壳壳虫 创建于 2026-10-31 03:27:53 UTC
由 壳壳虫 更新于 2026-10-31 03:27:53 UTC