Created
January 5, 2016 14:43
-
-
Save lubomir/1201f42e140ec07cf60f to your computer and use it in GitHub Desktop.
XMLHttpRequest with Kerberos credentials
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> | |
<meta charset="utf-8"> | |
<title>Token example</title> | |
</head> | |
<body> | |
<div id="token">Loading token...</div> | |
<script> | |
document.addEventListener("DOMContentLoaded", function () { | |
var url = "https://example.com/rest_api/v1/auth/token/obtain/"; | |
var x = new XMLHttpRequest(); | |
x.open('GET', url, true); | |
x.withCredentials = true; | |
x.setRequestHeader('Accept', 'application/json'); | |
x.addEventListener("load", function () { | |
var data = JSON.parse(x.response); | |
document.getElementById("token").innerHTML = data.token; | |
}); | |
x.addEventListener("error", function () { | |
document.getElementById("token").innerHTML = "Error :/"; | |
}); | |
x.send(); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment