Dil*_*e-O 25 asp.net authentication cross-browser
我这里有一些内部的.net Web应用程序,要求用户"注销"它们.我知道这在Intranet应用程序上似乎没什么问题,但它仍然存在.
我们对Intranet应用程序使用Windows身份验证,因此我们使用基本身份验证绑定到Active Directory,并且凭据存储在浏览器缓存中,而不是使用.net表单身份验证时的cookie.
在IE6 +中,您可以通过执行以下操作来利用他们创建的特殊JavaScript函数:
document.execCommand("ClearAuthenticationCache", "false")
Run Code Online (Sandbox Code Playgroud)
但是,对于其他需要支持的浏览器(即目前的Firefox,但我力求支持多浏览器),我只是向用户显示他们需要关闭浏览器以退出应用程序的消息,有效地刷新应用程序缓存.
有人知道一些命令/黑客/等.我可以在其他浏览器中使用来刷新身份验证缓存?
Kei*_*ith 11
我提出了一个似乎相当一致的修复方案,但是它很黑,我仍然不满意.
虽然确实有效:-)
1)将它们重定向到Logoff页面
2)在该页面上激活一个脚本到ajax加载另一个带有伪凭证的页面(jQuery中的示例):
$j.ajax({
url: '<%:Url.Action("LogOff401", new { id = random })%>',
type: 'POST',
username: '<%:random%>',
password: '<%:random%>',
success: function () { alert('logged off'); }
});
Run Code Online (Sandbox Code Playgroud)
3)应该总是第一次返回401(强制传递新凭据),然后只接受伪凭证(MVC中的示例):
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult LogOff401(string id)
{
// if we've been passed HTTP authorisation
string httpAuth = this.Request.Headers["Authorization"];
if (!string.IsNullOrEmpty(httpAuth) &&
httpAuth.StartsWith("basic", StringComparison.OrdinalIgnoreCase))
{
// build the string we expect - don't allow regular users to pass
byte[] enc = Encoding.UTF8.GetBytes(id + ':' + id);
string expected = "basic " + Convert.ToBase64String(enc);
if (string.Equals(httpAuth, expected, StringComparison.OrdinalIgnoreCase))
{
return Content("You are logged out.");
}
}
// return a request for an HTTP basic auth token, this will cause XmlHttp to pass the new header
this.Response.StatusCode = 401;
this.Response.StatusDescription = "Unauthorized";
this.Response.AppendHeader("WWW-Authenticate", "basic realm=\"My Realm\"");
return Content("Force AJAX component to sent header");
}
Run Code Online (Sandbox Code Playgroud)
4)现在,浏览器接受并缓存随机字符串凭证.当他们访问另一个页面时,它会尝试使用它们,失败,然后提示输入正确的页面.
Mozilla实现了通过DOM window对象提供的加密对象,该对象具有logout在浏览器级别清除SSL会话状态的功能(Firefox 1.5向上),以便"任何令牌上的下一个私有操作将再次需要用户密码"(参见这个).
加密对象似乎是Web Crypto API的一个实现,根据这个文档,DOMCrypt API将添加更多的功能.
如上所述,Microsoft IE(6向上)具有:
document.execCommand("ClearAuthenticationCache", "false")
我发现没有办法在Chrome清除SLL缓存(见这个和这个错误报告).
如果浏览器没有提供任何API来执行此操作,我认为我们可以做的更好的是指示用户关闭浏览器.
这是我做的:
var agt=navigator.userAgent.toLowerCase();
if (agt.indexOf("msie") !== -1) {
document.execCommand("ClearAuthenticationCache","false");
}
//window.crypto is defined in Chrome, but it has no logout function
else if (window.crypto && typeof window.crypto.logout === "function"){
window.crypto.logout();
}
else{
window.location = "/page/to/instruct/the/user/to/close/the/browser";
}
Run Code Online (Sandbox Code Playgroud)
几个笔记.有些人说过你需要使用无效凭据启动ajax请求,以使浏览器删除自己的凭据.
这是事实,但正如Keith指出的那样,服务器页面声称接受这些凭据以使此方法始终如一地工作至关重要.
在一个类似的说明:你的页面只是通过401错误调出登录对话框是不够的.如果用户取消对话框,则其缓存凭据也不受影响.
此外,如果你可以请在https://bugzilla.mozilla.org/show_bug.cgi?id=287957上戳MOZILLA 为FireFox添加一个正确的修复程序.在https://bugs.webkit.org/show_bug.cgi?id=44823上记录了一个webkit错误.IE使用以下方法实现了一个很差但功能性很强的解
document.execCommand("ClearAuthenticationCache", "false");
Run Code Online (Sandbox Code Playgroud)
不幸的是,我们只需要注销用户就可以使用这些长度.
小智 0
好吧,我现在已经浏览了 Bugzilla 一段时间,似乎清除身份验证的最佳方法是发送不存在的凭据。
在这里阅读更多信息:https://bugzilla.mozilla.org/show_bug.cgi?id =287957
| 归档时间: |
|
| 查看次数: |
39292 次 |
| 最近记录: |