@thoughtspot/visual-embed-sdk 1.11.0-auth.9 → 1.11.2
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/CHANGELOG.md +24 -2
- package/README.md +15 -2
- package/dist/src/auth.d.ts +13 -0
- package/dist/src/embed/base.d.ts +34 -4
- package/dist/src/embed/search.d.ts +4 -0
- package/dist/src/embed/ts-embed.d.ts +2 -2
- package/dist/src/index.d.ts +3 -2
- package/dist/src/types.d.ts +32 -1
- package/dist/src/utils/authService.d.ts +1 -0
- package/dist/src/utils/processData.d.ts +1 -1
- package/dist/src/utils.d.ts +1 -0
- package/dist/tsembed.es.js +1483 -2869
- package/dist/tsembed.js +1481 -2868
- package/lib/package.json +3 -2
- package/lib/src/auth.d.ts +13 -0
- package/lib/src/auth.js +35 -9
- package/lib/src/auth.js.map +1 -1
- package/lib/src/auth.spec.js +76 -1
- package/lib/src/auth.spec.js.map +1 -1
- package/lib/src/embed/app.spec.js +4 -3
- package/lib/src/embed/app.spec.js.map +1 -1
- package/lib/src/embed/base.d.ts +34 -4
- package/lib/src/embed/base.js +79 -11
- package/lib/src/embed/base.js.map +1 -1
- package/lib/src/embed/base.spec.js +50 -2
- 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/liveboard.spec.js +4 -3
- package/lib/src/embed/liveboard.spec.js.map +1 -1
- package/lib/src/embed/pinboard.spec.js +4 -3
- package/lib/src/embed/pinboard.spec.js.map +1 -1
- package/lib/src/embed/search.d.ts +4 -0
- package/lib/src/embed/search.js +1 -1
- package/lib/src/embed/search.js.map +1 -1
- package/lib/src/embed/search.spec.js +6 -1
- package/lib/src/embed/search.spec.js.map +1 -1
- package/lib/src/embed/ts-embed.d.ts +2 -2
- package/lib/src/embed/ts-embed.js +11 -20
- package/lib/src/embed/ts-embed.js.map +1 -1
- package/lib/src/embed/ts-embed.spec.js +1 -1
- package/lib/src/embed/ts-embed.spec.js.map +1 -1
- package/lib/src/index.d.ts +3 -2
- package/lib/src/index.js +3 -2
- package/lib/src/index.js.map +1 -1
- package/lib/src/react/index.spec.js +2 -2
- package/lib/src/react/index.spec.js.map +1 -1
- package/lib/src/types.d.ts +32 -1
- package/lib/src/types.js +14 -0
- package/lib/src/types.js.map +1 -1
- package/lib/src/utils/authService.d.ts +1 -0
- package/lib/src/utils/authService.js +12 -2
- 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.d.ts +1 -1
- package/lib/src/utils/processData.js +37 -3
- package/lib/src/utils/processData.js.map +1 -1
- package/lib/src/utils/processData.spec.js +106 -4
- package/lib/src/utils/processData.spec.js.map +1 -1
- package/lib/src/utils.d.ts +1 -0
- package/lib/src/utils.js +4 -0
- package/lib/src/utils.js.map +1 -1
- package/lib/src/utils.spec.js +14 -1
- package/lib/src/utils.spec.js.map +1 -1
- package/lib/src/visual-embed-sdk.d.ts +135 -8
- package/package.json +3 -2
- package/src/auth.spec.ts +98 -2
- package/src/auth.ts +44 -7
- package/src/embed/app.spec.ts +4 -3
- package/src/embed/base.spec.ts +57 -3
- package/src/embed/base.ts +96 -15
- package/src/embed/embed.spec.ts +1 -1
- package/src/embed/liveboard.spec.ts +4 -3
- package/src/embed/pinboard.spec.ts +4 -3
- package/src/embed/search.spec.ts +6 -1
- package/src/embed/search.ts +5 -0
- package/src/embed/ts-embed.spec.ts +1 -1
- package/src/embed/ts-embed.ts +17 -23
- package/src/index.ts +5 -1
- package/src/react/index.spec.tsx +3 -2
- package/src/types.ts +32 -0
- package/src/utils/authService.spec.ts +13 -0
- package/src/utils/authService.ts +14 -2
- package/src/utils/processData.spec.ts +139 -4
- package/src/utils/processData.ts +54 -4
- package/src/utils.spec.ts +26 -0
- package/src/utils.ts +5 -0
- package/dist/src/embed/pinboard.d.ts +0 -91
- package/dist/src/utils/plugin.d.ts +0 -0
- package/dist/src/v1/api.d.ts +0 -19
- package/lib/src/embed/pinboard.d.ts +0 -91
- package/lib/src/embed/pinboard.js +0 -110
- package/lib/src/embed/pinboard.js.map +0 -1
- package/lib/src/utils/plugin.d.ts +0 -0
- package/lib/src/utils/plugin.js +0 -1
- package/lib/src/utils/plugin.js.map +0 -1
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
// Generated by dts-bundle v0.7.3
|
|
2
|
+
// Dependencies for this module:
|
|
3
|
+
// ../../eventemitter3
|
|
2
4
|
|
|
3
5
|
declare module '@thoughtspot/visual-embed-sdk' {
|
|
4
6
|
/**
|
|
@@ -11,11 +13,12 @@ declare module '@thoughtspot/visual-embed-sdk' {
|
|
|
11
13
|
* @author Ayon Ghosh <ayon.ghosh@thoughtspot.com>
|
|
12
14
|
*/
|
|
13
15
|
import { AppEmbed, Page, AppViewConfig } from '@thoughtspot/visual-embed-sdk/embed/app';
|
|
14
|
-
import { init, prefetch } from '@thoughtspot/visual-embed-sdk/embed/base';
|
|
16
|
+
import { init, prefetch, logout } from '@thoughtspot/visual-embed-sdk/embed/base';
|
|
15
17
|
import { PinboardEmbed, LiveboardViewConfig, LiveboardEmbed } from '@thoughtspot/visual-embed-sdk/embed/liveboard';
|
|
16
18
|
import { SearchEmbed, SearchViewConfig } from '@thoughtspot/visual-embed-sdk/embed/search';
|
|
19
|
+
import { AuthFailureType, AuthStatus } from '@thoughtspot/visual-embed-sdk/auth';
|
|
17
20
|
import { AuthType, RuntimeFilter, RuntimeFilterOp, EmbedEvent, HostEvent, DataSourceVisualMode, Action, EmbedConfig } from '@thoughtspot/visual-embed-sdk/types';
|
|
18
|
-
export { init, 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, };
|
|
19
22
|
}
|
|
20
23
|
|
|
21
24
|
declare module '@thoughtspot/visual-embed-sdk/embed/app' {
|
|
@@ -134,14 +137,27 @@ declare module '@thoughtspot/visual-embed-sdk/embed/app' {
|
|
|
134
137
|
}
|
|
135
138
|
|
|
136
139
|
declare module '@thoughtspot/visual-embed-sdk/embed/base' {
|
|
140
|
+
/**
|
|
141
|
+
* Copyright (c) 2022
|
|
142
|
+
*
|
|
143
|
+
* Base classes
|
|
144
|
+
*
|
|
145
|
+
* @summary Base classes
|
|
146
|
+
* @author Ayon Ghosh <ayon.ghosh@thoughtspot.com>
|
|
147
|
+
*/
|
|
148
|
+
import EventEmitter from 'eventemitter3';
|
|
137
149
|
import { EmbedConfig } from '@thoughtspot/visual-embed-sdk/types';
|
|
150
|
+
import { AuthFailureType } from '@thoughtspot/visual-embed-sdk/auth';
|
|
138
151
|
export let authPromise: Promise<boolean>;
|
|
152
|
+
export const getEmbedConfig: () => EmbedConfig;
|
|
153
|
+
export const getAuthPromise: () => Promise<boolean>;
|
|
154
|
+
export function notifyAuthSuccess(): void;
|
|
155
|
+
export function notifyAuthFailure(failureType: AuthFailureType): void;
|
|
156
|
+
export function notifyLogout(): void;
|
|
139
157
|
/**
|
|
140
158
|
* Perform authentication on the ThoughtSpot app as applicable.
|
|
141
159
|
*/
|
|
142
160
|
export const handleAuth: () => Promise<boolean>;
|
|
143
|
-
export const getEmbedConfig: () => EmbedConfig;
|
|
144
|
-
export const getAuthPromise: () => Promise<boolean>;
|
|
145
161
|
/**
|
|
146
162
|
* Prefetches static resources from the specified URL. Web browsers can then cache the prefetched resources and serve them from the user's local disk to provide faster access to your app.
|
|
147
163
|
* @param url The URL provided for prefetch
|
|
@@ -153,14 +169,31 @@ declare module '@thoughtspot/visual-embed-sdk/embed/base' {
|
|
|
153
169
|
* @param embedConfig The configuration object containing ThoughtSpot host,
|
|
154
170
|
* authentication mechanism and so on.
|
|
155
171
|
*
|
|
156
|
-
*
|
|
172
|
+
* eg: authStatus = init(config);
|
|
173
|
+
* authStatus.on(AuthStatus.FAILURE, (reason) => { // do something here });
|
|
174
|
+
*
|
|
175
|
+
* @returns event emitter which emits events on authentication success, failure and logout. {@link AuthStatus}
|
|
157
176
|
*/
|
|
158
|
-
export const init: (embedConfig: EmbedConfig) =>
|
|
177
|
+
export const init: (embedConfig: EmbedConfig) => EventEmitter;
|
|
178
|
+
export function disableAutoLogin(): void;
|
|
179
|
+
/**
|
|
180
|
+
* Logout from ThoughtSpot. This also sets the autoLogin flag to false, to prevent
|
|
181
|
+
* the SDK from automatically logging in again.
|
|
182
|
+
*
|
|
183
|
+
* You can call the `init` method again to re login, if autoLogin is set to true in this
|
|
184
|
+
* second call it will be honored.
|
|
185
|
+
*
|
|
186
|
+
* @param doNotDisableAutoLogin This flag when passed will not disable autoLogin
|
|
187
|
+
* @returns Promise which resolves when logout completes.
|
|
188
|
+
* @version SDK: 1.10.1 | ThoughtSpot: *
|
|
189
|
+
*/
|
|
190
|
+
export const logout: (doNotDisableAutoLogin?: boolean) => Promise<boolean>;
|
|
159
191
|
/**
|
|
160
192
|
* Renders functions in a queue, resolves to next function only after the callback next is called
|
|
161
193
|
* @param fn The function being registered
|
|
162
194
|
*/
|
|
163
195
|
export const renderInQueue: (fn: (next?: (val?: any) => void) => void) => void;
|
|
196
|
+
export function reset(): void;
|
|
164
197
|
}
|
|
165
198
|
|
|
166
199
|
declare module '@thoughtspot/visual-embed-sdk/embed/liveboard' {
|
|
@@ -306,6 +339,10 @@ declare module '@thoughtspot/visual-embed-sdk/embed/search' {
|
|
|
306
339
|
* using raw answer data.
|
|
307
340
|
*/
|
|
308
341
|
hideResults?: boolean;
|
|
342
|
+
/**
|
|
343
|
+
* If set to true, expands all the data sources panel.
|
|
344
|
+
*/
|
|
345
|
+
expandAllDataSource?: boolean;
|
|
309
346
|
/**
|
|
310
347
|
* If set to true, the Search Assist feature is enabled.
|
|
311
348
|
*/
|
|
@@ -353,6 +390,65 @@ declare module '@thoughtspot/visual-embed-sdk/embed/search' {
|
|
|
353
390
|
export {};
|
|
354
391
|
}
|
|
355
392
|
|
|
393
|
+
declare module '@thoughtspot/visual-embed-sdk/auth' {
|
|
394
|
+
import { EmbedConfig } from '@thoughtspot/visual-embed-sdk/types';
|
|
395
|
+
export let loggedInStatus: boolean;
|
|
396
|
+
export let samlAuthWindow: Window;
|
|
397
|
+
export let samlCompletionPromise: Promise<void>;
|
|
398
|
+
export let sessionInfo: any;
|
|
399
|
+
export const SSO_REDIRECTION_MARKER_GUID = "5e16222e-ef02-43e9-9fbd-24226bf3ce5b";
|
|
400
|
+
export const EndPoints: {
|
|
401
|
+
AUTH_VERIFICATION: string;
|
|
402
|
+
SAML_LOGIN_TEMPLATE: (targetUrl: string) => string;
|
|
403
|
+
OIDC_LOGIN_TEMPLATE: (targetUrl: string) => string;
|
|
404
|
+
TOKEN_LOGIN: string;
|
|
405
|
+
BASIC_LOGIN: string;
|
|
406
|
+
LOGOUT: string;
|
|
407
|
+
};
|
|
408
|
+
export enum AuthFailureType {
|
|
409
|
+
SDK = "SDK",
|
|
410
|
+
NO_COOKIE_ACCESS = "NO_COOKIE_ACCESS",
|
|
411
|
+
EXPIRY = "EXPIRY",
|
|
412
|
+
OTHER = "OTHER"
|
|
413
|
+
}
|
|
414
|
+
export enum AuthStatus {
|
|
415
|
+
FAILURE = "FAILURE",
|
|
416
|
+
SUCCESS = "SUCCESS",
|
|
417
|
+
LOGOUT = "LOGOUT"
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Return sessionInfo if available else make a loggedIn check to fetch the sessionInfo
|
|
421
|
+
*/
|
|
422
|
+
export function getSessionInfo(): any;
|
|
423
|
+
export function initSession(sessionDetails: any): void;
|
|
424
|
+
/**
|
|
425
|
+
* Perform token based authentication
|
|
426
|
+
* @param embedConfig The embed configuration
|
|
427
|
+
*/
|
|
428
|
+
export const doTokenAuth: (embedConfig: EmbedConfig) => Promise<boolean>;
|
|
429
|
+
/**
|
|
430
|
+
* Perform basic authentication to the ThoughtSpot cluster using the cluster
|
|
431
|
+
* credentials.
|
|
432
|
+
*
|
|
433
|
+
* Warning: This feature is primarily intended for developer testing. It is
|
|
434
|
+
* strongly advised not to use this authentication method in production.
|
|
435
|
+
* @param embedConfig The embed configuration
|
|
436
|
+
*/
|
|
437
|
+
export const doBasicAuth: (embedConfig: EmbedConfig) => Promise<boolean>;
|
|
438
|
+
export const doSamlAuth: (embedConfig: EmbedConfig) => Promise<boolean>;
|
|
439
|
+
export const doOIDCAuth: (embedConfig: EmbedConfig) => Promise<boolean>;
|
|
440
|
+
export const logout: (embedConfig: EmbedConfig) => Promise<boolean>;
|
|
441
|
+
/**
|
|
442
|
+
* Perform authentication on the ThoughtSpot cluster
|
|
443
|
+
* @param embedConfig The embed configuration
|
|
444
|
+
*/
|
|
445
|
+
export const authenticate: (embedConfig: EmbedConfig) => Promise<boolean>;
|
|
446
|
+
/**
|
|
447
|
+
* Check if we are authenticated to the ThoughtSpot cluster
|
|
448
|
+
*/
|
|
449
|
+
export const isAuthenticated: () => boolean;
|
|
450
|
+
}
|
|
451
|
+
|
|
356
452
|
declare module '@thoughtspot/visual-embed-sdk/types' {
|
|
357
453
|
/**
|
|
358
454
|
* The authentication mechanism for allowing access to the
|
|
@@ -438,6 +534,15 @@ declare module '@thoughtspot/visual-embed-sdk/types' {
|
|
|
438
534
|
* @default false
|
|
439
535
|
*/
|
|
440
536
|
noRedirect?: boolean;
|
|
537
|
+
/**
|
|
538
|
+
* [SSO] For SSO Authentication, one can supply an optional path param,
|
|
539
|
+
* this will be the path on the host origin where the SAML flow will be
|
|
540
|
+
* terminated.
|
|
541
|
+
*
|
|
542
|
+
* Eg: "/dashboard", "#/foo" [Do not include the host]
|
|
543
|
+
* @version SDK: 1.10.2 | ThoughtSpot: *
|
|
544
|
+
*/
|
|
545
|
+
redirectPath?: string;
|
|
441
546
|
/** @internal */
|
|
442
547
|
basepath?: string;
|
|
443
548
|
/**
|
|
@@ -492,6 +597,14 @@ declare module '@thoughtspot/visual-embed-sdk/types' {
|
|
|
492
597
|
* @default ''
|
|
493
598
|
*/
|
|
494
599
|
customCssUrl?: string;
|
|
600
|
+
/**
|
|
601
|
+
* [AuthServer|Basic] Detect if 3rd party cookies are enabled by doing an additional call. This is slower
|
|
602
|
+
* and should be avoided. Listen to the NO_COOKIE_ACCESS event to handle the situation.
|
|
603
|
+
*
|
|
604
|
+
* This is slightly slower than letting the browser handle the cookie check, as it involves an extra network call.
|
|
605
|
+
* @version SDK: 1.10.4 | ThoughtSpot: *
|
|
606
|
+
*/
|
|
607
|
+
detectCookieAccessSlow?: boolean;
|
|
495
608
|
}
|
|
496
609
|
/**
|
|
497
610
|
* MessagePayload: Embed event payload: message type, data and status (start/end)
|
|
@@ -685,6 +798,16 @@ declare module '@thoughtspot/visual-embed-sdk/types' {
|
|
|
685
798
|
* The ThoughtSpot auth session has expired.
|
|
686
799
|
*/
|
|
687
800
|
AuthExpire = "ThoughtspotAuthExpired",
|
|
801
|
+
/**
|
|
802
|
+
* ThoughtSpot failed to validate the auth session.
|
|
803
|
+
* @hidden
|
|
804
|
+
*/
|
|
805
|
+
AuthFailure = "ThoughtspotAuthFailure",
|
|
806
|
+
/**
|
|
807
|
+
* ThoughtSpot failed to validate the auth session.
|
|
808
|
+
* @hidden
|
|
809
|
+
*/
|
|
810
|
+
AuthLogout = "ThoughtspotAuthLogout",
|
|
688
811
|
/**
|
|
689
812
|
* The height of the embedded Liveboard or visualization has been computed.
|
|
690
813
|
* @return data - The height of the embedded Liveboard or visualization
|
|
@@ -1085,7 +1208,11 @@ declare module '@thoughtspot/visual-embed-sdk/types' {
|
|
|
1085
1208
|
/**
|
|
1086
1209
|
* @version SDK: 1.11.0 | ThoughtSpot: 8.3.0.cl
|
|
1087
1210
|
*/
|
|
1088
|
-
CreateMonitor = "createMonitor"
|
|
1211
|
+
CreateMonitor = "createMonitor",
|
|
1212
|
+
/**
|
|
1213
|
+
* @version SDK: 1.11.1 | ThoughtSpot: 8.3.0.cl
|
|
1214
|
+
*/
|
|
1215
|
+
ReportError = "reportError"
|
|
1089
1216
|
}
|
|
1090
1217
|
export interface SessionInterface {
|
|
1091
1218
|
sessionId: string;
|
|
@@ -1136,7 +1263,7 @@ declare module '@thoughtspot/visual-embed-sdk/embed/ts-embed' {
|
|
|
1136
1263
|
* This parameters will be passed on the iframe
|
|
1137
1264
|
* as is.
|
|
1138
1265
|
*/
|
|
1139
|
-
[key: string]: string | number | boolean;
|
|
1266
|
+
[key: string]: string | number | boolean | undefined;
|
|
1140
1267
|
}
|
|
1141
1268
|
/**
|
|
1142
1269
|
* The configuration object for an embedded view.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thoughtspot/visual-embed-sdk",
|
|
3
|
-
"version": "1.11.
|
|
3
|
+
"version": "1.11.2",
|
|
4
4
|
"description": "ThoughtSpot Embed SDK",
|
|
5
5
|
"module": "lib/src/index.js",
|
|
6
6
|
"main": "dist/tsembed.js",
|
|
@@ -44,7 +44,8 @@
|
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"algoliasearch": "^4.10.5",
|
|
46
46
|
"classnames": "^2.3.1",
|
|
47
|
-
"
|
|
47
|
+
"eventemitter3": "^4.0.7",
|
|
48
|
+
"mixpanel-browser": "^2.45.0"
|
|
48
49
|
},
|
|
49
50
|
"devDependencies": {
|
|
50
51
|
"@mdx-js/mdx": "^1.6.22",
|
package/src/auth.spec.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as authInstance from './auth';
|
|
2
2
|
import * as authService from './utils/authService';
|
|
3
|
-
import { AuthType } from './types';
|
|
3
|
+
import { AuthType, EmbedConfig } from './types';
|
|
4
4
|
import { executeAfterWait } from './test/test-utils';
|
|
5
5
|
|
|
6
6
|
const thoughtSpotHost = 'http://localhost:3000';
|
|
@@ -13,8 +13,15 @@ const embedConfig: any = {
|
|
|
13
13
|
thoughtSpotHost,
|
|
14
14
|
username,
|
|
15
15
|
authEndpoint: 'auth',
|
|
16
|
+
authType: AuthType.AuthServer,
|
|
16
17
|
getAuthToken: jest.fn(() => Promise.resolve(token)),
|
|
17
18
|
}),
|
|
19
|
+
doTokenAuthWithCookieDetect: {
|
|
20
|
+
thoughtSpotHost,
|
|
21
|
+
username,
|
|
22
|
+
authEndpoint: 'auth',
|
|
23
|
+
detectCookieAccessSlow: true,
|
|
24
|
+
},
|
|
18
25
|
doTokenAuthFailureWithoutAuthEndPoint: {
|
|
19
26
|
thoughtSpotHost,
|
|
20
27
|
username,
|
|
@@ -35,9 +42,15 @@ const embedConfig: any = {
|
|
|
35
42
|
doSamlAuth: {
|
|
36
43
|
thoughtSpotHost,
|
|
37
44
|
},
|
|
45
|
+
doOidcAuth: {
|
|
46
|
+
thoughtSpotHost,
|
|
47
|
+
},
|
|
38
48
|
SSOAuth: {
|
|
39
49
|
authType: AuthType.SSO,
|
|
40
50
|
},
|
|
51
|
+
OIDCAuth: {
|
|
52
|
+
authType: AuthType.OIDC,
|
|
53
|
+
},
|
|
41
54
|
authServerFailure: {
|
|
42
55
|
thoughtSpotHost,
|
|
43
56
|
username,
|
|
@@ -168,6 +181,61 @@ describe('Unit test for auth', () => {
|
|
|
168
181
|
});
|
|
169
182
|
});
|
|
170
183
|
|
|
184
|
+
test('doTokenAuth: Should raise error when duplicate token is used', async () => {
|
|
185
|
+
jest.spyOn(authService, 'fetchSessionInfoService').mockResolvedValue({
|
|
186
|
+
status: 401,
|
|
187
|
+
});
|
|
188
|
+
jest.spyOn(window, 'alert').mockClear();
|
|
189
|
+
jest.spyOn(window, 'alert').mockReturnValue(undefined);
|
|
190
|
+
jest.spyOn(authService, 'fetchAuthService').mockReset();
|
|
191
|
+
jest.spyOn(authService, 'fetchAuthService').mockImplementation(() =>
|
|
192
|
+
Promise.resolve({
|
|
193
|
+
status: 200,
|
|
194
|
+
ok: true,
|
|
195
|
+
}),
|
|
196
|
+
);
|
|
197
|
+
await authInstance.doTokenAuth(
|
|
198
|
+
embedConfig.doTokenAuthSuccess('authToken3'),
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
try {
|
|
202
|
+
await authInstance.doTokenAuth(
|
|
203
|
+
embedConfig.doTokenAuthSuccess('authToken3'),
|
|
204
|
+
);
|
|
205
|
+
expect(false).toBe(true);
|
|
206
|
+
} catch (e) {
|
|
207
|
+
expect(e.message).toContain('Duplicate token');
|
|
208
|
+
}
|
|
209
|
+
await executeAfterWait(() => {
|
|
210
|
+
expect(authInstance.loggedInStatus).toBe(false);
|
|
211
|
+
expect(window.alert).toBeCalled();
|
|
212
|
+
expect(authService.fetchAuthService).toHaveBeenCalledTimes(1);
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
test('doTokenAuth: Should set loggedInStatus if detectThirdPartyCookieAccess is true and the second info call fails', async () => {
|
|
217
|
+
jest.spyOn(authService, 'fetchSessionInfoService')
|
|
218
|
+
.mockResolvedValue({
|
|
219
|
+
status: 401,
|
|
220
|
+
})
|
|
221
|
+
.mockClear();
|
|
222
|
+
jest.spyOn(
|
|
223
|
+
authService,
|
|
224
|
+
'fetchAuthTokenService',
|
|
225
|
+
).mockImplementation(() => ({ text: () => Promise.resolve('abc') }));
|
|
226
|
+
jest.spyOn(authService, 'fetchAuthService').mockImplementation(() =>
|
|
227
|
+
Promise.resolve({
|
|
228
|
+
status: 200,
|
|
229
|
+
ok: true,
|
|
230
|
+
}),
|
|
231
|
+
);
|
|
232
|
+
const isLoggedIn = await authInstance.doTokenAuth(
|
|
233
|
+
embedConfig.doTokenAuthWithCookieDetect,
|
|
234
|
+
);
|
|
235
|
+
expect(authService.fetchSessionInfoService).toHaveBeenCalledTimes(2);
|
|
236
|
+
expect(isLoggedIn).toBe(false);
|
|
237
|
+
});
|
|
238
|
+
|
|
171
239
|
describe('doBasicAuth', () => {
|
|
172
240
|
beforeEach(() => {
|
|
173
241
|
global.fetch = window.fetch;
|
|
@@ -266,6 +334,7 @@ describe('Unit test for auth', () => {
|
|
|
266
334
|
},
|
|
267
335
|
});
|
|
268
336
|
spyOn(authInstance, 'samlCompletionPromise');
|
|
337
|
+
global.window.open = jest.fn();
|
|
269
338
|
jest.spyOn(
|
|
270
339
|
authService,
|
|
271
340
|
'fetchSessionInfoService',
|
|
@@ -276,11 +345,31 @@ describe('Unit test for auth', () => {
|
|
|
276
345
|
...embedConfig.doSamlAuth,
|
|
277
346
|
noRedirect: true,
|
|
278
347
|
}),
|
|
279
|
-
).toBe(
|
|
348
|
+
).toBe(true);
|
|
280
349
|
expect(authService.fetchSessionInfoService).toBeCalled();
|
|
281
350
|
});
|
|
282
351
|
});
|
|
283
352
|
|
|
353
|
+
describe('doOIDCAuth', () => {
|
|
354
|
+
afterEach(() => {
|
|
355
|
+
delete global.window;
|
|
356
|
+
global.window = Object.create(originalWindow);
|
|
357
|
+
global.window.open = jest.fn();
|
|
358
|
+
global.fetch = window.fetch;
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
it('when user is not loggedIn & isAtSSORedirectUrl is true', async () => {
|
|
362
|
+
jest.spyOn(
|
|
363
|
+
authService,
|
|
364
|
+
'fetchSessionInfoService',
|
|
365
|
+
).mockImplementation(() => Promise.reject());
|
|
366
|
+
await authInstance.doOIDCAuth(embedConfig.doOidcAuth);
|
|
367
|
+
expect(authService.fetchSessionInfoService).toBeCalled();
|
|
368
|
+
expect(window.location.hash).toBe('');
|
|
369
|
+
expect(authInstance.loggedInStatus).toBe(false);
|
|
370
|
+
});
|
|
371
|
+
});
|
|
372
|
+
|
|
284
373
|
it('authenticate: when authType is SSO', async () => {
|
|
285
374
|
jest.spyOn(authInstance, 'doSamlAuth');
|
|
286
375
|
await authInstance.authenticate(embedConfig.SSOAuth);
|
|
@@ -288,6 +377,13 @@ describe('Unit test for auth', () => {
|
|
|
288
377
|
expect(authInstance.doSamlAuth).toBeCalled();
|
|
289
378
|
});
|
|
290
379
|
|
|
380
|
+
it('authenticate: when authType is OIDC', async () => {
|
|
381
|
+
jest.spyOn(authInstance, 'doOIDCAuth');
|
|
382
|
+
await authInstance.authenticate(embedConfig.OIDCAuth);
|
|
383
|
+
expect(window.location.hash).toBe('');
|
|
384
|
+
expect(authInstance.doOIDCAuth).toBeCalled();
|
|
385
|
+
});
|
|
386
|
+
|
|
291
387
|
it('authenticate: when authType is AuthServer', async () => {
|
|
292
388
|
spyOn(authInstance, 'doTokenAuth');
|
|
293
389
|
await authInstance.authenticate(embedConfig.authServerFailure);
|
package/src/auth.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { initMixpanel } from './mixpanel-service';
|
|
2
2
|
import { AuthType, EmbedConfig, EmbedEvent } from './types';
|
|
3
|
-
import {
|
|
3
|
+
import { getRedirectUrl } from './utils';
|
|
4
4
|
// eslint-disable-next-line import/no-cycle
|
|
5
5
|
import {
|
|
6
6
|
fetchSessionInfoService,
|
|
7
7
|
fetchAuthTokenService,
|
|
8
8
|
fetchAuthService,
|
|
9
9
|
fetchBasicAuthService,
|
|
10
|
+
fetchLogoutService,
|
|
10
11
|
} from './utils/authService';
|
|
11
12
|
|
|
12
13
|
// eslint-disable-next-line import/no-mutable-exports
|
|
@@ -29,8 +30,22 @@ export const EndPoints = {
|
|
|
29
30
|
`/callosum/v1/oidc/login?targetURLPath=${targetUrl}`,
|
|
30
31
|
TOKEN_LOGIN: '/callosum/v1/session/login/token',
|
|
31
32
|
BASIC_LOGIN: '/callosum/v1/session/login',
|
|
33
|
+
LOGOUT: '/callosum/v1/session/logout',
|
|
32
34
|
};
|
|
33
35
|
|
|
36
|
+
export enum AuthFailureType {
|
|
37
|
+
SDK = 'SDK',
|
|
38
|
+
NO_COOKIE_ACCESS = 'NO_COOKIE_ACCESS',
|
|
39
|
+
EXPIRY = 'EXPIRY',
|
|
40
|
+
OTHER = 'OTHER',
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export enum AuthStatus {
|
|
44
|
+
FAILURE = 'FAILURE',
|
|
45
|
+
SUCCESS = 'SUCCESS',
|
|
46
|
+
LOGOUT = 'LOGOUT',
|
|
47
|
+
}
|
|
48
|
+
|
|
34
49
|
/**
|
|
35
50
|
* Check if we are logged into the ThoughtSpot cluster
|
|
36
51
|
* @param thoughtSpotHost The ThoughtSpot cluster hostname or IP
|
|
@@ -110,8 +125,8 @@ export const doTokenAuth = async (
|
|
|
110
125
|
'Either auth endpoint or getAuthToken function must be provided',
|
|
111
126
|
);
|
|
112
127
|
}
|
|
113
|
-
|
|
114
|
-
if (!
|
|
128
|
+
loggedInStatus = await isLoggedIn(thoughtSpotHost);
|
|
129
|
+
if (!loggedInStatus) {
|
|
115
130
|
let authToken = null;
|
|
116
131
|
if (getAuthToken) {
|
|
117
132
|
authToken = await getAuthToken();
|
|
@@ -127,8 +142,11 @@ export const doTokenAuth = async (
|
|
|
127
142
|
);
|
|
128
143
|
// token login issues a 302 when successful
|
|
129
144
|
loggedInStatus = resp.ok || resp.type === 'opaqueredirect';
|
|
130
|
-
|
|
131
|
-
|
|
145
|
+
if (loggedInStatus && embedConfig.detectCookieAccessSlow) {
|
|
146
|
+
// When 3rd party cookie access is blocked, this will fail because cookies will
|
|
147
|
+
// not be sent with the call.
|
|
148
|
+
loggedInStatus = await isLoggedIn(thoughtSpotHost);
|
|
149
|
+
}
|
|
132
150
|
}
|
|
133
151
|
return loggedInStatus;
|
|
134
152
|
};
|
|
@@ -153,6 +171,9 @@ export const doBasicAuth = async (
|
|
|
153
171
|
password,
|
|
154
172
|
);
|
|
155
173
|
loggedInStatus = response.ok;
|
|
174
|
+
if (embedConfig.detectCookieAccessSlow) {
|
|
175
|
+
loggedInStatus = await isLoggedIn(thoughtSpotHost);
|
|
176
|
+
}
|
|
156
177
|
} else {
|
|
157
178
|
loggedInStatus = true;
|
|
158
179
|
}
|
|
@@ -223,6 +244,7 @@ const doSSOAuth = async (
|
|
|
223
244
|
const ssoURL = `${thoughtSpotHost}${ssoEndPoint}`;
|
|
224
245
|
if (embedConfig.noRedirect) {
|
|
225
246
|
await samlPopupFlow(ssoURL);
|
|
247
|
+
loggedInStatus = true;
|
|
226
248
|
return;
|
|
227
249
|
}
|
|
228
250
|
|
|
@@ -235,7 +257,11 @@ export const doSamlAuth = async (embedConfig: EmbedConfig) => {
|
|
|
235
257
|
// again and the same JS will execute again.
|
|
236
258
|
const ssoRedirectUrl = embedConfig.noRedirect
|
|
237
259
|
? `${thoughtSpotHost}/v2/#/embed/saml-complete`
|
|
238
|
-
:
|
|
260
|
+
: getRedirectUrl(
|
|
261
|
+
window.location.href,
|
|
262
|
+
SSO_REDIRECTION_MARKER_GUID,
|
|
263
|
+
embedConfig.redirectPath,
|
|
264
|
+
);
|
|
239
265
|
|
|
240
266
|
// bring back the page to the same URL
|
|
241
267
|
const ssoEndPoint = `${EndPoints.SAML_LOGIN_TEMPLATE(
|
|
@@ -252,7 +278,11 @@ export const doOIDCAuth = async (embedConfig: EmbedConfig) => {
|
|
|
252
278
|
// again and the same JS will execute again.
|
|
253
279
|
const ssoRedirectUrl = embedConfig.noRedirect
|
|
254
280
|
? `${thoughtSpotHost}/v2/#/embed/saml-complete`
|
|
255
|
-
:
|
|
281
|
+
: getRedirectUrl(
|
|
282
|
+
window.location.href,
|
|
283
|
+
SSO_REDIRECTION_MARKER_GUID,
|
|
284
|
+
embedConfig.redirectPath,
|
|
285
|
+
);
|
|
256
286
|
|
|
257
287
|
// bring back the page to the same URL
|
|
258
288
|
const ssoEndPoint = `${EndPoints.OIDC_LOGIN_TEMPLATE(
|
|
@@ -263,6 +293,13 @@ export const doOIDCAuth = async (embedConfig: EmbedConfig) => {
|
|
|
263
293
|
return loggedInStatus;
|
|
264
294
|
};
|
|
265
295
|
|
|
296
|
+
export const logout = async (embedConfig: EmbedConfig): Promise<boolean> => {
|
|
297
|
+
const { thoughtSpotHost } = embedConfig;
|
|
298
|
+
const response = await fetchLogoutService(thoughtSpotHost);
|
|
299
|
+
loggedInStatus = false;
|
|
300
|
+
return loggedInStatus;
|
|
301
|
+
};
|
|
302
|
+
|
|
266
303
|
/**
|
|
267
304
|
* Perform authentication on the ThoughtSpot cluster
|
|
268
305
|
* @param embedConfig The embed configuration
|
package/src/embed/app.spec.ts
CHANGED
|
@@ -18,8 +18,9 @@ const defaultViewConfig = {
|
|
|
18
18
|
},
|
|
19
19
|
};
|
|
20
20
|
const thoughtSpotHost = 'tshost';
|
|
21
|
-
const
|
|
22
|
-
const
|
|
21
|
+
const defaultParamsWithoutHiddenActions = `&hostAppUrl=local-host&viewPortHeight=768&viewPortWidth=1024&sdkVersion=${version}`;
|
|
22
|
+
const defaultParams = `${defaultParamsWithoutHiddenActions}&hideAction=[%22${Action.ReportError}%22]`;
|
|
23
|
+
const defaultParamsForPinboardEmbed = `hostAppUrl=local-host&viewPortHeight=768&viewPortWidth=1024&sdkVersion=${version}&hideAction=[%22${Action.ReportError}%22]`;
|
|
23
24
|
const defaultParamsPost = '&isPinboardV2Enabled=false';
|
|
24
25
|
|
|
25
26
|
beforeAll(() => {
|
|
@@ -154,7 +155,7 @@ describe('App embed tests', () => {
|
|
|
154
155
|
appEmbed.render();
|
|
155
156
|
await executeAfterWait(() => {
|
|
156
157
|
expect(getIFrameSrc()).toBe(
|
|
157
|
-
`http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=false&profileAndHelpInNavBarHidden=false${
|
|
158
|
+
`http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=false&profileAndHelpInNavBarHidden=false${defaultParamsWithoutHiddenActions}&disableAction=[%22save%22,%22update%22]&disableHint=Access%20denied&hideAction=[%22${Action.ReportError}%22,%22download%22]${defaultParamsPost}#/home`,
|
|
158
159
|
);
|
|
159
160
|
});
|
|
160
161
|
});
|
package/src/embed/base.spec.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import EventEmitter from 'eventemitter3';
|
|
2
|
+
import * as auth from '../auth';
|
|
1
3
|
import * as index from '../index';
|
|
4
|
+
import * as base from './base';
|
|
2
5
|
import {
|
|
3
6
|
executeAfterWait,
|
|
4
7
|
getAllIframeEl,
|
|
@@ -9,10 +12,11 @@ import {
|
|
|
9
12
|
} from '../test/test-utils';
|
|
10
13
|
|
|
11
14
|
const thoughtSpotHost = 'tshost';
|
|
15
|
+
let authEE: EventEmitter;
|
|
12
16
|
|
|
13
17
|
describe('Base TS Embed', () => {
|
|
14
18
|
beforeAll(() => {
|
|
15
|
-
index.init({
|
|
19
|
+
authEE = index.init({
|
|
16
20
|
thoughtSpotHost,
|
|
17
21
|
authType: index.AuthType.None,
|
|
18
22
|
});
|
|
@@ -38,8 +42,10 @@ describe('Base TS Embed', () => {
|
|
|
38
42
|
},
|
|
39
43
|
'*',
|
|
40
44
|
);
|
|
41
|
-
|
|
42
|
-
jest.spyOn(window, 'alert').mockImplementation(() =>
|
|
45
|
+
jest.spyOn(window, 'alert').mockReset();
|
|
46
|
+
jest.spyOn(window, 'alert').mockImplementation(() => undefined);
|
|
47
|
+
authEE.on(auth.AuthStatus.FAILURE, (reason) => {
|
|
48
|
+
expect(reason).toEqual(auth.AuthFailureType.NO_COOKIE_ACCESS);
|
|
43
49
|
expect(window.alert).toBeCalledWith(
|
|
44
50
|
'Third party cookie access is blocked on this browser, please allow third party cookies for this to work properly. \nYou can use `suppressNoCookieAccessAlert` to suppress this message.',
|
|
45
51
|
);
|
|
@@ -92,4 +98,52 @@ describe('Base TS Embed', () => {
|
|
|
92
98
|
expect(getIFrameSrc()).toContain('disableLoginRedirect=true');
|
|
93
99
|
});
|
|
94
100
|
});
|
|
101
|
+
|
|
102
|
+
test('handleAuth notifies for SDK auth failure', (done) => {
|
|
103
|
+
jest.spyOn(auth, 'authenticate').mockResolvedValue(false);
|
|
104
|
+
const authEmitter = index.init({
|
|
105
|
+
thoughtSpotHost,
|
|
106
|
+
authType: index.AuthType.Basic,
|
|
107
|
+
username: 'test',
|
|
108
|
+
password: 'test',
|
|
109
|
+
});
|
|
110
|
+
authEmitter.on(auth.AuthStatus.FAILURE, (reason) => {
|
|
111
|
+
expect(reason).toBe(auth.AuthFailureType.SDK);
|
|
112
|
+
done();
|
|
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
|
+
headers: {
|
|
131
|
+
'x-requested-by': 'ThoughtSpot',
|
|
132
|
+
},
|
|
133
|
+
method: 'POST',
|
|
134
|
+
},
|
|
135
|
+
);
|
|
136
|
+
expect(base.getEmbedConfig().autoLogin).toBe(false);
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
describe('Base without init', () => {
|
|
141
|
+
test('notify should error when called without init', () => {
|
|
142
|
+
base.reset();
|
|
143
|
+
jest.spyOn(global.console, 'error').mockImplementation(() => undefined);
|
|
144
|
+
base.notifyAuthSuccess();
|
|
145
|
+
base.notifyAuthFailure(auth.AuthFailureType.SDK);
|
|
146
|
+
base.notifyLogout();
|
|
147
|
+
expect(global.console.error).toHaveBeenCalledTimes(3);
|
|
148
|
+
});
|
|
95
149
|
});
|