@thoughtspot/visual-embed-sdk 1.11.0-auth.11 → 1.11.0-auth.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/embed/base.d.ts +4 -1
- package/dist/src/index.d.ts +2 -1
- package/dist/src/types.d.ts +5 -0
- package/dist/tsembed.es.js +51 -24
- package/dist/tsembed.js +59 -34
- package/lib/package.json +1 -1
- package/lib/src/auth.js +4 -8
- package/lib/src/auth.js.map +1 -1
- package/lib/src/auth.spec.js +54 -1
- package/lib/src/auth.spec.js.map +1 -1
- package/lib/src/embed/base.d.ts +4 -1
- package/lib/src/embed/base.js +30 -8
- package/lib/src/embed/base.js.map +1 -1
- package/lib/src/embed/base.spec.js +28 -0
- package/lib/src/embed/base.spec.js.map +1 -1
- package/lib/src/embed/embed.spec.js +1 -1
- package/lib/src/embed/embed.spec.js.map +1 -1
- package/lib/src/embed/ts-embed.js +1 -1
- package/lib/src/embed/ts-embed.js.map +1 -1
- package/lib/src/index.d.ts +2 -1
- package/lib/src/index.js +2 -1
- package/lib/src/index.js.map +1 -1
- package/lib/src/types.d.ts +5 -0
- package/lib/src/types.js +5 -0
- package/lib/src/types.js.map +1 -1
- package/lib/src/utils/authService.js +5 -5
- package/lib/src/utils/authService.js.map +1 -1
- package/lib/src/utils/authService.spec.js +10 -0
- package/lib/src/utils/authService.spec.js.map +1 -1
- package/lib/src/utils/processData.js +11 -1
- package/lib/src/utils/processData.js.map +1 -1
- package/lib/src/utils/processData.spec.js +21 -0
- package/lib/src/utils/processData.spec.js.map +1 -1
- package/lib/src/visual-embed-sdk.d.ts +70 -61
- package/package.json +1 -1
- package/src/auth.spec.ts +67 -1
- package/src/auth.ts +4 -7
- package/src/embed/base.spec.ts +33 -0
- package/src/embed/base.ts +33 -8
- package/src/embed/embed.spec.ts +1 -1
- package/src/embed/ts-embed.ts +1 -1
- package/src/index.ts +3 -0
- package/src/types.ts +5 -0
- package/src/utils/authService.spec.ts +13 -0
- package/src/utils/authService.ts +4 -5
- package/src/utils/processData.spec.ts +25 -0
- package/src/utils/processData.ts +13 -0
|
@@ -10,6 +10,9 @@ describe('Unit test for process data', () => {
|
|
|
10
10
|
authType: AuthType.None,
|
|
11
11
|
});
|
|
12
12
|
});
|
|
13
|
+
afterEach(() => {
|
|
14
|
+
jest.resetAllMocks();
|
|
15
|
+
});
|
|
13
16
|
const thoughtSpotHost = 'http://localhost';
|
|
14
17
|
test('processDataInstance, when operation is GetChartWithData', () => {
|
|
15
18
|
const answerService = {};
|
|
@@ -126,5 +129,23 @@ describe('Unit test for process data', () => {
|
|
|
126
129
|
expect(base.notifyAuthFailure).toBeCalledWith(auth.AuthFailureType.OTHER);
|
|
127
130
|
expect(el.innerHTML).toBe('Hello');
|
|
128
131
|
});
|
|
132
|
+
test('process authLogout', () => {
|
|
133
|
+
base.init({
|
|
134
|
+
loginFailedMessage: 'Hello',
|
|
135
|
+
autoLogin: true,
|
|
136
|
+
thoughtSpotHost: '',
|
|
137
|
+
authType: AuthType.None,
|
|
138
|
+
});
|
|
139
|
+
jest.spyOn(base, 'getEmbedConfig').mockRestore();
|
|
140
|
+
const e = { type: EmbedEvent.AuthLogout };
|
|
141
|
+
jest.spyOn(base, 'notifyLogout');
|
|
142
|
+
const el = {};
|
|
143
|
+
expect(processDataInstance.processEventData(e.type, e, '', el)).toEqual({
|
|
144
|
+
type: e.type,
|
|
145
|
+
});
|
|
146
|
+
expect(base.notifyLogout).toBeCalled();
|
|
147
|
+
expect(el.innerHTML).toBe('Hello');
|
|
148
|
+
expect(base.getEmbedConfig().autoLogin).toBe(false);
|
|
149
|
+
});
|
|
129
150
|
});
|
|
130
151
|
//# sourceMappingURL=processData.spec.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processData.spec.js","sourceRoot":"","sources":["../../../src/utils/processData.spec.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,mBAAmB,MAAM,eAAe,CAAC;AACrD,OAA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C;QACF,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,UAAU,EAAE,CAAC;QACvC,MAAM,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACnC,MAAM,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACxD,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -16,8 +16,9 @@ declare module '@thoughtspot/visual-embed-sdk' {
|
|
|
16
16
|
import { init, prefetch, logout } from '@thoughtspot/visual-embed-sdk/embed/base';
|
|
17
17
|
import { PinboardEmbed, LiveboardViewConfig, LiveboardEmbed } from '@thoughtspot/visual-embed-sdk/embed/liveboard';
|
|
18
18
|
import { SearchEmbed, SearchViewConfig } from '@thoughtspot/visual-embed-sdk/embed/search';
|
|
19
|
+
import { AuthFailureType, AuthStatus } from '@thoughtspot/visual-embed-sdk/auth';
|
|
19
20
|
import { AuthType, RuntimeFilter, RuntimeFilterOp, EmbedEvent, HostEvent, DataSourceVisualMode, Action, EmbedConfig } from '@thoughtspot/visual-embed-sdk/types';
|
|
20
|
-
export { init, logout, prefetch, SearchEmbed, PinboardEmbed, LiveboardEmbed, AppEmbed, Page, AuthType, RuntimeFilter, RuntimeFilterOp, EmbedEvent, HostEvent, DataSourceVisualMode, Action, EmbedConfig, SearchViewConfig, LiveboardViewConfig, AppViewConfig, };
|
|
21
|
+
export { init, logout, prefetch, SearchEmbed, PinboardEmbed, LiveboardEmbed, AppEmbed, AuthFailureType, AuthStatus, Page, AuthType, RuntimeFilter, RuntimeFilterOp, EmbedEvent, HostEvent, DataSourceVisualMode, Action, EmbedConfig, SearchViewConfig, LiveboardViewConfig, AppViewConfig, };
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
declare module '@thoughtspot/visual-embed-sdk/embed/app' {
|
|
@@ -152,6 +153,7 @@ declare module '@thoughtspot/visual-embed-sdk/embed/base' {
|
|
|
152
153
|
export const getAuthPromise: () => Promise<boolean>;
|
|
153
154
|
export function notifyAuthSuccess(): void;
|
|
154
155
|
export function notifyAuthFailure(failureType: AuthFailureType): void;
|
|
156
|
+
export function notifyLogout(): void;
|
|
155
157
|
/**
|
|
156
158
|
* Perform authentication on the ThoughtSpot app as applicable.
|
|
157
159
|
*/
|
|
@@ -170,12 +172,14 @@ declare module '@thoughtspot/visual-embed-sdk/embed/base' {
|
|
|
170
172
|
* @returns authPromise Promise which resolves when authentication is complete.
|
|
171
173
|
*/
|
|
172
174
|
export const init: (embedConfig: EmbedConfig) => EventEmitter;
|
|
173
|
-
export
|
|
175
|
+
export function disableAutoLogin(): void;
|
|
176
|
+
export const logout: (doNotDisableAutoLogin?: boolean) => Promise<boolean>;
|
|
174
177
|
/**
|
|
175
178
|
* Renders functions in a queue, resolves to next function only after the callback next is called
|
|
176
179
|
* @param fn The function being registered
|
|
177
180
|
*/
|
|
178
181
|
export const renderInQueue: (fn: (next?: (val?: any) => void) => void) => void;
|
|
182
|
+
export function reset(): void;
|
|
179
183
|
}
|
|
180
184
|
|
|
181
185
|
declare module '@thoughtspot/visual-embed-sdk/embed/liveboard' {
|
|
@@ -368,6 +372,65 @@ declare module '@thoughtspot/visual-embed-sdk/embed/search' {
|
|
|
368
372
|
export {};
|
|
369
373
|
}
|
|
370
374
|
|
|
375
|
+
declare module '@thoughtspot/visual-embed-sdk/auth' {
|
|
376
|
+
import { EmbedConfig } from '@thoughtspot/visual-embed-sdk/types';
|
|
377
|
+
export let loggedInStatus: boolean;
|
|
378
|
+
export let samlAuthWindow: Window;
|
|
379
|
+
export let samlCompletionPromise: Promise<void>;
|
|
380
|
+
export let sessionInfo: any;
|
|
381
|
+
export const SSO_REDIRECTION_MARKER_GUID = "5e16222e-ef02-43e9-9fbd-24226bf3ce5b";
|
|
382
|
+
export const EndPoints: {
|
|
383
|
+
AUTH_VERIFICATION: string;
|
|
384
|
+
SAML_LOGIN_TEMPLATE: (targetUrl: string) => string;
|
|
385
|
+
OIDC_LOGIN_TEMPLATE: (targetUrl: string) => string;
|
|
386
|
+
TOKEN_LOGIN: string;
|
|
387
|
+
BASIC_LOGIN: string;
|
|
388
|
+
LOGOUT: string;
|
|
389
|
+
};
|
|
390
|
+
export enum AuthFailureType {
|
|
391
|
+
SDK = "SDK",
|
|
392
|
+
NO_COOKIE_ACCESS = "NO_COOKIE_ACCESS",
|
|
393
|
+
EXPIRY = "EXPIRY",
|
|
394
|
+
OTHER = "OTHER"
|
|
395
|
+
}
|
|
396
|
+
export enum AuthStatus {
|
|
397
|
+
FAILURE = "FAILURE",
|
|
398
|
+
SUCCESS = "SUCCESS",
|
|
399
|
+
LOGOUT = "LOGOUT"
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Return sessionInfo if available else make a loggedIn check to fetch the sessionInfo
|
|
403
|
+
*/
|
|
404
|
+
export function getSessionInfo(): any;
|
|
405
|
+
export function initSession(sessionDetails: any): void;
|
|
406
|
+
/**
|
|
407
|
+
* Perform token based authentication
|
|
408
|
+
* @param embedConfig The embed configuration
|
|
409
|
+
*/
|
|
410
|
+
export const doTokenAuth: (embedConfig: EmbedConfig) => Promise<boolean>;
|
|
411
|
+
/**
|
|
412
|
+
* Perform basic authentication to the ThoughtSpot cluster using the cluster
|
|
413
|
+
* credentials.
|
|
414
|
+
*
|
|
415
|
+
* Warning: This feature is primarily intended for developer testing. It is
|
|
416
|
+
* strongly advised not to use this authentication method in production.
|
|
417
|
+
* @param embedConfig The embed configuration
|
|
418
|
+
*/
|
|
419
|
+
export const doBasicAuth: (embedConfig: EmbedConfig) => Promise<boolean>;
|
|
420
|
+
export const doSamlAuth: (embedConfig: EmbedConfig) => Promise<boolean>;
|
|
421
|
+
export const doOIDCAuth: (embedConfig: EmbedConfig) => Promise<boolean>;
|
|
422
|
+
export const logout: (embedConfig: EmbedConfig) => Promise<boolean>;
|
|
423
|
+
/**
|
|
424
|
+
* Perform authentication on the ThoughtSpot cluster
|
|
425
|
+
* @param embedConfig The embed configuration
|
|
426
|
+
*/
|
|
427
|
+
export const authenticate: (embedConfig: EmbedConfig) => Promise<boolean>;
|
|
428
|
+
/**
|
|
429
|
+
* Check if we are authenticated to the ThoughtSpot cluster
|
|
430
|
+
*/
|
|
431
|
+
export const isAuthenticated: () => boolean;
|
|
432
|
+
}
|
|
433
|
+
|
|
371
434
|
declare module '@thoughtspot/visual-embed-sdk/types' {
|
|
372
435
|
/**
|
|
373
436
|
* The authentication mechanism for allowing access to the
|
|
@@ -705,6 +768,11 @@ declare module '@thoughtspot/visual-embed-sdk/types' {
|
|
|
705
768
|
* @hidden
|
|
706
769
|
*/
|
|
707
770
|
AuthFailure = "ThoughtspotAuthFailure",
|
|
771
|
+
/**
|
|
772
|
+
* ThoughtSpot failed to validate the auth session.
|
|
773
|
+
* @hidden
|
|
774
|
+
*/
|
|
775
|
+
AuthLogout = "ThoughtspotAuthLogout",
|
|
708
776
|
/**
|
|
709
777
|
* The height of the embedded Liveboard or visualization has been computed.
|
|
710
778
|
* @return data - The height of the embedded Liveboard or visualization
|
|
@@ -1358,62 +1426,3 @@ declare module '@thoughtspot/visual-embed-sdk/embed/ts-embed' {
|
|
|
1358
1426
|
}
|
|
1359
1427
|
}
|
|
1360
1428
|
|
|
1361
|
-
declare module '@thoughtspot/visual-embed-sdk/auth' {
|
|
1362
|
-
import { EmbedConfig } from '@thoughtspot/visual-embed-sdk/types';
|
|
1363
|
-
export let loggedInStatus: boolean;
|
|
1364
|
-
export let samlAuthWindow: Window;
|
|
1365
|
-
export let samlCompletionPromise: Promise<void>;
|
|
1366
|
-
export let sessionInfo: any;
|
|
1367
|
-
export const SSO_REDIRECTION_MARKER_GUID = "5e16222e-ef02-43e9-9fbd-24226bf3ce5b";
|
|
1368
|
-
export const EndPoints: {
|
|
1369
|
-
AUTH_VERIFICATION: string;
|
|
1370
|
-
SAML_LOGIN_TEMPLATE: (targetUrl: string) => string;
|
|
1371
|
-
OIDC_LOGIN_TEMPLATE: (targetUrl: string) => string;
|
|
1372
|
-
TOKEN_LOGIN: string;
|
|
1373
|
-
BASIC_LOGIN: string;
|
|
1374
|
-
LOGOUT: string;
|
|
1375
|
-
};
|
|
1376
|
-
export enum AuthFailureType {
|
|
1377
|
-
SDK = "SDK",
|
|
1378
|
-
NO_COOKIE_ACCESS = "NO_COOKIE_ACCESS",
|
|
1379
|
-
EXPIRY = "EXPIRY",
|
|
1380
|
-
OTHER = "OTHER"
|
|
1381
|
-
}
|
|
1382
|
-
export enum AuthStatus {
|
|
1383
|
-
FAILURE = "FAILURE",
|
|
1384
|
-
SUCCESS = "SUCCESS",
|
|
1385
|
-
LOGOUT = "LOGOUT"
|
|
1386
|
-
}
|
|
1387
|
-
/**
|
|
1388
|
-
* Return sessionInfo if available else make a loggedIn check to fetch the sessionInfo
|
|
1389
|
-
*/
|
|
1390
|
-
export function getSessionInfo(): any;
|
|
1391
|
-
export function initSession(sessionDetails: any): void;
|
|
1392
|
-
/**
|
|
1393
|
-
* Perform token based authentication
|
|
1394
|
-
* @param embedConfig The embed configuration
|
|
1395
|
-
*/
|
|
1396
|
-
export const doTokenAuth: (embedConfig: EmbedConfig) => Promise<boolean>;
|
|
1397
|
-
/**
|
|
1398
|
-
* Perform basic authentication to the ThoughtSpot cluster using the cluster
|
|
1399
|
-
* credentials.
|
|
1400
|
-
*
|
|
1401
|
-
* Warning: This feature is primarily intended for developer testing. It is
|
|
1402
|
-
* strongly advised not to use this authentication method in production.
|
|
1403
|
-
* @param embedConfig The embed configuration
|
|
1404
|
-
*/
|
|
1405
|
-
export const doBasicAuth: (embedConfig: EmbedConfig) => Promise<boolean>;
|
|
1406
|
-
export const doSamlAuth: (embedConfig: EmbedConfig) => Promise<boolean>;
|
|
1407
|
-
export const doOIDCAuth: (embedConfig: EmbedConfig) => Promise<boolean>;
|
|
1408
|
-
export const logout: (embedConfig: EmbedConfig) => Promise<boolean>;
|
|
1409
|
-
/**
|
|
1410
|
-
* Perform authentication on the ThoughtSpot cluster
|
|
1411
|
-
* @param embedConfig The embed configuration
|
|
1412
|
-
*/
|
|
1413
|
-
export const authenticate: (embedConfig: EmbedConfig) => Promise<boolean>;
|
|
1414
|
-
/**
|
|
1415
|
-
* Check if we are authenticated to the ThoughtSpot cluster
|
|
1416
|
-
*/
|
|
1417
|
-
export const isAuthenticated: () => boolean;
|
|
1418
|
-
}
|
|
1419
|
-
|
package/package.json
CHANGED
package/src/auth.spec.ts
CHANGED
|
@@ -35,9 +35,15 @@ const embedConfig: any = {
|
|
|
35
35
|
doSamlAuth: {
|
|
36
36
|
thoughtSpotHost,
|
|
37
37
|
},
|
|
38
|
+
doOidcAuth: {
|
|
39
|
+
thoughtSpotHost,
|
|
40
|
+
},
|
|
38
41
|
SSOAuth: {
|
|
39
42
|
authType: AuthType.SSO,
|
|
40
43
|
},
|
|
44
|
+
OIDCAuth: {
|
|
45
|
+
authType: AuthType.OIDC,
|
|
46
|
+
},
|
|
41
47
|
authServerFailure: {
|
|
42
48
|
thoughtSpotHost,
|
|
43
49
|
username,
|
|
@@ -168,6 +174,38 @@ describe('Unit test for auth', () => {
|
|
|
168
174
|
});
|
|
169
175
|
});
|
|
170
176
|
|
|
177
|
+
test('doTokenAuth: Should raise error when duplicate token is used', async () => {
|
|
178
|
+
jest.spyOn(authService, 'fetchSessionInfoService').mockResolvedValue({
|
|
179
|
+
status: 401,
|
|
180
|
+
});
|
|
181
|
+
jest.spyOn(window, 'alert').mockClear();
|
|
182
|
+
jest.spyOn(window, 'alert').mockReturnValue(undefined);
|
|
183
|
+
jest.spyOn(authService, 'fetchAuthService').mockReset();
|
|
184
|
+
jest.spyOn(authService, 'fetchAuthService').mockImplementation(() =>
|
|
185
|
+
Promise.resolve({
|
|
186
|
+
status: 200,
|
|
187
|
+
ok: true,
|
|
188
|
+
}),
|
|
189
|
+
);
|
|
190
|
+
await authInstance.doTokenAuth(
|
|
191
|
+
embedConfig.doTokenAuthSuccess('authToken3'),
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
try {
|
|
195
|
+
await authInstance.doTokenAuth(
|
|
196
|
+
embedConfig.doTokenAuthSuccess('authToken3'),
|
|
197
|
+
);
|
|
198
|
+
expect(false).toBe(true);
|
|
199
|
+
} catch (e) {
|
|
200
|
+
expect(e.message).toContain('Duplicate token');
|
|
201
|
+
}
|
|
202
|
+
await executeAfterWait(() => {
|
|
203
|
+
expect(authInstance.loggedInStatus).toBe(false);
|
|
204
|
+
expect(window.alert).toBeCalled();
|
|
205
|
+
expect(authService.fetchAuthService).toHaveBeenCalledTimes(1);
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
|
|
171
209
|
describe('doBasicAuth', () => {
|
|
172
210
|
beforeEach(() => {
|
|
173
211
|
global.fetch = window.fetch;
|
|
@@ -266,6 +304,7 @@ describe('Unit test for auth', () => {
|
|
|
266
304
|
},
|
|
267
305
|
});
|
|
268
306
|
spyOn(authInstance, 'samlCompletionPromise');
|
|
307
|
+
global.window.open = jest.fn();
|
|
269
308
|
jest.spyOn(
|
|
270
309
|
authService,
|
|
271
310
|
'fetchSessionInfoService',
|
|
@@ -276,8 +315,28 @@ describe('Unit test for auth', () => {
|
|
|
276
315
|
...embedConfig.doSamlAuth,
|
|
277
316
|
noRedirect: true,
|
|
278
317
|
}),
|
|
279
|
-
).toBe(
|
|
318
|
+
).toBe(true);
|
|
319
|
+
expect(authService.fetchSessionInfoService).toBeCalled();
|
|
320
|
+
});
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
describe('doOIDCAuth', () => {
|
|
324
|
+
afterEach(() => {
|
|
325
|
+
delete global.window;
|
|
326
|
+
global.window = Object.create(originalWindow);
|
|
327
|
+
global.window.open = jest.fn();
|
|
328
|
+
global.fetch = window.fetch;
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
it('when user is not loggedIn & isAtSSORedirectUrl is true', async () => {
|
|
332
|
+
jest.spyOn(
|
|
333
|
+
authService,
|
|
334
|
+
'fetchSessionInfoService',
|
|
335
|
+
).mockImplementation(() => Promise.reject());
|
|
336
|
+
await authInstance.doOIDCAuth(embedConfig.doOidcAuth);
|
|
280
337
|
expect(authService.fetchSessionInfoService).toBeCalled();
|
|
338
|
+
expect(window.location.hash).toBe('');
|
|
339
|
+
expect(authInstance.loggedInStatus).toBe(false);
|
|
281
340
|
});
|
|
282
341
|
});
|
|
283
342
|
|
|
@@ -288,6 +347,13 @@ describe('Unit test for auth', () => {
|
|
|
288
347
|
expect(authInstance.doSamlAuth).toBeCalled();
|
|
289
348
|
});
|
|
290
349
|
|
|
350
|
+
it('authenticate: when authType is OIDC', async () => {
|
|
351
|
+
jest.spyOn(authInstance, 'doOIDCAuth');
|
|
352
|
+
await authInstance.authenticate(embedConfig.OIDCAuth);
|
|
353
|
+
expect(window.location.hash).toBe('');
|
|
354
|
+
expect(authInstance.doOIDCAuth).toBeCalled();
|
|
355
|
+
});
|
|
356
|
+
|
|
291
357
|
it('authenticate: when authType is AuthServer', async () => {
|
|
292
358
|
spyOn(authInstance, 'doTokenAuth');
|
|
293
359
|
await authInstance.authenticate(embedConfig.authServerFailure);
|
package/src/auth.ts
CHANGED
|
@@ -125,8 +125,8 @@ export const doTokenAuth = async (
|
|
|
125
125
|
'Either auth endpoint or getAuthToken function must be provided',
|
|
126
126
|
);
|
|
127
127
|
}
|
|
128
|
-
|
|
129
|
-
if (!
|
|
128
|
+
loggedInStatus = await isLoggedIn(thoughtSpotHost);
|
|
129
|
+
if (!loggedInStatus) {
|
|
130
130
|
let authToken = null;
|
|
131
131
|
if (getAuthToken) {
|
|
132
132
|
authToken = await getAuthToken();
|
|
@@ -142,8 +142,6 @@ export const doTokenAuth = async (
|
|
|
142
142
|
);
|
|
143
143
|
// token login issues a 302 when successful
|
|
144
144
|
loggedInStatus = resp.ok || resp.type === 'opaqueredirect';
|
|
145
|
-
} else {
|
|
146
|
-
loggedInStatus = true;
|
|
147
145
|
}
|
|
148
146
|
return loggedInStatus;
|
|
149
147
|
};
|
|
@@ -238,6 +236,7 @@ const doSSOAuth = async (
|
|
|
238
236
|
const ssoURL = `${thoughtSpotHost}${ssoEndPoint}`;
|
|
239
237
|
if (embedConfig.noRedirect) {
|
|
240
238
|
await samlPopupFlow(ssoURL);
|
|
239
|
+
loggedInStatus = true;
|
|
241
240
|
return;
|
|
242
241
|
}
|
|
243
242
|
|
|
@@ -281,9 +280,7 @@ export const doOIDCAuth = async (embedConfig: EmbedConfig) => {
|
|
|
281
280
|
export const logout = async (embedConfig: EmbedConfig): Promise<boolean> => {
|
|
282
281
|
const { thoughtSpotHost } = embedConfig;
|
|
283
282
|
const response = await fetchLogoutService(thoughtSpotHost);
|
|
284
|
-
|
|
285
|
-
loggedInStatus = false;
|
|
286
|
-
}
|
|
283
|
+
loggedInStatus = false;
|
|
287
284
|
return loggedInStatus;
|
|
288
285
|
};
|
|
289
286
|
|
package/src/embed/base.spec.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import EventEmitter from 'eventemitter3';
|
|
2
2
|
import * as auth from '../auth';
|
|
3
3
|
import * as index from '../index';
|
|
4
|
+
import * as base from './base';
|
|
4
5
|
import {
|
|
5
6
|
executeAfterWait,
|
|
6
7
|
getAllIframeEl,
|
|
@@ -111,4 +112,36 @@ describe('Base TS Embed', () => {
|
|
|
111
112
|
done();
|
|
112
113
|
});
|
|
113
114
|
});
|
|
115
|
+
|
|
116
|
+
test('Logout method should disable autoLogin', () => {
|
|
117
|
+
jest.spyOn(window, 'fetch').mockResolvedValue({
|
|
118
|
+
type: 'opaque',
|
|
119
|
+
});
|
|
120
|
+
index.init({
|
|
121
|
+
thoughtSpotHost,
|
|
122
|
+
authType: index.AuthType.None,
|
|
123
|
+
autoLogin: true,
|
|
124
|
+
});
|
|
125
|
+
index.logout();
|
|
126
|
+
expect(window.fetch).toHaveBeenCalledWith(
|
|
127
|
+
`http://${thoughtSpotHost}${auth.EndPoints.LOGOUT}`,
|
|
128
|
+
{
|
|
129
|
+
credentials: 'include',
|
|
130
|
+
mode: 'no-cors',
|
|
131
|
+
method: 'POST',
|
|
132
|
+
},
|
|
133
|
+
);
|
|
134
|
+
expect(base.getEmbedConfig().autoLogin).toBe(false);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
describe('Base without init', () => {
|
|
139
|
+
test('notify should error when called without init', () => {
|
|
140
|
+
base.reset();
|
|
141
|
+
jest.spyOn(global.console, 'error').mockImplementation(() => undefined);
|
|
142
|
+
base.notifyAuthSuccess();
|
|
143
|
+
base.notifyAuthFailure(auth.AuthFailureType.SDK);
|
|
144
|
+
base.notifyLogout();
|
|
145
|
+
expect(global.console.error).toHaveBeenCalledTimes(3);
|
|
146
|
+
});
|
|
114
147
|
});
|
package/src/embed/base.ts
CHANGED
|
@@ -47,15 +47,19 @@ export function notifyAuthFailure(failureType: AuthFailureType): void {
|
|
|
47
47
|
}
|
|
48
48
|
authEE.emit(AuthStatus.FAILURE, failureType);
|
|
49
49
|
}
|
|
50
|
+
|
|
51
|
+
export function notifyLogout(): void {
|
|
52
|
+
if (!authEE) {
|
|
53
|
+
console.error('SDK not initialized');
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
authEE.emit(AuthStatus.LOGOUT);
|
|
57
|
+
}
|
|
50
58
|
/**
|
|
51
59
|
* Perform authentication on the ThoughtSpot app as applicable.
|
|
52
60
|
*/
|
|
53
61
|
export const handleAuth = (): Promise<boolean> => {
|
|
54
|
-
|
|
55
|
-
...config,
|
|
56
|
-
thoughtSpotHost: getThoughtSpotHost(config),
|
|
57
|
-
};
|
|
58
|
-
authPromise = authenticate(authConfig);
|
|
62
|
+
authPromise = authenticate(config);
|
|
59
63
|
authPromise.then(
|
|
60
64
|
(isLoggedIn) => {
|
|
61
65
|
if (!isLoggedIn) {
|
|
@@ -97,7 +101,11 @@ export const prefetch = (url?: string): void => {
|
|
|
97
101
|
* @returns authPromise Promise which resolves when authentication is complete.
|
|
98
102
|
*/
|
|
99
103
|
export const init = (embedConfig: EmbedConfig): EventEmitter => {
|
|
100
|
-
config = {
|
|
104
|
+
config = {
|
|
105
|
+
...CONFIG_DEFAULTS,
|
|
106
|
+
...embedConfig,
|
|
107
|
+
thoughtSpotHost: getThoughtSpotHost(embedConfig),
|
|
108
|
+
};
|
|
101
109
|
authEE = new EventEmitter();
|
|
102
110
|
handleAuth();
|
|
103
111
|
|
|
@@ -112,8 +120,18 @@ export const init = (embedConfig: EmbedConfig): EventEmitter => {
|
|
|
112
120
|
return authEE;
|
|
113
121
|
};
|
|
114
122
|
|
|
115
|
-
export
|
|
116
|
-
|
|
123
|
+
export function disableAutoLogin(): void {
|
|
124
|
+
config.autoLogin = false;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export const logout = (doNotDisableAutoLogin = false): Promise<boolean> => {
|
|
128
|
+
if (!doNotDisableAutoLogin) {
|
|
129
|
+
disableAutoLogin();
|
|
130
|
+
}
|
|
131
|
+
return _logout(config).then((isLoggedIn) => {
|
|
132
|
+
notifyLogout();
|
|
133
|
+
return isLoggedIn;
|
|
134
|
+
});
|
|
117
135
|
};
|
|
118
136
|
|
|
119
137
|
let renderQueue: Promise<any> = Promise.resolve();
|
|
@@ -131,3 +149,10 @@ export const renderInQueue = (fn: (next?: (val?: any) => void) => void) => {
|
|
|
131
149
|
fn(() => {}); // eslint-disable-line @typescript-eslint/no-empty-function
|
|
132
150
|
}
|
|
133
151
|
};
|
|
152
|
+
|
|
153
|
+
// For testing purposes only
|
|
154
|
+
export function reset(): void {
|
|
155
|
+
config = {} as any;
|
|
156
|
+
authEE = null;
|
|
157
|
+
authPromise = null;
|
|
158
|
+
}
|
package/src/embed/embed.spec.ts
CHANGED
|
@@ -71,7 +71,7 @@ describe('Custom CSS Url', () => {
|
|
|
71
71
|
document.body.innerHTML = getDocumentBody();
|
|
72
72
|
});
|
|
73
73
|
|
|
74
|
-
test
|
|
74
|
+
test('passing customCssUrl should set the correct query params on the iframe', async (done) => {
|
|
75
75
|
init({
|
|
76
76
|
thoughtSpotHost,
|
|
77
77
|
authType: AuthType.None,
|
package/src/embed/ts-embed.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
LiveboardEmbed,
|
|
17
17
|
} from './embed/liveboard';
|
|
18
18
|
import { SearchEmbed, SearchViewConfig } from './embed/search';
|
|
19
|
+
import { AuthFailureType, AuthStatus } from './auth';
|
|
19
20
|
import {
|
|
20
21
|
AuthType,
|
|
21
22
|
RuntimeFilter,
|
|
@@ -35,6 +36,8 @@ export {
|
|
|
35
36
|
PinboardEmbed,
|
|
36
37
|
LiveboardEmbed,
|
|
37
38
|
AppEmbed,
|
|
39
|
+
AuthFailureType,
|
|
40
|
+
AuthStatus,
|
|
38
41
|
// types
|
|
39
42
|
Page,
|
|
40
43
|
AuthType,
|
package/src/types.ts
CHANGED
|
@@ -376,6 +376,11 @@ export enum EmbedEvent {
|
|
|
376
376
|
* @hidden
|
|
377
377
|
*/
|
|
378
378
|
AuthFailure = 'ThoughtspotAuthFailure',
|
|
379
|
+
/**
|
|
380
|
+
* ThoughtSpot failed to validate the auth session.
|
|
381
|
+
* @hidden
|
|
382
|
+
*/
|
|
383
|
+
AuthLogout = 'ThoughtspotAuthLogout',
|
|
379
384
|
/**
|
|
380
385
|
* The height of the embedded Liveboard or visualization has been computed.
|
|
381
386
|
* @return data - The height of the embedded Liveboard or visualization
|
|
@@ -63,4 +63,17 @@ describe('Unit test for authService', () => {
|
|
|
63
63
|
await fetchBasicAuthService(thoughtSpotHost, username, password);
|
|
64
64
|
expect(fetch).toBeCalled();
|
|
65
65
|
});
|
|
66
|
+
|
|
67
|
+
test('log error on API failures', async () => {
|
|
68
|
+
jest.spyOn(global.console, 'error').mockImplementation(() => undefined);
|
|
69
|
+
global.fetch = jest.fn(() =>
|
|
70
|
+
Promise.resolve({
|
|
71
|
+
text: () => Promise.resolve('error'),
|
|
72
|
+
status: 500,
|
|
73
|
+
ok: false,
|
|
74
|
+
}),
|
|
75
|
+
);
|
|
76
|
+
await fetchSessionInfoService(authVerificationUrl);
|
|
77
|
+
expect(global.console.error).toHaveBeenCalledWith('Failure', 'error');
|
|
78
|
+
});
|
|
66
79
|
});
|
package/src/utils/authService.ts
CHANGED
|
@@ -6,8 +6,8 @@ function failureLoggedFetch(
|
|
|
6
6
|
options: RequestInit = {},
|
|
7
7
|
): Promise<Response> {
|
|
8
8
|
return fetch(url, options).then(async (r) => {
|
|
9
|
-
if (!r.ok && r.type !== 'opaqueredirect') {
|
|
10
|
-
console.error('Failure', await r.text());
|
|
9
|
+
if (!r.ok && r.type !== 'opaqueredirect' && r.type !== 'opaque') {
|
|
10
|
+
console.error('Failure', await r.text?.());
|
|
11
11
|
}
|
|
12
12
|
return r;
|
|
13
13
|
});
|
|
@@ -65,8 +65,7 @@ export async function fetchLogoutService(
|
|
|
65
65
|
): Promise<any> {
|
|
66
66
|
return failureLoggedFetch(`${thoughtSpotHost}${EndPoints.LOGOUT}`, {
|
|
67
67
|
credentials: 'include',
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
},
|
|
68
|
+
mode: 'no-cors',
|
|
69
|
+
method: 'POST',
|
|
71
70
|
});
|
|
72
71
|
}
|
|
@@ -11,6 +11,10 @@ describe('Unit test for process data', () => {
|
|
|
11
11
|
authType: AuthType.None,
|
|
12
12
|
});
|
|
13
13
|
});
|
|
14
|
+
afterEach(() => {
|
|
15
|
+
jest.resetAllMocks();
|
|
16
|
+
});
|
|
17
|
+
|
|
14
18
|
const thoughtSpotHost = 'http://localhost';
|
|
15
19
|
test('processDataInstance, when operation is GetChartWithData', () => {
|
|
16
20
|
const answerService = {};
|
|
@@ -186,4 +190,25 @@ describe('Unit test for process data', () => {
|
|
|
186
190
|
);
|
|
187
191
|
expect(el.innerHTML).toBe('Hello');
|
|
188
192
|
});
|
|
193
|
+
|
|
194
|
+
test('process authLogout', () => {
|
|
195
|
+
base.init({
|
|
196
|
+
loginFailedMessage: 'Hello',
|
|
197
|
+
autoLogin: true,
|
|
198
|
+
thoughtSpotHost: '',
|
|
199
|
+
authType: AuthType.None,
|
|
200
|
+
});
|
|
201
|
+
jest.spyOn(base, 'getEmbedConfig').mockRestore();
|
|
202
|
+
const e = { type: EmbedEvent.AuthLogout };
|
|
203
|
+
jest.spyOn(base, 'notifyLogout');
|
|
204
|
+
const el: any = {};
|
|
205
|
+
expect(processDataInstance.processEventData(e.type, e, '', el)).toEqual(
|
|
206
|
+
{
|
|
207
|
+
type: e.type,
|
|
208
|
+
},
|
|
209
|
+
);
|
|
210
|
+
expect(base.notifyLogout).toBeCalled();
|
|
211
|
+
expect(el.innerHTML).toBe('Hello');
|
|
212
|
+
expect(base.getEmbedConfig().autoLogin).toBe(false);
|
|
213
|
+
});
|
|
189
214
|
});
|
package/src/utils/processData.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
|
+
disableAutoLogin,
|
|
2
3
|
getEmbedConfig,
|
|
3
4
|
handleAuth,
|
|
4
5
|
notifyAuthFailure,
|
|
5
6
|
notifyAuthSuccess,
|
|
7
|
+
notifyLogout,
|
|
6
8
|
} from '../embed/base';
|
|
7
9
|
import { AuthFailureType, initSession } from '../auth';
|
|
8
10
|
import { EmbedEvent, OperationType } from '../types';
|
|
@@ -78,6 +80,15 @@ function processAuthFailure(e: any, containerEl: Element) {
|
|
|
78
80
|
return e;
|
|
79
81
|
}
|
|
80
82
|
|
|
83
|
+
function processAuthLogout(e: any, containerEl: Element) {
|
|
84
|
+
const { loginFailedMessage } = getEmbedConfig();
|
|
85
|
+
// eslint-disable-next-line no-param-reassign
|
|
86
|
+
containerEl.innerHTML = loginFailedMessage;
|
|
87
|
+
disableAutoLogin();
|
|
88
|
+
notifyLogout();
|
|
89
|
+
return e;
|
|
90
|
+
}
|
|
91
|
+
|
|
81
92
|
export function processEventData(
|
|
82
93
|
type: EmbedEvent,
|
|
83
94
|
e: any,
|
|
@@ -95,6 +106,8 @@ export function processEventData(
|
|
|
95
106
|
return processNoCookieAccess(e, containerEl);
|
|
96
107
|
case EmbedEvent.AuthFailure:
|
|
97
108
|
return processAuthFailure(e, containerEl);
|
|
109
|
+
case EmbedEvent.AuthLogout:
|
|
110
|
+
return processAuthLogout(e, containerEl);
|
|
98
111
|
default:
|
|
99
112
|
}
|
|
100
113
|
return e;
|