How does http://user:pass@host.com authentication work?

前端 未结 1 387
你的背包
你的背包 2021-01-13 03:53

Can anyone explain how http://user:pass@host.com authentication works? Does the browser send the Authorization header with user:pass being base-64

相关标签:
1条回答
  • 2021-01-13 04:40

    To inspect headers, you need to test against a server that requires authentication. The client will not send any Authorization header until the server asks for it since the client won't know what authentication method the server requires (basic or digest).


    HTTP authentication is done in two requests:

    First, a request without any Authorization header is sent. The server then responds with a WWW-Authenticate that tells the client how to authenticate. This includes a realm name and an authentication method (again, this is either basic or digest)

    The client then sends a new request with an additional Authorization header. In the case of basic authentication, this header is just user:pass base64 encoded, just as you are saying:

    Authorization: Basic dXNlcjpwYXNz
    

    Now the password is visible in transit, unless you are using https. A better option is digest authentication, where the contents of both WWW-Authenticate and Authorization are best explained by the wikipedia article. :)

    0 讨论(0)
提交回复
热议问题