Pages

Monday, May 30, 2011

Clear Authentication Cache - Javascript

If we use http authentication, at the moment we want to logout a user for good, there's some issues we have to be aware of. So, we want to logout a user at client side and make sure that no one else has access to his/her account when using the same browser to access the same portal for instance. For IE, early versions, is pretty easy, we just do the code below:

// Clear current credentials
// Requires IE6 SP1 or later
document.execCommand(ClearAuthenticationCache)


Unfortunately, the ClearAuthenticationCache command is not available to others browsers in this case, so in order to do this really need to close the browser or, if it works for you, make an ajax call with wrong credentials to make your latest credentials saved to browser authentication cache be a 401 for that site. Mixing this all together we can have a javascript code like this one:




























References:
http://www.adopenstatic.com/cs/blogs/ken/archive/2005/04/12/14.aspx
http://stackoverflow.com/questions/31326/is-there-a-browser-equivalent-to-ies-clearauthenticationcache
http://stackoverflow.com/questions/1205045/how-to-clear-authentication-cache-on-ie7-with-javascript
http://www.nanodocumet.com/?p=6
http://msdn.microsoft.com/en-us/library/ms536979(v=vs.85).aspx
http://code.google.com/p/chromium/issues/detail?id=5497
http://trac-hacks.org/wiki/TrueHttpLogoutPatch

2 comments:

  1. Hi, just tested this. But got wierd problem. When I click log out button with that code it's logged out, but cannot access to that site again for a while. Do you know anything about this?

    ReplyDelete
  2. That's really weird... that never happened with me... every time you clear authentication cache you have to log in again...

    If you clear the browser cache it still happens in that time?

    which browser? if is FF take a look here: https://support.mozilla.org/en-US/kb/fix-login-issues-on-websites-require-passwords

    Do you have any kind of cookie that prevents logging in? clearing the cache this should not be a problem...

    Tell me how you manage this after please...

    ReplyDelete