-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
82 lines (72 loc) · 2.66 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
81
82
<!DOCTYPE html>
<html>
<head>
<title>Territory planning</title>
<script type="text/javascript" src="https://auth.simplizio.com/js/keycloak.js"></script>
<script type="text/javascript">
function output(content) {
if (typeof content === 'object') {
content = JSON.stringify(content, null, 2)
}
document.getElementById('output').textContent = content;
}
function profile() {
if (kc.idTokenParsed.name) {
document.getElementById('name').textContent = 'Hello ' + kc.idTokenParsed.name;
} else {
document.getElementById('name').textContent = 'Hello ' + kc.idTokenParsed.preferred_username;
}
if (kc.idTokenParsed.picture) {
document.getElementById('picture').src = kc.idTokenParsed.picture;
}
document.getElementById('user').style.display = 'block';
}
function sendRequest() {
var req = new XMLHttpRequest();
req.onreadystatechange = function() {
if (req.readyState === 4) {
output(req.status + '\n\n' + req.responseText);
}
}
req.open('GET', 'https://app.simplizio.com/api/sauce', true);
req.setRequestHeader('Authorization', 'Bearer ' + kc.token);
req.send();
}
var kc = new Keycloak({ realm: 'landscapes', clientId: 'planner-console-api' });
window.onload = function() {
kc.init({'messageReceiveTimeout': 100000}).then(function() {
if(kc.authenticated) {
profile();
} else {
document.getElementById('anonymous').style.display = 'block';
}
});
}
</script>
</head>
<body>
<div id="anonymous" style="display: none">
<button onclick="window.kc.login()">Login</button>
</div>
<div>
<h1>here is some content which is always visible</h1>
</div>
<div id="user" style="display: none">
<div>
<h2>User console</h2>
</div>
<div>
<button onclick="window.kc.logout()">Logout</button>
<button onclick="output(kc.idTokenParsed)">Show ID Token</button>
<button onclick="output(kc.tokenParsed)">Show Access Token</button>
<button onclick="window.kc.updateToken(-1).then(function() { output(kc.idTokenParsed); profile() })">Refresh</button>
<button onclick="sendRequest()">Invoke Service</button>
<hr/>
<h2 id="name"></h2>
<img id="picture" width="50px" height="50px"/>
<hr/>
<pre id="output"></pre>
</div>
</div>
</body>
</html>