-
Notifications
You must be signed in to change notification settings - Fork 2
/
trusted_auth_tester.html
514 lines (453 loc) · 18.1 KB
/
trusted_auth_tester.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
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
<!DOCTYPE html>
<!--
Single page demo app with configurable sidebar using menuItems JSON object
-->
<html lang='en'>
<head>
<meta charset='UTF-8'/>
<title>ThoughtSpot Trusted Authentication Tester</title>
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Material+Icons&family=Monoton&family=Bungee+Outline&family=Roboto:wght@400;500;700&family=Faster+One&family=Plaster&display=swap" rel="stylesheet">
<style>
/* Simple styling of basic page */
body {
background-color: rgb(255, 255, 255);
font-family: sans-serif;
}
div {
/* border: 1px dashed black; */
/* margin: 4px; */
padding: 10px;
margin: 0px;
}
#embed {
height: 800px;
min-width: 600px;
}
#embed-2 {
height: 800px;
min-width: 600px;
}
#header {
background-color: black;
color: white;
}
#sidebar {
/* border-right: solid 1px black; */
flex: 0 0 400px;
}
#main-content-div {
background-color: rgb(238, 241, 244);
}
#no-data {
display: none;
}
ul {
margin-left: 5px;
padding-left: 0px;
}
li {
list-style-type: none;
padding-top: 10px;
padding-bottom: 10px;
margin-bottom: 3px;
font-size: 18px;
font-weight: 500;
font-family: 'Roboto', sans-serif;
color: #444444;
line-height: 1.429;
cursor: pointer;
padding-left: 10px;
}
li:hover{
background-color: rgb(238, 238, 238);
}
</style>
<style>
/* Defines the Modal pop-up look and feel for use with Custom Action */
/* https://www.w3schools.com/howto/howto_css_modals.asp */
/* The Modal (background) */
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 4; /* Sit on top */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
min-height: 600px;
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}
/* Modal Content/Box */
.modal-content {
background-color: #fefefe;
margin: 15% auto; /* 15% from the top and centered */
padding: 20px;
border: 1px solid #888;
width: 60%; /* Could be more or less, depending on screen size */
}
/* The Close Button */
.close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: black;
text-decoration: none;
cursor: pointer;
}
</style>
</head>
<body>
<!-- Top header bar. Feel free to add logo or other elements -->
<div id='header'>
<h1>ThoughtSpot Trusted Authentication Test Page</h1>
</div>
<!-- Main page is flex container split into 'sidebar' menu and 'main-content-div' where ThoughtSpot content embeds -->
<div id='page-content-div' style='display: flex;'>
<div id='sidebar'>
<!-- Home item just to look like a real system, feel free to add others below-->
<h3>Enter Details Here</h3>
<hr/>
<p>ThoughtSpot URL:
<input id="url-input"></input>
<p>Liveboard GUID
<input id="liveboard-input"></input>
<p>Username:
<input id="username-input"></input>
<p>Token:
<input id="token-input"></input>
<p></p>
<button id='test-button' class='menu-button' style="display: inline;">Load Liveboard</button> <!-- Change to display: none; to hide -->
<!-- Analytics menu gets populated based on the menuItems object above-->
<h3>Instructions</h3>
<hr/>
<p>The input boxes above take in the necessary values to perform a Trusted Authentication flow in ThoughtSpot. Make sure your CORS and CSP settings are configured in ThoughtSpot to allow the server and port you host this page on.</p>
<p>The "Liveboard GUID" can be found in the URL of any Liveboard (it is the value after '/pinboard/' in the URL)</p>
<p>The Token value should be generated from your Authenticator Service using the using the <a href='https://developers.thoughtspot.com/docs/?pageid=session-api#session-authToken' target="_blank">/session/auth/token</a> API endpoint. This can be as simple as the built in Swagger portal at "/external/swagger" or a simple Python request to generate the token.</p>
<p>The username field must match EXACTLY with the username value used to generate the token</p>
<p>Once you have this working, you will update the <b>authTokenCallback</b> function to make the request to the completed Authenticator Service on demand. You also must set the <b>username</b> in the <b>init</b> function dynamically.
</div>
<div id='main-content-div' style='flex: 3 3 0;'>
<!--<div id="loader">Loader Image Would Go Here</div>
<div id="no-data"></div>-->
<!-- Description is rendered here and set to display:block if it exists -->
<div id='description' style='display:none'></div>
<!-- Embed component goes here -->
<div id='embed'></div>
</div>
</div>
<!-- from https://www.w3schools.com/howto/howto_css_modals.asp -->
<!-- The Modal -->
<div id="myModal" class="modal">
<!-- Modal content, pop-up on a custom action. Doesn't actually DO anything when the buttons are pressed -->
<div class="modal-content">
<span class="close">×</span>
<!-- Header of the modal, change to what feels appropriate -->
<h3>Create a New Item</h3>
<p>Summary <input type='text' id='summary-field' style="width: 400px;"></p>
<p>Description</p>
<textarea style="height: 100px; width: 450px;"></textarea>
<p><button onclick='document.getElementById("myModal").style.display="none";'>Cancel</button> <button onclick='document.getElementById("myModal").style.display="none";'>Create</button></p>
</div>
</div>
<script>
/*
* Modal window operations
*/
// Get the modal
var modal = document.getElementById("myModal");
// Get the button that opens the modal
var btn = document.getElementById("myBtn");
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks on the button, open the modal
//btn.onclick = function() {
//modal.style.display = "block";
//}
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
</script>
<!-- Put the ThoughtSpot EmbedSDK script down here so it runs after the page loads fully -->
<!-- Of note, because this uses the module form of the SDK, all code relating to TS must be in this block,
as the imported functions are not accessible from any other script tag
-->
<script type='module'>
// Import ThoughtSpot SDK
import {
init,
PinboardEmbed,
LiveboardEmbed,
SearchEmbed,
Action,
RuntimeFilterOp,
EmbedEvent,
HostEvent,
AuthType
} from 'https://cdn.jsdelivr.net/npm/@thoughtspot/visual-embed-sdk/dist/tsembed.es.js'; // Copied in from GitHub
// In this tester, the promise simply returns the token entered into the
function authTokenCallback(){
let thoughtspotAuthToken = document.getElementById('token-input').value;
return Promise.resolve(thoughtspotAuthToken);
}
function initThoughtspot(){
// Initialize embed configuration
init(
{
thoughtSpotHost: document.getElementById('url-input').value,
authType: AuthType.AuthServer,
username: document.getElementById('username-input').value,
getAuthToken: authTokenCallback
});
}
const embedDiv = '#embed';
let embed; // Global scoped variable for the current embedded object
function makeLiveboard(guid){
// Instantiate class for embedding a pinboard
embed = new LiveboardEmbed(embedDiv, {
frameParams: {},
/*param-start-modifyActions*/
disabledActions: [],
disabledActionReason: "Reason for disabling",
hiddenActions: [],
/*param-end-modifyActions*/
pinboardId: guid,
/*runtimeFilters: [ {
columnName: 'Country', // eg: color
operator: RuntimeFilterOp.EQ,
values: ['Taiwan'] // eg: red
}
]
/*param-start-runtimeFilters*//*param-end-runtimeFilters*/
});
//hideNoDataImage();
embed
// Register event listeners
//.on(EmbedEvent.Init, showLoader)
//.on(EmbedEvent.Load, hideLoader)
/*param-start-customActionHandle*//*param-end-customActionHandle*/
.on(EmbedEvent.Error, () => {
//showNoDataImage();
//hideLoader();
})
.on(EmbedEvent.CustomAction, (response) => {
console.log('CustomAction event fires');
console.log(response);
const data = response.data;
if (response.id === 'create-jira'){
let dataObj = JSON.parse(data);
console.log(dataObj);
let point = dataObj.selectedPoints[0];
let val1 = point.selectedAttributes[0].value;
let val2 = point.selectedMeasures[0].value;
let summaryText = val1 + " - " + val2;
document.getElementById('summary-field').value = summaryText;
// Display the modal box
modal.style.display = "block";
//return modal;
}
} )
// Render pinboard
.render();
}
function makeVisualization(guid, vizGuid){
// Instantiate class for embedding a pinboard
let embed = new PinboardEmbed(embedDiv, {
frameParams: {},
/*param-start-modifyActions*/
disabledActions: [],
disabledActionReason: "Reason for disabling",
hiddenActions: [],
/*param-end-modifyActions*/
pinboardId: guid,
vizId: vizGuid
/*param-start-runtimeFilters*//*param-end-runtimeFilters*/
});
//hideNoDataImage();
embed
// Register event listeners
//.on(EmbedEvent.Init, showLoader)
//.on(EmbedEvent.Load, hideLoader)
/*param-start-customActionHandle*//*param-end-customActionHandle*/
.on(EmbedEvent.Error, () => {
//showNoDataImage();
//hideLoader();
})
.on(EmbedEvent.CustomAction, (response) => {
console.log('CustomAction event fires');
console.log(response);
const data = response.data;
if (response.id === 'create-jira'){
let dataObj = JSON.parse(data);
console.log(dataObj);
let point = dataObj.selectedPoints[0];
let val1 = point.selectedAttributes[0].value;
let val2 = point.selectedMeasures[0].value;
let summaryText = val1 + " - " + val2;
document.getElementById('summary-field').value = summaryText;
// Display the modal box
modal.style.display = "block";
//return modal;
}
} )
// Render pinboard
.render();
}
function makeSearch(datasourceGuid, searchString){
// Instantiate class for embedding a pinboard
let embed = new SearchEmbed(embedDiv, {
frameParams: {},
/*param-start-modifyActions*/
disabledActions: [],
disabledActionReason: "Reason for disabling",
hiddenActions: [],
/*param-end-modifyActions*/
dataSources: [datasourceGuid],
searchOptions: {
searchTokenString: searchString, //write a TML query
//[commit date][revenue]
executeSearch: true,
},
/*param-start-runtimeFilters*//*param-end-runtimeFilters*/
});
//hideNoDataImage();
embed
// Register event listeners
//.on(EmbedEvent.Init, showLoader)
//.on(EmbedEvent.Load, hideLoader)
/*param-start-customActionHandle*//*param-end-customActionHandle*/
.on(EmbedEvent.Error, () => {
//showNoDataImage();
//hideLoader();
})
.on(EmbedEvent.CustomAction, (response) => {
console.log('CustomAction event fires');
console.log(response);
const data = response.data;
if (response.id === 'create-jira'){
let dataObj = JSON.parse(data);
console.log(dataObj);
let point = dataObj.selectedPoints[0];
let val1 = point.selectedAttributes[0].value;
let val2 = point.selectedMeasures[0].value;
let summaryText = val1 + " - " + val2;
document.getElementById('summary-field').value = summaryText;
// Display the modal box
modal.style.display = "block";
//return modal;
}
} )
// Render pinboard
.render();
}
function makeAnswer(answerGuid){
// Instantiate class for embedding a pinboard
let embed = new SearchEmbed(embedDiv, {
frameParams: {},
/*param-start-modifyActions*/
disabledActions: [],
disabledActionReason: "Reason for disabling",
hiddenActions: [],
/*param-end-modifyActions*/
answerId: answerGuid
/*param-start-runtimeFilters*//*param-end-runtimeFilters*/
});
//hideNoDataImage();
embed
// Register event listeners
//.on(EmbedEvent.Init, showLoader)
//.on(EmbedEvent.Load, hideLoader)
/*param-start-customActionHandle*//*param-end-customActionHandle*/
.on(EmbedEvent.Error, () => {
//showNoDataImage();
//hideLoader();
})
.on(EmbedEvent.CustomAction, (response) => {
console.log('CustomAction event fires');
console.log(response);
const data = response.data;
if (response.id === 'create-jira'){
let dataObj = JSON.parse(data);
console.log(dataObj);
let point = dataObj.selectedPoints[0];
let val1 = point.selectedAttributes[0].value;
let val2 = point.selectedMeasures[0].value;
let summaryText = val1 + " - " + val2;
document.getElementById('summary-field').value = summaryText;
// Display the modal box
modal.style.display = "block";
//return modal;
}
} )
// Render pinboard
.render();
}
// Functions to show and hide a loader while iframe loads
function showLoader() {
document.getElementById("loader").style.display = "block";
}
function hideLoader() {
document.getElementById("loader").style.display = "none";
}
// Functions to show or hide No data images
function showNoDataImage() {
document.getElementById("no-data").style.display = "block";
}
function hideNoDataImage() {
document.getElementById("no-data").style.display = "none";
}
// Clears the embedded section when new menu item is selected
const clearEmbed = () => {
const div = document.getElementById("embed");
div.innerHTML = "";
}
function writeDescription(description) {
let descDiv = document.getElementById("description");
descDiv.style.display = "block";
descDiv.style.fontSize = '18pt';
descDiv.innerHTML = '';
descDiv.innerText = description;
}
/* Router function to read the content type and map to appropriate build function */
function loadContent(contentObj){
console.log('Running load content');
console.log(contentObj);
clearEmbed();
if(contentObj.description !== null){
writeDescription(contentObj.description);
}
else {
document.getElementById("description").style.display = "none";
}
if(contentObj.type == 'liveboard'){
makeLiveboard(contentObj.guid);
}
if(contentObj.type == 'visualization'){
makeVisualization(contentObj.guid, contentObj.vizGuid);
}
if(contentObj.type == 'search'){
makeSearch(contentObj.guid);
}
if(contentObj.type == 'answer'){
makeAnswer(contentObj.guid);
}
}
document.getElementById('test-button').onclick = function (){
initThoughtspot();
makeLiveboard(document.getElementById('liveboard-input').value)
};
</script>
</body>