-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.html
80 lines (65 loc) · 2.23 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Single Page Application</title>
</head>
<body>
<!-- Edit this URL to reflect your domain, Auth0 Client ID, and the port you're using -->
<a href="https://YOUR_AUTH0_DOMAIN/authorize?scope=read:contacts%20read:calendar&audience=organize&response_type=id_token%20token&client_id=YOUR_CLIENT_ID&redirect_uri=http://localhost:3000&nonce=NONCE">
Sign In
</a>
<div id="app" style="display:none;">
<button id="get-contacts">List Contacts</button>
<button id="get-appointments">List Appointments</button>
<div id="results"><pre></pre></div>
</div>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script>
function getParameterByName(name) {
var match = RegExp('[#&]' + name + '=([^&]*)').exec(window.location.hash);
return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
}
function getAccessToken() {
return getParameterByName('access_token');
}
function getIdToken() {
return getParameterByName('id_token');
}
$(function () {
var access_token = getAccessToken();
if (access_token) {
$('#app').show();
} else {
return
}
console.log('Your access token is ' + access_token)
// Use the access token to make API calls
$('#get-contacts').on('click', function(e) {
e.preventDefault();
// Change to the port you're using
$.ajax({
url: "http://localhost:3001/api/contacts",
method: "GET",
headers: { "Authorization": "Bearer " + access_token },
success: function (data) {
$('#results pre').text(JSON.stringify(data, null, 2))
}
});
});
$('#get-appointments').on('click', function(e) {
e.preventDefault();
// Change to the port you're using
$.ajax({
url: "http://localhost:3002/api/appointments",
method: "GET",
headers: { "Authorization": "Bearer " + access_token },
success: function (data) {
$('#results pre').text(JSON.stringify(data, null, 2))
}
});
});
});
</script>
</body>
</html>