Skip to content

Commit 9efa4cb

Browse files
committed
Auth0 example
1 parent a678491 commit 9efa4cb

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

examples/clients/auth0/vanilla.html

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<html>
2+
<head>
3+
<meta charset="utf-8" />
4+
<script>
5+
var domain = ''; // hostname ending in '.auth0.com'
6+
var clientId = ''; // client id as defined in auth0
7+
var audience = ''; // api audience as defined in auth0
8+
window.onload = function () {
9+
var match = RegExp('[#&]access_token=([^&]*)').exec(window.location.hash);
10+
var accessToken = match && decodeURIComponent(match[1].replace(/\+/g, ' '));
11+
document.location.hash = '';
12+
if (accessToken) {
13+
url = '/api.php/records/posts?join=categories&join=tags&join=comments&filter=id,eq,1';
14+
var req = new XMLHttpRequest();
15+
req.onreadystatechange = function () {
16+
if (req.readyState==4) {
17+
console.log(req.responseText);
18+
jsonObject = JSON.parse(req.responseText);
19+
document.getElementById('output').innerHTML = JSON.stringify(jsonObject, undefined, 4);
20+
}
21+
}
22+
req.open("GET", url, true);
23+
req.setRequestHeader('X-Authorization', 'Bearer '+accessToken);
24+
req.send();
25+
} else {
26+
redirectUri = document.location.href;
27+
url = 'https://'+domain+'/authorize?audience='+audience+'&response_type=token&client_id='+clientId+'&redirect_uri='+redirectUri;
28+
document.location = url;
29+
}
30+
};
31+
</script>
32+
</head>
33+
<body>
34+
<pre id="output"></pre>
35+
</body>
36+
</html>

0 commit comments

Comments
 (0)