Last active
May 18, 2017 14:45
-
-
Save rollcat/23f6a523dbc4dd2027d4d467647cfea9 to your computer and use it in GitHub Desktop.
Basic auth logout hack
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
On your backend, create an endpoint (like /api/logout), | |
that will always respond "401 Unauthorized" (without the WWW-Authenticate header). | |
On your frontend, include a JS snippet, to create a logout button. |
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> | |
<script type="text/javascript"> | |
window.onload = function() { | |
var logout = document.getElementById("logout"); | |
logout.onclick = function() { | |
xhr = new XMLHttpRequest(); | |
xhr.addEventListener("load", location.reload); | |
xhr.open("GET", location.origin + "/api/logout"); | |
xhr.send(); | |
}; | |
logout.innerText = "logout"; | |
}; | |
</script> | |
{% endblock %} | |
</head> | |
<body> | |
<a id="logout"></a> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment