-
Notifications
You must be signed in to change notification settings - Fork 13
/
3_Use_IdentityToken.html
108 lines (93 loc) · 3.87 KB
/
3_Use_IdentityToken.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Login Example</title>
<script type="text/javascript" src="https://demo.microstrategy.com/MicroStrategyLibrary/javascript/embeddinglib.js"></script>
<!-- This is for playgound button. You don't need it in your application. -->
<script type="text/javascript" src="js/jsfiddle.js"></script>
</head>
<body>
<div>
<div>Server: <input type="text" id="baseURL" value="https://demo.microstrategy.com/MicroStrategyLibraryInsights" size="100"></div>
<div>ProjectID: <input type="text" id="projectId" value="EC70648611E7A2F962E90080EFD58751" size="100"></div>
<div>DossierID: <input type="text" id="dossierId" value="4C4BB57C11EB4EFF96550080EF952010" size="100"></div>
<div>Username: <input type="text" id="username" value="guest" /></div>
<div>Password: <input type="password" id="password" value="" /></div>
<div>
<span>Auth Mode:</span>
<select label="Auth Mode" id="loginMode">
<option value="1">Standard</option>
<option value="8">Guest</option>
<option value="16">LDAP</option>
</select>
</div>
<div><input type="submit" value="Show Dossier" onclick="showDossier()" /></div>
</div>
<div id="myDossier"></div>
<script type="text/javascript">
function login() {
var baseURL = document.getElementById("baseURL").value
var username = document.getElementById("username").value
var password = document.getElementById("password").value
var loginMode = parseInt(document.getElementById("loginMode").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
})
};
return fetch(baseURL + '/api/auth/login', options)
.then(function(response) {
if (response.ok) {
const authToken = response.headers.get('x-mstr-authToken');
var option = {
method: 'POST',
credentials: 'include', // Including cookie
mode: 'cors', // Setting as cors mode for cross origin
headers: {
'Content-Type': 'application/json',
'X-MSTR-AuthToken': authToken
}
}
return fetch(baseURL + '/api/auth/identityToken', option)
.then(function(response) {
if (response.ok) {
return response.headers.get('X-MSTR-IdentityToken')
}
})
} else {
response.json().then(function(json) {
console.log(json);
});
}
}).catch(function(error) {
console.log(error);
});
}
function showDossier() {
var baseURL = document.getElementById("baseURL").value
var projectId = document.getElementById("projectId").value
var dossierId = document.getElementById("dossierId").value
var placeHolderDiv = document.getElementById("myDossier");
var dossierUrl = baseURL + '/app/' + projectId + '/' + dossierId;
microstrategy.dossier.create({
placeholder: placeHolderDiv,
url: dossierUrl,
enableCustomAuthentication: true,
enableResponsive: true,
customAuthenticationType: microstrategy.dossier.CustomAuthenticationType.IDENTITY_TOKEN,
getLoginToken: login,
containerHeight: '1000px'
});
}
</script>
</body>
</html>