@sisense/sdk-rest-client 1.2.0 → 1.3.0
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/authenticator.d.ts +1 -1
- package/dist/authenticator.js +2 -2
- package/dist/sso-authenticator.d.ts +5 -2
- package/dist/sso-authenticator.js +50 -20
- package/dist/translation/resources/en.d.ts +1 -0
- package/dist/translation/resources/en.js +2 -1
- package/dist/translation/resources/index.d.ts +2 -0
- package/dist/translation/resources/uk.js +1 -0
- package/package.json +2 -2
package/dist/authenticator.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Authenticator } from './interfaces.js';
|
|
2
|
-
export declare function getAuthenticator(url: string, username: string | undefined, password: string | undefined, token: string | undefined, wat: string | undefined, ssoEnabled: boolean | undefined): Authenticator | null;
|
|
2
|
+
export declare function getAuthenticator(url: string, username: string | undefined, password: string | undefined, token: string | undefined, wat: string | undefined, ssoEnabled: boolean | undefined, enableSilentPreAuth?: boolean): Authenticator | null;
|
package/dist/authenticator.js
CHANGED
|
@@ -2,10 +2,10 @@ import { PasswordAuthenticator } from './password-authenticator.js';
|
|
|
2
2
|
import { BearerAuthenticator } from './bearer-authenticator.js';
|
|
3
3
|
import { WatAuthenticator } from './wat-authenticator.js';
|
|
4
4
|
import { SsoAuthenticator } from './sso-authenticator.js';
|
|
5
|
-
export function getAuthenticator(url, username, password, token, wat, ssoEnabled) {
|
|
5
|
+
export function getAuthenticator(url, username, password, token, wat, ssoEnabled, enableSilentPreAuth = false) {
|
|
6
6
|
// sso overrides all other auth methods
|
|
7
7
|
if (ssoEnabled) {
|
|
8
|
-
return new SsoAuthenticator(url);
|
|
8
|
+
return new SsoAuthenticator(url, enableSilentPreAuth);
|
|
9
9
|
}
|
|
10
10
|
// username/password or tokens are chosen relative to priority
|
|
11
11
|
if (username && password) {
|
|
@@ -2,12 +2,15 @@
|
|
|
2
2
|
import { Authenticator } from './interfaces.js';
|
|
3
3
|
export declare class SsoAuthenticator implements Authenticator {
|
|
4
4
|
readonly url: string;
|
|
5
|
+
private _enableSilentPreAuth;
|
|
5
6
|
private _valid;
|
|
6
7
|
private _authenticating;
|
|
7
|
-
constructor(url: string);
|
|
8
|
+
constructor(url: string, enableSilentPreAuth?: boolean);
|
|
8
9
|
isValid(): boolean;
|
|
9
10
|
invalidate(): void;
|
|
10
11
|
isAuthenticating(): boolean;
|
|
11
12
|
applyHeader(headers: HeadersInit): HeadersInit;
|
|
12
|
-
|
|
13
|
+
private authenticateSilent;
|
|
14
|
+
private checkAuthentication;
|
|
15
|
+
authenticate(silent?: boolean): Promise<boolean>;
|
|
13
16
|
}
|
|
@@ -10,10 +10,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
import { TranslatableError } from './translation/translatable-error.js';
|
|
12
12
|
export class SsoAuthenticator {
|
|
13
|
-
constructor(url) {
|
|
13
|
+
constructor(url, enableSilentPreAuth = false) {
|
|
14
14
|
this._valid = true;
|
|
15
15
|
this._authenticating = false;
|
|
16
16
|
this.url = url;
|
|
17
|
+
this._enableSilentPreAuth = enableSilentPreAuth;
|
|
17
18
|
}
|
|
18
19
|
isValid() {
|
|
19
20
|
return this._valid;
|
|
@@ -27,31 +28,60 @@ export class SsoAuthenticator {
|
|
|
27
28
|
applyHeader(headers) {
|
|
28
29
|
return headers;
|
|
29
30
|
}
|
|
30
|
-
|
|
31
|
+
authenticateSilent(loginUrl) {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
const iframe = document.createElement('iframe');
|
|
34
|
+
iframe.style.display = 'none';
|
|
35
|
+
document.body.appendChild(iframe);
|
|
36
|
+
iframe.src = `${loginUrl}?return_to=${window.location.href}`;
|
|
37
|
+
yield new Promise((resolve) => {
|
|
38
|
+
iframe.onload = () => {
|
|
39
|
+
resolve(true);
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
document.body.removeChild(iframe);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
checkAuthentication() {
|
|
31
46
|
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
-
this._authenticating = true;
|
|
33
47
|
const fetchUrl = `${this.url}${!this.url.endsWith('/') ? '/' : ''}api/auth/isauth`;
|
|
34
|
-
|
|
48
|
+
const response = yield fetch(fetchUrl, {
|
|
35
49
|
headers: { Internal: 'true' },
|
|
36
50
|
credentials: 'include',
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
// SSO is disabled on instance, do not proceed
|
|
43
|
-
if (!res.ssoEnabled)
|
|
44
|
-
throw new TranslatableError('errors.ssoNotEnabled');
|
|
45
|
-
// redirect to login page
|
|
46
|
-
(_a = window === null || window === void 0 ? void 0 : window.location) === null || _a === void 0 ? void 0 : _a.assign(`${res.loginUrl}?return_to=${window.location.href}`);
|
|
47
|
-
return false;
|
|
51
|
+
});
|
|
52
|
+
const result = yield response.json();
|
|
53
|
+
if (!result.isAuthenticated) {
|
|
54
|
+
if (!result.ssoEnabled) {
|
|
55
|
+
throw new TranslatableError('errors.ssoNotEnabled');
|
|
48
56
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
this._authenticating = false;
|
|
52
|
-
return true;
|
|
57
|
+
if (!result.loginUrl) {
|
|
58
|
+
throw new TranslatableError('errors.ssoNoLoginUrl');
|
|
53
59
|
}
|
|
54
|
-
}
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
isAuthenticated: result.isAuthenticated,
|
|
63
|
+
loginUrl: `${result.loginUrl}?return_to=${window.location.href}`,
|
|
64
|
+
};
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
authenticate(silent = true) {
|
|
68
|
+
var _a;
|
|
69
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
this._authenticating = true;
|
|
71
|
+
const { isAuthenticated, loginUrl } = yield this.checkAuthentication();
|
|
72
|
+
if (!isAuthenticated) {
|
|
73
|
+
if (this._enableSilentPreAuth && silent) {
|
|
74
|
+
yield this.authenticateSilent(loginUrl);
|
|
75
|
+
return this.authenticate(false);
|
|
76
|
+
}
|
|
77
|
+
(_a = window === null || window === void 0 ? void 0 : window.location) === null || _a === void 0 ? void 0 : _a.assign(loginUrl);
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
// no authentication needed, indicate success
|
|
82
|
+
this._authenticating = false;
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
55
85
|
});
|
|
56
86
|
}
|
|
57
87
|
}
|
|
@@ -5,7 +5,8 @@ export const translation = {
|
|
|
5
5
|
errorPrefix: '[request-error]',
|
|
6
6
|
errors: {
|
|
7
7
|
networkError: "Network error. Probably you forgot to add your domain to 'CORS Allowed Origins' in Sisense Admin Panel -> Security Settings.",
|
|
8
|
-
ssoNotEnabled: 'SSO is not enabled on target instance, please choose another authentication method',
|
|
8
|
+
ssoNotEnabled: 'SSO is not enabled on target instance, please choose another authentication method.',
|
|
9
|
+
ssoNoLoginUrl: 'Can not fetch login URL on target instance. Check SSO settings.',
|
|
9
10
|
passwordAuthFailed: '$t(errorPrefix) Username and password authentication was not successful. Check credentials.',
|
|
10
11
|
tokenAuthFailed: '$t(errorPrefix) Token authentication was not successful. Check credentials.',
|
|
11
12
|
responseError_onlyStatus: '$t(errorPrefix) Status: {{status}}',
|
|
@@ -7,6 +7,7 @@ export declare const resources: {
|
|
|
7
7
|
errors: {
|
|
8
8
|
networkError: string;
|
|
9
9
|
ssoNotEnabled: string;
|
|
10
|
+
ssoNoLoginUrl: string;
|
|
10
11
|
passwordAuthFailed: string;
|
|
11
12
|
tokenAuthFailed: string;
|
|
12
13
|
responseError_onlyStatus: string;
|
|
@@ -18,6 +19,7 @@ export declare const resources: {
|
|
|
18
19
|
errors: {
|
|
19
20
|
networkError: string;
|
|
20
21
|
ssoNotEnabled: string;
|
|
22
|
+
ssoNoLoginUrl: string;
|
|
21
23
|
passwordAuthFailed: string;
|
|
22
24
|
tokenAuthFailed: string;
|
|
23
25
|
responseError_onlyStatus: string;
|
|
@@ -6,6 +6,7 @@ export const translation = {
|
|
|
6
6
|
errors: {
|
|
7
7
|
networkError: 'Помилка мережі. Можливо ви забули додати свій домен до «CORS Allowed Origins» в панелі адміністратора Sisense -> Security Settings.',
|
|
8
8
|
ssoNotEnabled: 'SSO не ввімкнено на цьому сервері, будь ласка, виберіть інший метод аутентифікації',
|
|
9
|
+
ssoNoLoginUrl: 'Неможливо отримати loginUrl з сервера. Перевірте налаштування SSO.',
|
|
9
10
|
passwordAuthFailed: '$t(errorPrefix) Помилка автентифікації за допомогою імені користувача та пароля. Перевірте дані для входу.',
|
|
10
11
|
tokenAuthFailed: '$t(errorPrefix) Помилка автентифікації за допомогою токена. Перевірте дані для входу.',
|
|
11
12
|
responseError_onlyStatus: '$t(errorPrefix) Статус: {{status}}',
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"Sisense",
|
|
12
12
|
"Compose SDK"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.
|
|
14
|
+
"version": "1.3.0",
|
|
15
15
|
"type": "module",
|
|
16
16
|
"exports": "./dist/index.js",
|
|
17
17
|
"main": "./dist/index.js",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"author": "Sisense",
|
|
21
21
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@sisense/sdk-common": "^1.
|
|
23
|
+
"@sisense/sdk-common": "^1.3.0",
|
|
24
24
|
"fetch-intercept": "^2.4.0"
|
|
25
25
|
},
|
|
26
26
|
"scripts": {
|