我读过https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication和HTTP中的基本身份验证章节:权威指南。
我认为Proxy-Authenticate + Proxy-Authorization + status code 407和WWW-Authenticate + Authorization + status code 401本质上是一样的。我认为如果服务器响应WWW-Authenticate + 401或Proxy-Authorization + 407,在这两种情况下,浏览器都会弹出一个auth对话框,然后浏览器会发送带有Authorization或Proxy-Authorization头的凭据。
“WWW-身份验证组合报头”确实按预期工作,而“代理组合报头”则没有工作。对于Proxy-Authorization + 407,我在Chrome中获得ERR_UNEXPECTED_PROXY_AUTH,在火狐中什么也没有发生(No auth对话框弹出!)。
Chrome错误:
This site can’t be reached.
The webpage at http://localhost:5000/http_auth might be temporarily down or it may have moved permanently to a new web address.
ERR_UNEXPECTED_PROXY_AUTH那么这两组相似的标题之间有什么区别呢?何时何地使用Proxy-Authenticate?我能做的实际经验会很感激的。
我正在使用Python与烧瓶一起进行测试。
我的服务器端代码:
WWW-认证
@app.route('/www_auth')
def ha():
print("====request headers begin======")
print(request.headers)
print("====request headers end======")
if 'Authorization' in request.headers and request.headers['Authorization'] == 'Basic MTIzOjQ1Ng==':
return render_template('demo.html')
else:
resp = make_response(render_template('demo.html'), 401)
resp.headers['WWW-Authenticate'] = 'Basic realm="WWW-Authenticate required :)"'
return resp代理认证
@app.route('/proxy_auth')
def haha():
print("====request headers begin======")
print(request.headers)
print("====request headers end======")
if 'Proxy-Authorization' in request.headers and request.headers['Proxy-Authorization'] == 'Basic MTIzOjQ1Ng==':
return render_template('demo.html')
else:
resp = make_response(render_template('demo.html'), 407)
resp.headers['Proxy-Authenticate'] = 'Basic realm="Proxy-Authenticate required :)"'
return resp发布于 2019-09-06 03:44:27
我做了一些测试,这是我发现的。(我看了一下RFC,和往常一样,它太压倒性了:)
Proxy-Authenticate标题集确实可以导致auth弹出对话框。但是,首先必须在客户机/浏览器中手动设置它。具体来说,例如在Firefox中,它与代理设置有关。

当您连接到需要用户名和密码的代理时,将使用Proxy-Authenticate头集。
注意:您需要设置代理函数的根路径,如下所示:
@app.route('/')
def haha():
#rest of the code工作流程是:
-----------------------------------Step 1---------------------------------------------------->
client/browser <---Step 2, 407,Proxy-Authorization response header, required username and password----------- proxy
----Step 3, Proxy-Authorization request headers, contains credentials------------------------> --------> target website
----Subsequent requests, Proxy-Authorization request headers with credentials is still sent--> ---------> target website在这种情况下,将为每个请求自动发送Proxy-Authorization(带有凭据)。
如果服务器不需要身份验证,那么客户端可以直接访问目标网站,并且请求中没有Proxy-Authorization头。(我认为,在Web上找到的大多数免费http代理都是这样工作的)
当我在火狐中设置WWW-Authenticate代理设置时,我也尝试了头集。结果是:每次我访问一个新的网站,我需要再次认证。因此,很明显,在这种情况下,不打算使用WWW-Authenticate头集。
任何其他深入的意见/解释将不胜感激。毕竟,我只是做了一些测试,我想知道更多。
https://stackoverflow.com/questions/57798725
复制相似问题