AJAX - 拦截 401 响应以进行自定义身份验证
我需要一个跨平台解决方案来正确执行摘要访问身份验证,并且最好对 POST 请求使用“qop=auth-int”。看来只有 Opera 会响应 qop=auth-int,而 IE 6 则无法使用任何 Digest。
所以我心里想:我知道,我只需做一个 AJAX 请求并使用 setRequestHeader() 自己实现身份验证。我已经实现了执行 RFC-2617 所需的服务器端内容,因此我这里唯一的主要障碍是弄清楚如何通过 javascript 获得足够的控制来解析 401 WWW-Authenticate 标头并形成适当的响应。
问题是这样的:浏览器似乎处理了 401,而不是允许它传递给 XMLHttpRequest.onreadystatechange。如果已经为网站 Chrome 存储了用户/通行证; Firefox 只会默默地处理 Authentication header 上的问题。如果没有,他们将弹出正常的登录框。
在您警告我 Digest Auth 和 Digest Auth 的不足之处之前,请先阅读以下内容:告诉我我需要使用 TLS——我意识到安全风险。服务器是一个资源非常有限的嵌入式平台,SSL 并不是真正的选择。服务器不会出现在公共互联网上。因此,身份验证更多的是阻止好奇的未经授权的人进行更改(认为管理者有良好的意图但知识不足),而不是知道如何进行 MitM 的恶意攻击者。
I'm in need of a cross-platform solution for doing Digest Access Authentication correctly, and preferably using "qop=auth-int" for POST requests. It appears that only Opera will respond with qop=auth-int, and I.E. 6 has trouble w/ anything Digest.
So I thought to myself: I know, I'll just do an AJAX request and implement the authentication myself using setRequestHeader(). I've already implemented the server-side stuff necessary to do RFC-2617, so my only major hurdle here is figuring out how to gain sufficient control through javascript to get parse the 401 WWW-Authenticate header and form the appropriate response.
Here's the problem: It looks like the browser handles the 401 instead of allowing it to be passed along to XMLHttpRequest.onreadystatechange. If a user/pass is already stored for the site Chrome & Firefox will just silently handle tack on the Authentication header. If not, they will pop the normal login box.
Before you warn me of the inadequacies of Digest Auth & tell me I need to be using TLS--I realize the security risks. The server is a very resource-limited embedded platform, where SSL is not really an option. The server is not indented to appear on public internet. So the authentication is more to dissuade curious unauthorized people from making changes (think manager with good intentions but inadequate knowledge) rather than malicious attacker w/ the know how to do a MitM.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论