Last active
October 27, 2015 22:51
-
-
Save stegrams/8749ed052d7f546f7314 to your computer and use it in GitHub Desktop.
Basic Auth with log out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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:[email protected]/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