-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path2_Authentication.html
More file actions
180 lines (158 loc) · 6.29 KB
/
2_Authentication.html
File metadata and controls
180 lines (158 loc) · 6.29 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Hyper Web SDK Demo</title>
<script type="text/javascript" src="https://demo.microstrategy.com/hypersdk/js/mstr_hyper.bundle.js"></script>
<!-- This is for the jsfiddle button. You don't need it in your application. -->
<script type="text/javascript" src="js/jsfiddle.js"></script>
</head>
<body>
<br />
<p style="border: 2px; border-style: dotted; border-color: red">This example shows authentication workflow. HyperSDK
supports
different ways to authenticate user. </p>
<div>
<table>
<tr>
<td colspan="2">
<p style="border: 2px; border-style: dotted; border-color: red">
You can pass authentication mode and credentials to HyperSDK. You should provide interface for
user to enter credentials. DO NOT hard-code login and password in your web page. </p>
</td>
</tr>
<tr>
<td>
<div>Server:</span>
</td>
<td><input type="text" id="server" value="https://demo.microstrategy.com/MicroStrategyLibrary2"
size="100" /></td>
</tr>
<tr>
<td><span>Username:</span></td>
<td><input type="text" id="login" placeholder="guest" /></td>
</tr>
<tr>
<td><span>Password:</span></td>
<td><input type="password" id="password" /></td>
</tr>
<tr>
<td><span>Auth Mode:</span></td>
<td><select label="Auth Mode" id="authmode">
<option value="1">Standard</option>
<option value="8">Guest</option>
<option value="16">LDAP</option>
<option value="0x100000">SAML</option>
<option value="0x400000">OIDC</option>
</select></td>
</tr>
<tr>
<td><input type="submit" value="Login" onclick="login()" /></td>
<td><input type="submit" value="Logout" onclick="mstrHyper.logout()" /></td>
</tr>
<tr>
<td colspan="2">
<p style="border: 2px; border-style: dotted; border-color: red">
You can pass authentication token to HyperSDK. </p>
</td>
</tr>
<tr>
<td><input type="submit" value="GetToken" onclick="getToken()" /></td>
<td>AuthToken: <input type="text" id="token" /></td>
</tr>
<td colspan="2"><input type="submit" value="loginWithToken" onclick="loginWithToken()" /></td>
</tr>
</table>
</div>
<script>
login = function () {
const authmode = parseInt(document.getElementById("authmode").value)
let auth
if (authmode == 0x100000 || authmode == 0x400000) {
auth = {
authMode: authmode,
onSessionError: function (error) {
// Open a new window for user to login.
return mstrHyper.ssoLogin(mstrHyper.AUTH_MODES.OIDC);
}
}
} else {
const uid = document.getElementById("login").value
const password = document.getElementById("password").value
auth = {
authMode: authmode,
username: uid,
password: password,
}
}
mstrHyper.start({
server: document.getElementById("server").value,
auth
})
};
loginWithToken = function () {
token = document.getElementById("token").value
authMode = parseInt(document.getElementById("authmode").value)
mstrHyper.login({
authMode: authMode,// LDAP 0x10, GUEST 0x08, SAML 0x100000
authToken: token,
}).then(() => {
mstrHyper.enableCards();
});
}
getToken = function () {
server = document.getElementById("server").value
username = document.getElementById("login").value
password = document.getElementById("password").value
loginMode = parseInt(document.getElementById("authmode").value)
var options = {
method: 'POST',
credentials: 'include', // Including cookie
mode: 'cors', // Setting as cors mode for cross origin
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
loginMode,
username,
password
})
};
fetch(server + '/api/auth/login', options)
.then(response => {
if (response.ok) {
document.getElementById("token").value = response.headers.get('x-mstr-authToken');
} else {
response.json().then(function (json) {
console.log(json);
});
}
}).catch(function (error) {
console.log(error);
});
};
</script>
<p style="border: 2px; border-style: dotted; border-color: red">Add content you want to highlight in the text area
below. </p>
<div id="content">
<p>Apple</p>
<p>Strategy</p>
<p>Bitcoin</p>
<p>Sierra</p>
<p>Gladio</p>
<p>Jessica Liu</p>
</div>
<div>
<input id="textInput" onchange="addText()"></input>
<button type="submit" title="Add Content" onclick="addText()">Add Content</button>
</div>
<script>
addText = function () {
content = document.getElementById("content");
textInput = document.getElementById('textInput');
p = document.createElement("p");
p.innerText = textInput.value;
content.appendChild(p);
textInput.value = "";
};
</script>
</body>
</html>