This repository was archived by the owner on Sep 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
80 lines (68 loc) · 2.23 KB
/
Copy pathindex.html
File metadata and controls
80 lines (68 loc) · 2.23 KB
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>OAuth example</title>
<script src="node_modules/life-engine-js/dist/LifeEngine.js"></script>
<script src="config.js"></script>
<style>
#s {
white-space: pre-wrap;
}
</style>
</head>
<body>
<div id="s">Starting</div>
<script>
var statusContainer = document.getElementById("s");
var clientId = config.oauth.client_id;
var apiUrl = config.apiUrl;
var backendUrl = window.location.protocol + "//" + window.location.host;
var oauthStartUrl = backendUrl + "/connect/life_engine";
var urlData = getUrlData();
var LE = new LifeEngine({
"apiUrl": apiUrl,
"clientId": clientId
});
function setStatus(text) {
console.log(text);
statusContainer.innerHTML = text;
}
function getUrlData() {
var hash = String(window.location.hash);
if (hash.length > 0) {
var data = JSON.parse(decodeURIComponent(hash.substr(1)));
window.location.hash = "";
return data;
}
return {};
}
function getAccessToken() {
// Storage and refreshing best handled on the server in reality
var token = urlData.accessToken;
if (token === undefined) {
token = window.localStorage.getItem("access_token");
}
window.localStorage.setItem("access_token", token);
console.log("Token", token);
return token;
}
function run() {
var accessToken = getAccessToken();
if (accessToken === undefined) {
// Start OAuth Authorization Grant -flow
var link = '<a href="' + oauthStartUrl + '">' + oauthStartUrl + '</a>';
setStatus("No authorization. Please Log In at " + link);
return;
}
setStatus("Got authorization token. Fetching entities");
LE.setAuthToken(accessToken);
LE.entities.get({include: "keyValueData"}).then(function (result) {
var entities = result.data.data;
setStatus("Fetched entities: " + JSON.stringify(entities, null, 2));
});
}
run();
</script>
</body>
</html>