Skip to content

Instantly share code, notes, and snippets.

@lubomir
Created January 5, 2016 14:43
Show Gist options
  • Save lubomir/1201f42e140ec07cf60f to your computer and use it in GitHub Desktop.
Save lubomir/1201f42e140ec07cf60f to your computer and use it in GitHub Desktop.
XMLHttpRequest with Kerberos credentials
<!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