Skip to content

Instantly share code, notes, and snippets.

@stegrams
Last active October 27, 2015 22:51
Show Gist options
  • Save stegrams/8749ed052d7f546f7314 to your computer and use it in GitHub Desktop.
Save stegrams/8749ed052d7f546f7314 to your computer and use it in GitHub Desktop.
Basic Auth with log out
<!DOCTYPE html>
<html>
<head>
<title>Basic Auth Log Out</title>
</head>
<script type="text/javascript">
if(~document.URL.split('/')[2].search('@'))
// clean url from bad credentials (log:out@)
document.location = document.location.origin
+ document.location.pathname;
</script>
<body>
<div id="contents">
Congrats! You are in.
<button id="logout">Logout</button>
</div>
<script type="text/javascript">
document.getElementById('logout').onclick = function(e){
document.getElementById('contents')
.innerHTML = 'You are out.';
// Bad credentials (http://log:out@example.com/path) to
// provoke a 401 response that results an artificial log out.
document.location = document.URL.replace('//', '//log:out@');
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment