發文作者:dieabsorb | 八月 8, 2011

HTTP Basic Authentication Logout 的方法

因為某些需求, 用了 HTTP Basic Auth 作為認證的方法 (偷懶..)
但在需要 Logout 的時候遇到了點小問題..

document.execCommand(‘ClearAuthenticationCache’) 只能在 IE 系列使用, google 找了一下, 最後這樣解決
(有用 jQuery)

if ( $.browser.msie ) {
  document.execCommand('ClearAuthenticationCache')
} else {
  $.ajax({
    url: "logout",
    username: "logout",
    password: "logout",
    error: function() {
      window.location = 'http://o.x.logout.page';
    }
  });
}

其實就是丟一個 ajax request 出去假裝換了帳號密碼, 收到 401 之後導到其他頁面,
測了 IE, Firefox, Chrome, 看來沒什麼問題 :p


發表迴響

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 變更 )

Twitter picture

You are commenting using your Twitter account. Log Out / 變更 )

Facebook照片

You are commenting using your Facebook account. Log Out / 變更 )

連結到 %s

分類

Follow

Get every new post delivered to your Inbox.