Authorization
HTTP 請求中的 Authorization
是 user agent 用來向伺服器做身份認證(authentication)的憑證(credentials),
通常是在伺服器回應 401
(en-US)
Unauthorized
狀態及 WWW-Authenticate
(en-US) 標頭後才會在後續請求使用這個標頭。
Header type | Request header (en-US) |
---|---|
Forbidden header name (en-US) | no |
語法
http
Authorization: <type> <credentials>
指令
- <type>
-
認證方式 (en-US),通常是 "Basic" (en-US)。其他方式可以參考:
- IANA registry of Authentication schemes
- Authentification for AWS servers (
AWS4-HMAC-SHA256
)
- <credentials>
-
如果使用「Basic」方式,則憑證的格式會長的像這樣:
- 帳號、密碼會用冒號(:)串起來(
aladdin:opensesame
)。 - 然後在以 base64 (en-US) 編碼 (
YWxhZGRpbjpvcGVuc2VzYW1l
)。
備註: Base64 編碼不是加密也不是雜湊(Hash)!就算用明文直接傳,安全性也跟用 base64 編碼過一樣(base64 是可以解碼的)。最好用 HTTPS 搭配這種驗證方式。
- 帳號、密碼會用冒號(:)串起來(
範例
Authorization: Basic YWxhZGRpbjpvcGVuc2VzYW1l
可以看看 HTTP authentication (en-US) 中的範例 教你如何在 Apache 或 nginx 上啟用 HTTP basic authentication 來保護你的網站。
規範
Specification |
---|
HTTP Semantics # field.authorization |
瀏覽器相容性
BCD tables only load in the browser