@jetbrains/ring-ui-built 6.0.31 → 6.0.32
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/components/_helpers/_rollupPluginBabelHelpers.js +1 -567
- package/components/_helpers/anchor.js +7 -6
- package/components/_helpers/button__classes.js +16 -14
- package/components/_helpers/caption.js +14 -20
- package/components/_helpers/card.js +95 -105
- package/components/_helpers/dialog__body-scroll-preventer.js +11 -19
- package/components/_helpers/icon__svg.js +22 -25
- package/components/_helpers/input.js +146 -177
- package/components/_helpers/query-assist__suggestions.js +74 -90
- package/components/_helpers/select__filter.js +48 -69
- package/components/_helpers/services-link.js +29 -37
- package/components/_helpers/sidebar.js +99 -107
- package/components/_helpers/tab-link.js +7 -7
- package/components/_helpers/theme.js +31 -40
- package/components/_helpers/title.js +57 -72
- package/components/alert/alert.js +150 -202
- package/components/alert/container.js +32 -41
- package/components/alert-service/alert-service.js +105 -170
- package/components/analytics/analytics.js +12 -22
- package/components/analytics/analytics__custom-plugin.js +54 -75
- package/components/auth/auth.js +4 -36
- package/components/auth/auth__core.js +746 -1471
- package/components/auth/background-flow.js +87 -127
- package/components/auth/down-notification.js +30 -73
- package/components/auth/iframe-flow.js +75 -133
- package/components/auth/request-builder.js +46 -82
- package/components/auth/response-parser.js +86 -116
- package/components/auth/storage.js +171 -334
- package/components/auth/token-validator.js +137 -242
- package/components/auth/window-flow.js +92 -134
- package/components/auth-dialog/auth-dialog.js +114 -172
- package/components/auth-dialog-service/auth-dialog-service.js +8 -31
- package/components/avatar/avatar-example-datauri.js +23 -1
- package/components/avatar/avatar.js +119 -152
- package/components/avatar/fallback-avatar.js +22 -38
- package/components/badge/badge.js +35 -45
- package/components/button/button.js +86 -107
- package/components/button-group/button-group.js +19 -33
- package/components/button-set/button-set.js +20 -32
- package/components/button-toolbar/button-toolbar.js +19 -31
- package/components/caret/caret.js +186 -220
- package/components/checkbox/checkbox.js +76 -101
- package/components/clipboard/clipboard-fallback.js +10 -10
- package/components/clipboard/clipboard.js +35 -132
- package/components/code/code.js +92 -166
- package/components/collapse/collapse-content.js +42 -64
- package/components/collapse/collapse-context.js +2 -2
- package/components/collapse/collapse-control.js +12 -14
- package/components/collapse/collapse.js +11 -17
- package/components/collapse/consts.js +4 -4
- package/components/collapse/utils.js +1 -3
- package/components/confirm/confirm.js +66 -104
- package/components/confirm-service/confirm-service.js +37 -59
- package/components/content-layout/content-layout.js +43 -64
- package/components/content-layout/sidebar.js +0 -1
- package/components/contenteditable/contenteditable.js +50 -59
- package/components/control-label/control-label.js +9 -9
- package/components/data-list/data-list.js +129 -182
- package/components/data-list/data-list.mock.js +2 -6
- package/components/data-list/item.js +143 -170
- package/components/data-list/selection.js +76 -136
- package/components/data-list/title.js +1 -12
- package/components/date-picker/consts.js +19 -26
- package/components/date-picker/date-input.js +113 -144
- package/components/date-picker/date-picker.js +227 -282
- package/components/date-picker/date-popup.js +350 -395
- package/components/date-picker/day.js +87 -116
- package/components/date-picker/month-names.js +43 -66
- package/components/date-picker/month-slider.js +51 -76
- package/components/date-picker/month.js +16 -25
- package/components/date-picker/months.js +43 -50
- package/components/date-picker/weekdays.js +12 -22
- package/components/date-picker/years.js +83 -110
- package/components/dialog/dialog.js +142 -190
- package/components/dialog/dialog__body-scroll-preventer.js +0 -4
- package/components/dropdown/anchor.js +0 -9
- package/components/dropdown/dropdown.js +182 -213
- package/components/dropdown-menu/dropdown-menu.js +71 -97
- package/components/editable-heading/editable-heading.js +75 -127
- package/components/error-bubble/error-bubble.js +31 -60
- package/components/error-message/error-message.js +39 -59
- package/components/footer/footer.js +27 -30
- package/components/global/compose.js +1 -10
- package/components/global/composeRefs.js +7 -12
- package/components/global/controls-height.js +2 -2
- package/components/global/create-stateful-context.js +15 -15
- package/components/global/data-tests.js +6 -14
- package/components/global/dom.js +47 -86
- package/components/global/focus-sensor-hoc.js +122 -132
- package/components/global/fuzzy-highlight.js +22 -36
- package/components/global/get-event-key.js +8 -8
- package/components/global/get-uid.js +4 -8
- package/components/global/inject-styles.js +10 -15
- package/components/global/listeners.js +27 -51
- package/components/global/memoize.js +6 -12
- package/components/global/normalize-indent.js +19 -50
- package/components/global/promise-with-timeout.js +6 -8
- package/components/global/prop-types.js +3 -5
- package/components/global/react-dom-renderer.js +28 -44
- package/components/global/react-render-adapter.js +1 -1
- package/components/global/rerender-hoc.js +12 -30
- package/components/global/schedule-raf.js +5 -6
- package/components/global/sniffer.js +1 -1
- package/components/global/theme.js +0 -22
- package/components/global/trivial-template-tag.js +3 -10
- package/components/global/typescript-utils.js +2 -6
- package/components/global/url.js +20 -26
- package/components/global/use-event-callback.js +6 -4
- package/components/grid/col.js +35 -52
- package/components/grid/grid.js +17 -31
- package/components/grid/row.js +35 -47
- package/components/group/group.js +17 -25
- package/components/header/header.js +33 -78
- package/components/header/logo.js +20 -36
- package/components/header/profile.js +166 -199
- package/components/header/services-link.js +0 -4
- package/components/header/services.js +73 -116
- package/components/header/smart-profile.js +111 -203
- package/components/header/smart-services.js +62 -113
- package/components/header/tray-icon.js +21 -37
- package/components/header/tray.js +21 -32
- package/components/heading/heading.js +24 -25
- package/components/http/http.d.ts +1 -3
- package/components/http/http.js +203 -353
- package/components/http/http.mock.js +49 -101
- package/components/hub-source/hub-source.js +83 -190
- package/components/hub-source/hub-source__user.js +11 -44
- package/components/hub-source/hub-source__users-groups.js +37 -65
- package/components/i18n/i18n-context.js +7 -10
- package/components/i18n/i18n.js +7 -10
- package/components/icon/icon.js +76 -93
- package/components/icon/icon__svg.js +0 -8
- package/components/icon/index.js +0 -8
- package/components/input/input.js +0 -13
- package/components/island/adaptive-island-hoc.js +30 -43
- package/components/island/content.js +115 -132
- package/components/island/header.js +57 -70
- package/components/island/island.js +28 -40
- package/components/island-legacy/content-legacy.js +17 -25
- package/components/island-legacy/header-legacy.js +19 -27
- package/components/island-legacy/island-legacy.js +17 -25
- package/components/link/clickableLink.js +44 -59
- package/components/link/link.js +57 -68
- package/components/list/consts.js +2 -2
- package/components/list/list.js +611 -698
- package/components/list/list__custom.js +44 -62
- package/components/list/list__hint.js +10 -19
- package/components/list/list__item.js +133 -174
- package/components/list/list__link.js +37 -50
- package/components/list/list__separator.js +14 -24
- package/components/list/list__title.js +22 -32
- package/components/list/list__users-groups-source.js +54 -126
- package/components/loader/loader.js +43 -74
- package/components/loader/loader__core.js +198 -263
- package/components/loader-inline/loader-inline.js +23 -35
- package/components/loader-screen/loader-screen.js +25 -46
- package/components/login-dialog/login-dialog.js +111 -158
- package/components/login-dialog/service.js +8 -34
- package/components/markdown/markdown.js +15 -23
- package/components/message/message.js +161 -203
- package/components/old-browsers-message/old-browsers-message.js +11 -18
- package/components/old-browsers-message/old-browsers-message__stop.js +0 -7
- package/components/old-browsers-message/white-list.js +8 -16
- package/components/pager/pager.js +212 -271
- package/components/panel/panel.js +17 -25
- package/components/permissions/permissions.js +127 -172
- package/components/permissions/permissions__cache.js +194 -224
- package/components/popup/popup.consts.js +1 -1
- package/components/popup/popup.js +284 -343
- package/components/popup/popup.target.js +9 -8
- package/components/popup/position.js +96 -106
- package/components/popup-menu/popup-menu.js +44 -80
- package/components/progress-bar/progress-bar.js +87 -104
- package/components/query-assist/query-assist.js +838 -916
- package/components/query-assist/query-assist__suggestions.js +1 -30
- package/components/radio/radio.js +19 -34
- package/components/radio/radio__item.js +52 -69
- package/components/select/select.js +852 -957
- package/components/select/select__filter.js +0 -30
- package/components/select/select__popup.js +373 -487
- package/components/shortcuts/core.js +166 -217
- package/components/shortcuts/shortcut-title.js +6 -11
- package/components/shortcuts/shortcuts-hoc.js +19 -45
- package/components/shortcuts/shortcuts.js +50 -75
- package/components/slider/slider.js +99 -122
- package/components/slider/slider.utils.js +14 -24
- package/components/storage/storage.js +4 -33
- package/components/storage/storage__fallback.js +149 -224
- package/components/storage/storage__local.js +90 -153
- package/components/tab-trap/tab-trap.js +122 -153
- package/components/table/cell.js +14 -26
- package/components/table/disable-hover-hoc.js +33 -51
- package/components/table/header-cell.js +64 -89
- package/components/table/header.js +104 -132
- package/components/table/multitable.js +107 -125
- package/components/table/row-with-focus-sensor.js +25 -69
- package/components/table/row.js +175 -216
- package/components/table/selection-adapter.js +1 -3
- package/components/table/selection-shortcuts-hoc.js +180 -181
- package/components/table/selection.js +156 -226
- package/components/table/smart-table.js +50 -88
- package/components/table/table.js +289 -358
- package/components/tabs/collapsible-more.js +46 -79
- package/components/tabs/collapsible-tab.js +31 -38
- package/components/tabs/collapsible-tabs.js +88 -153
- package/components/tabs/custom-item.js +4 -2
- package/components/tabs/dumb-tabs.js +74 -117
- package/components/tabs/smart-tabs.js +29 -69
- package/components/tabs/tab-link.js +1 -5
- package/components/tabs/tab.js +19 -31
- package/components/tabs/tabs.js +0 -31
- package/components/tag/tag.js +133 -173
- package/components/tags-input/tags-input.js +329 -427
- package/components/tags-list/tags-list.js +57 -78
- package/components/text/text.js +28 -39
- package/components/toggle/toggle.js +56 -70
- package/components/tooltip/tooltip.js +146 -190
- package/components/user-agreement/service.js +228 -371
- package/components/user-agreement/toolbox.eula.js +160 -1
- package/components/user-agreement/user-agreement.js +85 -120
- package/components/user-card/card.js +0 -29
- package/components/user-card/smart-user-card-tooltip.js +51 -111
- package/components/user-card/tooltip.js +47 -84
- package/components/user-card/user-card.js +0 -29
- package/package.json +1 -1
@@ -1,49 +1,22 @@
|
|
1
|
-
import { _ as _defineProperty, b as _createClass, d as _objectSpread2, f as _classCallCheck, k as _toConsumableArray, h as _asyncToGenerator, i as _regeneratorRuntime } from '../_helpers/_rollupPluginBabelHelpers.js';
|
2
|
-
import 'core-js/modules/es.array.concat.js';
|
3
|
-
import 'core-js/modules/es.array.filter.js';
|
4
|
-
import 'core-js/modules/es.array.includes.js';
|
5
|
-
import 'core-js/modules/es.array.iterator.js';
|
6
|
-
import 'core-js/modules/es.object.to-string.js';
|
7
|
-
import 'core-js/modules/es.promise.js';
|
8
|
-
import 'core-js/modules/es.regexp.exec.js';
|
9
|
-
import 'core-js/modules/es.regexp.to-string.js';
|
10
|
-
import 'core-js/modules/es.set.js';
|
11
|
-
import 'core-js/modules/es.string.includes.js';
|
12
|
-
import 'core-js/modules/es.string.replace.js';
|
13
|
-
import 'core-js/modules/es.string.search.js';
|
14
|
-
import 'core-js/modules/web.dom-collections.iterator.js';
|
15
|
-
import 'core-js/modules/web.url.js';
|
16
|
-
import 'core-js/modules/web.url.to-json.js';
|
17
|
-
import 'core-js/modules/web.url-search-params.js';
|
18
1
|
import { getAbsoluteBaseURL, fixUrl } from '../global/url.js';
|
19
2
|
import Listeners from '../global/listeners.js';
|
20
3
|
import HTTP from '../http/http.js';
|
21
4
|
import promiseWithTimeout from '../global/promise-with-timeout.js';
|
22
|
-
import {
|
5
|
+
import { getTranslationsWithFallback, translate, getTranslations } from '../i18n/i18n.js';
|
23
6
|
import AuthStorage from './storage.js';
|
24
7
|
import AuthResponseParser from './response-parser.js';
|
25
8
|
import AuthRequestBuilder from './request-builder.js';
|
26
9
|
import BackgroundFlow from './background-flow.js';
|
27
10
|
import TokenValidator from './token-validator.js';
|
28
|
-
import 'core-js/modules/es.array.index-of.js';
|
29
|
-
import 'core-js/modules/es.string.match.js';
|
30
|
-
import 'core-js/modules/es.array.map.js';
|
31
|
-
import 'core-js/modules/es.map.js';
|
32
|
-
import 'core-js/modules/es.object.entries.js';
|
33
|
-
import 'core-js/modules/es.reflect.delete-property.js';
|
34
|
-
import 'core-js/modules/es.weak-map.js';
|
35
|
-
import 'core-js/modules/web.dom-collections.for-each.js';
|
36
11
|
import 'es6-error';
|
37
|
-
import 'core-js/modules/es.array.reduce.js';
|
38
|
-
import 'core-js/modules/es.array.sort.js';
|
39
12
|
import '../storage/storage.js';
|
40
13
|
import '../storage/storage__local.js';
|
41
14
|
import '../alert-service/alert-service.js';
|
15
|
+
import '../_helpers/_rollupPluginBabelHelpers.js';
|
42
16
|
import 'react';
|
43
17
|
import 'react-dom/client';
|
44
18
|
import '../global/get-uid.js';
|
45
19
|
import '../alert/alert.js';
|
46
|
-
import 'core-js/modules/es.object.values.js';
|
47
20
|
import 'classnames';
|
48
21
|
import 'prop-types';
|
49
22
|
import '@jetbrains/icons/exception';
|
@@ -54,13 +27,10 @@ import '../icon/icon.js';
|
|
54
27
|
import 'util-deprecate';
|
55
28
|
import '../icon/icon__constants.js';
|
56
29
|
import '../_helpers/icon__svg.js';
|
57
|
-
import 'core-js/modules/es.string.starts-with.js';
|
58
30
|
import '../global/memoize.js';
|
59
31
|
import '../loader-inline/loader-inline.js';
|
60
32
|
import '../global/data-tests.js';
|
61
33
|
import '../global/dom.js';
|
62
|
-
import 'core-js/modules/es.object.assign.js';
|
63
|
-
import 'core-js/modules/es.string.split.js';
|
64
34
|
import '../button/button.js';
|
65
35
|
import '@jetbrains/icons/chevron-10px';
|
66
36
|
import '../link/clickableLink.js';
|
@@ -73,9 +43,6 @@ import '../popup/popup.js';
|
|
73
43
|
import '../global/schedule-raf.js';
|
74
44
|
import '../shortcuts/shortcuts.js';
|
75
45
|
import '../shortcuts/core.js';
|
76
|
-
import 'core-js/modules/es.array.find-index.js';
|
77
|
-
import 'core-js/modules/es.array.slice.js';
|
78
|
-
import 'core-js/modules/es.array.splice.js';
|
79
46
|
import 'combokeys';
|
80
47
|
import '../global/sniffer.js';
|
81
48
|
import 'sniffr';
|
@@ -88,19 +55,19 @@ import 'deep-equal';
|
|
88
55
|
import 'simply-uuid';
|
89
56
|
|
90
57
|
/* eslint-disable @typescript-eslint/no-magic-numbers */
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
58
|
+
const DEFAULT_EXPIRES_TIMEOUT = 40 * 60;
|
59
|
+
const DEFAULT_BACKGROUND_TIMEOUT = 10 * 1000;
|
60
|
+
const DEFAULT_BACKEND_CHECK_TIMEOUT = 10 * 1000;
|
61
|
+
const BACKGROUND_REDIRECT_TIMEOUT = 20 * 1000;
|
62
|
+
const DEFAULT_WAIT_FOR_REDIRECT_TIMEOUT = 5 * 1000;
|
96
63
|
/* eslint-enable @typescript-eslint/no-magic-numbers */
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
64
|
+
const USER_CHANGED_EVENT = 'userChange';
|
65
|
+
const DOMAIN_USER_CHANGED_EVENT = 'domainUser';
|
66
|
+
const LOGOUT_EVENT = 'logout';
|
67
|
+
const LOGOUT_POSTPONED_EVENT = 'logoutPostponed';
|
68
|
+
const USER_CHANGE_POSTPONED_EVENT = 'changePostponed';
|
102
69
|
function noop() {}
|
103
|
-
|
70
|
+
const DEFAULT_CONFIG = {
|
104
71
|
cacheCurrentUser: false,
|
105
72
|
reloadOnUserChange: true,
|
106
73
|
embeddedLogin: false,
|
@@ -114,78 +81,82 @@ var DEFAULT_CONFIG = {
|
|
114
81
|
userFields: ['guest', 'id', 'name', 'login', 'profile/avatar/url'],
|
115
82
|
cleanHash: true,
|
116
83
|
onLogout: noop,
|
117
|
-
onPostponeChangedUser:
|
118
|
-
onPostponeLogout:
|
84
|
+
onPostponeChangedUser: () => {},
|
85
|
+
onPostponeLogout: () => {},
|
119
86
|
enableBackendStatusCheck: true,
|
120
87
|
backendCheckTimeout: DEFAULT_BACKEND_CHECK_TIMEOUT,
|
121
|
-
checkBackendIsUp:
|
122
|
-
|
123
|
-
},
|
124
|
-
onBackendDown: function onBackendDown() {
|
125
|
-
return function () {};
|
126
|
-
},
|
88
|
+
checkBackendIsUp: () => Promise.resolve(null),
|
89
|
+
onBackendDown: () => () => {},
|
127
90
|
defaultExpiresIn: DEFAULT_EXPIRES_TIMEOUT,
|
128
91
|
waitForRedirectTimeout: DEFAULT_WAIT_FOR_REDIRECT_TIMEOUT,
|
129
92
|
translations: null
|
130
93
|
};
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
94
|
+
class Auth {
|
95
|
+
static DEFAULT_CONFIG = DEFAULT_CONFIG;
|
96
|
+
static API_PATH = 'api/rest/';
|
97
|
+
static API_AUTH_PATH = 'oauth2/auth';
|
98
|
+
static API_PROFILE_PATH = 'users/me';
|
99
|
+
static CLOSE_BACKEND_DOWN_MESSAGE = 'backend-check-succeeded';
|
100
|
+
static CLOSE_WINDOW_MESSAGE = 'close-login-window';
|
101
|
+
static shouldRefreshToken = TokenValidator.shouldRefreshToken;
|
102
|
+
static storageIsUnavailable = !navigator.cookieEnabled;
|
103
|
+
config;
|
104
|
+
listeners = new Listeners();
|
105
|
+
http;
|
106
|
+
_service = {};
|
107
|
+
_storage = null;
|
108
|
+
_responseParser = new AuthResponseParser();
|
109
|
+
_requestBuilder = null;
|
110
|
+
_backgroundFlow;
|
111
|
+
_embeddedFlow = null;
|
112
|
+
_tokenValidator = null;
|
113
|
+
_postponed = false;
|
114
|
+
_backendCheckPromise = null;
|
115
|
+
_authDialogService = undefined;
|
116
|
+
_domainStorage;
|
117
|
+
user = null;
|
118
|
+
_initDeferred;
|
119
|
+
_isLoginWindowOpen;
|
120
|
+
constructor(config) {
|
152
121
|
if (!config) {
|
153
122
|
throw new Error('Config is required');
|
154
123
|
}
|
155
124
|
if (config.serverUri == null) {
|
156
125
|
throw new Error('\"serverUri\" property is required');
|
157
126
|
}
|
158
|
-
|
159
|
-
return config.hasOwnProperty(param);
|
160
|
-
});
|
127
|
+
const unsupportedParams = ['redirect_uri', 'request_credentials', 'client_id'].filter(param => config.hasOwnProperty(param));
|
161
128
|
if (unsupportedParams.length !== 0) {
|
162
|
-
throw new Error(
|
129
|
+
throw new Error(`The following parameters are no longer supported: ${unsupportedParams.join(', ')}. Please change them from snake_case to camelCase.`);
|
163
130
|
}
|
164
131
|
config.userFields = config.userFields || [];
|
165
|
-
this.config =
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
132
|
+
this.config = {
|
133
|
+
...Auth.DEFAULT_CONFIG,
|
134
|
+
...config
|
135
|
+
};
|
136
|
+
const {
|
137
|
+
clientId,
|
138
|
+
redirect,
|
139
|
+
redirectUri,
|
140
|
+
requestCredentials,
|
141
|
+
scope
|
142
|
+
} = this.config;
|
143
|
+
const serverUriLength = this.config.serverUri.length;
|
173
144
|
if (serverUriLength > 0 && this.config.serverUri.charAt(serverUriLength - 1) !== '/') {
|
174
145
|
this.config.serverUri += '/';
|
175
146
|
}
|
176
147
|
this.config.userParams = {
|
177
148
|
query: {
|
178
|
-
fields:
|
149
|
+
fields: [...new Set(Auth.DEFAULT_CONFIG.userFields.concat(config.userFields))].join()
|
179
150
|
}
|
180
151
|
};
|
181
152
|
if (!scope.includes(Auth.DEFAULT_CONFIG.clientId)) {
|
182
153
|
scope.push(Auth.DEFAULT_CONFIG.clientId);
|
183
154
|
}
|
184
155
|
this._storage = new AuthStorage({
|
185
|
-
messagePrefix:
|
186
|
-
stateKeyPrefix:
|
187
|
-
tokenKey:
|
188
|
-
userKey:
|
156
|
+
messagePrefix: `${clientId}-message-`,
|
157
|
+
stateKeyPrefix: `${clientId}-states-`,
|
158
|
+
tokenKey: `${clientId}-token`,
|
159
|
+
userKey: `${clientId}-user-`
|
189
160
|
});
|
190
161
|
this._domainStorage = new AuthStorage({
|
191
162
|
messagePrefix: 'domain-message-'
|
@@ -198,7 +169,9 @@ var Auth = /*#__PURE__*/function () {
|
|
198
169
|
requestCredentials,
|
199
170
|
scopes: scope
|
200
171
|
}, this._storage);
|
201
|
-
|
172
|
+
let {
|
173
|
+
backgroundRefreshTimeout
|
174
|
+
} = this.config;
|
202
175
|
if (!backgroundRefreshTimeout) {
|
203
176
|
backgroundRefreshTimeout = this.config.embeddedLogin ? DEFAULT_BACKGROUND_TIMEOUT : BACKGROUND_REDIRECT_TIMEOUT;
|
204
177
|
}
|
@@ -207,1447 +180,749 @@ var Auth = /*#__PURE__*/function () {
|
|
207
180
|
var _this$config$translat;
|
208
181
|
this._embeddedFlow = new this.config.EmbeddedLoginFlow(this._requestBuilder, this._storage, (_this$config$translat = this.config.translations) !== null && _this$config$translat !== void 0 ? _this$config$translat : getTranslationsWithFallback());
|
209
182
|
}
|
210
|
-
|
211
|
-
|
183
|
+
const API_BASE = this.config.serverUri + Auth.API_PATH;
|
184
|
+
const fetchConfig = config.fetchCredentials ? {
|
212
185
|
credentials: config.fetchCredentials
|
213
186
|
} : undefined;
|
214
187
|
this.http = new HTTP(this, API_BASE, fetchConfig);
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
case 0:
|
221
|
-
_context.next = 2;
|
222
|
-
return _this.getUser(token);
|
223
|
-
case 2:
|
224
|
-
user = _context.sent;
|
225
|
-
_this.user = user;
|
226
|
-
return _context.abrupt("return", user);
|
227
|
-
case 5:
|
228
|
-
case "end":
|
229
|
-
return _context.stop();
|
230
|
-
}
|
231
|
-
}, _callee);
|
232
|
-
}));
|
233
|
-
return function getUser(_x) {
|
234
|
-
return _ref.apply(this, arguments);
|
235
|
-
};
|
236
|
-
}();
|
188
|
+
const getUser = async token => {
|
189
|
+
const user = await this.getUser(token);
|
190
|
+
this.user = user;
|
191
|
+
return user;
|
192
|
+
};
|
237
193
|
this._tokenValidator = new TokenValidator(this.config, getUser, this._storage);
|
238
194
|
if (this.config.onLogout) {
|
239
195
|
this.addListener(LOGOUT_EVENT, this.config.onLogout);
|
240
196
|
}
|
241
197
|
if (this.config.reloadOnUserChange) {
|
242
|
-
this.addListener(USER_CHANGED_EVENT,
|
243
|
-
return _this._reloadCurrentPage();
|
244
|
-
});
|
198
|
+
this.addListener(USER_CHANGED_EVENT, () => this._reloadCurrentPage());
|
245
199
|
}
|
246
|
-
this.addListener(LOGOUT_POSTPONED_EVENT,
|
247
|
-
|
248
|
-
|
249
|
-
this.addListener(
|
250
|
-
return _this._setPostponed(true);
|
251
|
-
});
|
252
|
-
this.addListener(USER_CHANGED_EVENT, function () {
|
253
|
-
return _this._setPostponed(false);
|
254
|
-
});
|
255
|
-
this.addListener(USER_CHANGED_EVENT, function (user) {
|
200
|
+
this.addListener(LOGOUT_POSTPONED_EVENT, () => this._setPostponed(true));
|
201
|
+
this.addListener(USER_CHANGE_POSTPONED_EVENT, () => this._setPostponed(true));
|
202
|
+
this.addListener(USER_CHANGED_EVENT, () => this._setPostponed(false));
|
203
|
+
this.addListener(USER_CHANGED_EVENT, user => {
|
256
204
|
if (user) {
|
257
|
-
|
205
|
+
this._updateDomainUser(user.id);
|
258
206
|
}
|
259
207
|
});
|
260
208
|
if (this.config.cacheCurrentUser) {
|
261
|
-
this.addListener(LOGOUT_EVENT,
|
262
|
-
|
263
|
-
return (_this$_storage = _this._storage) === null || _this$_storage === void 0 ? void 0 : _this$_storage.wipeCachedCurrentUser();
|
264
|
-
});
|
265
|
-
this.addListener(USER_CHANGED_EVENT, function () {
|
266
|
-
var _this$_storage2;
|
267
|
-
return (_this$_storage2 = _this._storage) === null || _this$_storage2 === void 0 ? void 0 : _this$_storage2.onUserChanged();
|
268
|
-
});
|
209
|
+
this.addListener(LOGOUT_EVENT, () => this._storage?.wipeCachedCurrentUser());
|
210
|
+
this.addListener(USER_CHANGED_EVENT, () => this._storage?.onUserChanged());
|
269
211
|
}
|
270
212
|
this._createInitDeferred();
|
271
213
|
this.setUpPreconnect(config.serverUri);
|
272
214
|
}
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
215
|
+
_setPostponed() {
|
216
|
+
let postponed = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
217
|
+
this._postponed = postponed;
|
218
|
+
}
|
219
|
+
_updateDomainUser(userID) {
|
220
|
+
this._domainStorage.sendMessage(DOMAIN_USER_CHANGED_EVENT, {
|
221
|
+
userID,
|
222
|
+
serviceID: this.config.clientId
|
223
|
+
});
|
224
|
+
}
|
225
|
+
addListener(event, handler) {
|
226
|
+
this.listeners.add(event, handler);
|
227
|
+
}
|
228
|
+
removeListener(event, handler) {
|
229
|
+
this.listeners.remove(event, handler);
|
230
|
+
}
|
231
|
+
setAuthDialogService(authDialogService) {
|
232
|
+
this._authDialogService = authDialogService;
|
233
|
+
}
|
234
|
+
setCurrentService(service) {
|
235
|
+
this._service = service;
|
236
|
+
}
|
237
|
+
_createInitDeferred() {
|
238
|
+
const deferred = {};
|
239
|
+
deferred.promise = new Promise((resolve, reject) => {
|
240
|
+
deferred.resolve = resolve;
|
241
|
+
deferred.reject = reject;
|
242
|
+
});
|
243
|
+
this._initDeferred = deferred;
|
244
|
+
}
|
245
|
+
/**
|
246
|
+
* @return {Promise.<string>} absolute URL promise that is resolved to a URL
|
247
|
+
* that should be restored after returning back from auth server.
|
248
|
+
*/
|
249
|
+
async init() {
|
250
|
+
this._storage?.onTokenChange(async token => {
|
251
|
+
const isGuest = this.user ? this.user.guest : false;
|
252
|
+
if (isGuest && !token) {
|
253
|
+
return;
|
254
|
+
}
|
255
|
+
if (!token) {
|
256
|
+
this.logout();
|
257
|
+
} else {
|
258
|
+
try {
|
259
|
+
await this._detectUserChange(token.accessToken);
|
260
|
+
} catch (error) {
|
261
|
+
if (!(error instanceof Error)) {
|
262
|
+
throw error;
|
263
|
+
}
|
264
|
+
if (this._canShowDialogs()) {
|
265
|
+
this._showAuthDialog({
|
266
|
+
nonInteractive: true,
|
267
|
+
error
|
268
|
+
});
|
269
|
+
}
|
270
|
+
}
|
271
|
+
}
|
272
|
+
});
|
273
|
+
this._domainStorage.onMessage(DOMAIN_USER_CHANGED_EVENT, message => {
|
274
|
+
const {
|
283
275
|
userID,
|
284
|
-
serviceID
|
285
|
-
}
|
276
|
+
serviceID
|
277
|
+
} = message || {};
|
278
|
+
if (serviceID === this.config.clientId) {
|
279
|
+
return;
|
280
|
+
}
|
281
|
+
if (this.user && userID === this.user.id) {
|
282
|
+
return;
|
283
|
+
}
|
284
|
+
this.forceTokenUpdate();
|
285
|
+
});
|
286
|
+
let state;
|
287
|
+
try {
|
288
|
+
// Look for token or error in hash
|
289
|
+
state = await this._checkForAuthResponse();
|
290
|
+
} catch (error) {
|
291
|
+
return error instanceof Error ? this.handleInitError(error) : undefined;
|
286
292
|
}
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
this.listeners.add(event, handler);
|
293
|
+
// Return endless promise in the background to avoid service start
|
294
|
+
if (state && state.nonRedirect) {
|
295
|
+
return new Promise(noop);
|
291
296
|
}
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
this
|
297
|
+
try {
|
298
|
+
// Check if there is a valid token
|
299
|
+
await this._tokenValidator?.validateToken();
|
300
|
+
// Checking if there is a message left by another app on this domain
|
301
|
+
const message = await this._domainStorage._messagesStorage.get(`domain-message-${DOMAIN_USER_CHANGED_EVENT}`);
|
302
|
+
if (message) {
|
303
|
+
const {
|
304
|
+
userID,
|
305
|
+
serviceID
|
306
|
+
} = message;
|
307
|
+
if (serviceID !== this.config.clientId && (!userID || this.user?.id !== userID)) {
|
308
|
+
this.forceTokenUpdate();
|
309
|
+
}
|
310
|
+
}
|
311
|
+
// Access token appears to be valid.
|
312
|
+
// We may resolve restoreLocation URL now
|
313
|
+
if (!state) {
|
314
|
+
// Check if we have requested to restore state anyway
|
315
|
+
state = await this._checkForStateRestoration();
|
316
|
+
}
|
317
|
+
this._initDeferred?.resolve?.(state && state.restoreLocation);
|
318
|
+
return state?.restoreLocation;
|
319
|
+
} catch (error) {
|
320
|
+
if (Auth.storageIsUnavailable) {
|
321
|
+
this._initDeferred?.resolve?.(); // No way to handle if cookies are disabled
|
322
|
+
await this.requestUser(); // Someone may expect user to be loaded as a part of token validation
|
323
|
+
return null;
|
324
|
+
}
|
325
|
+
return error instanceof Error ? this.handleInitValidationError(error) : undefined;
|
296
326
|
}
|
297
|
-
}
|
298
|
-
|
299
|
-
|
300
|
-
|
327
|
+
}
|
328
|
+
async sendRedirect(error) {
|
329
|
+
const authRequest = await this._requestBuilder?.prepareAuthRequest();
|
330
|
+
if (authRequest != null) {
|
331
|
+
this._redirectCurrentPage(authRequest.url);
|
301
332
|
}
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
333
|
+
// HUB-10867 Since we already redirecting the page, there is no actual need to throw an error
|
334
|
+
// and scare user with flashing error
|
335
|
+
// But let's keep it just in case redirect was not successful
|
336
|
+
await new Promise(resolve => setTimeout(resolve, this.config.waitForRedirectTimeout));
|
337
|
+
throw error;
|
338
|
+
}
|
339
|
+
async handleInitError(error) {
|
340
|
+
if ('stateId' in error && error.stateId) {
|
341
|
+
try {
|
342
|
+
const state = await this._storage?.getState(error.stateId);
|
343
|
+
if (state && state.nonRedirect) {
|
344
|
+
state.error = error;
|
345
|
+
this._storage?.saveState(error.stateId, state);
|
346
|
+
// Return endless promise in the background to avoid service start
|
347
|
+
return new Promise(noop);
|
348
|
+
}
|
349
|
+
} catch (e) {
|
350
|
+
// Throw the original error instead below
|
351
|
+
}
|
306
352
|
}
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
this._initDeferred = deferred;
|
353
|
+
throw error;
|
354
|
+
}
|
355
|
+
async handleInitValidationError(error) {
|
356
|
+
if ('cause' in error && error.cause instanceof Error && error.cause?.message === 'invalid_client') {
|
357
|
+
// eslint-disable-next-line no-console
|
358
|
+
console.error('RingUI Auth: invalid client detected. Logging out', error);
|
359
|
+
await this.logout();
|
360
|
+
return undefined;
|
316
361
|
}
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
(_this$_storage3 = this._storage) === null || _this$_storage3 === void 0 || _this$_storage3.onTokenChange( /*#__PURE__*/function () {
|
332
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(token) {
|
333
|
-
var isGuest;
|
334
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
335
|
-
while (1) switch (_context2.prev = _context2.next) {
|
336
|
-
case 0:
|
337
|
-
isGuest = _this2.user ? _this2.user.guest : false;
|
338
|
-
if (!(isGuest && !token)) {
|
339
|
-
_context2.next = 3;
|
340
|
-
break;
|
341
|
-
}
|
342
|
-
return _context2.abrupt("return");
|
343
|
-
case 3:
|
344
|
-
if (token) {
|
345
|
-
_context2.next = 7;
|
346
|
-
break;
|
347
|
-
}
|
348
|
-
_this2.logout();
|
349
|
-
_context2.next = 17;
|
350
|
-
break;
|
351
|
-
case 7:
|
352
|
-
_context2.prev = 7;
|
353
|
-
_context2.next = 10;
|
354
|
-
return _this2._detectUserChange(token.accessToken);
|
355
|
-
case 10:
|
356
|
-
_context2.next = 17;
|
357
|
-
break;
|
358
|
-
case 12:
|
359
|
-
_context2.prev = 12;
|
360
|
-
_context2.t0 = _context2["catch"](7);
|
361
|
-
if (_context2.t0 instanceof Error) {
|
362
|
-
_context2.next = 16;
|
363
|
-
break;
|
364
|
-
}
|
365
|
-
throw _context2.t0;
|
366
|
-
case 16:
|
367
|
-
if (_this2._canShowDialogs()) {
|
368
|
-
_this2._showAuthDialog({
|
369
|
-
nonInteractive: true,
|
370
|
-
error: _context2.t0
|
371
|
-
});
|
372
|
-
}
|
373
|
-
case 17:
|
374
|
-
case "end":
|
375
|
-
return _context2.stop();
|
376
|
-
}
|
377
|
-
}, _callee2, null, [[7, 12]]);
|
378
|
-
}));
|
379
|
-
return function (_x2) {
|
380
|
-
return _ref2.apply(this, arguments);
|
381
|
-
};
|
382
|
-
}());
|
383
|
-
this._domainStorage.onMessage(DOMAIN_USER_CHANGED_EVENT, function (message) {
|
384
|
-
var _ref3 = message || {},
|
385
|
-
userID = _ref3.userID,
|
386
|
-
serviceID = _ref3.serviceID;
|
387
|
-
if (serviceID === _this2.config.clientId) {
|
388
|
-
return;
|
389
|
-
}
|
390
|
-
if (_this2.user && userID === _this2.user.id) {
|
391
|
-
return;
|
392
|
-
}
|
393
|
-
_this2.forceTokenUpdate();
|
394
|
-
});
|
395
|
-
_context3.prev = 2;
|
396
|
-
_context3.next = 5;
|
397
|
-
return this._checkForAuthResponse();
|
398
|
-
case 5:
|
399
|
-
state = _context3.sent;
|
400
|
-
_context3.next = 11;
|
401
|
-
break;
|
402
|
-
case 8:
|
403
|
-
_context3.prev = 8;
|
404
|
-
_context3.t0 = _context3["catch"](2);
|
405
|
-
return _context3.abrupt("return", _context3.t0 instanceof Error ? this.handleInitError(_context3.t0) : undefined);
|
406
|
-
case 11:
|
407
|
-
if (!(state && state.nonRedirect)) {
|
408
|
-
_context3.next = 13;
|
409
|
-
break;
|
410
|
-
}
|
411
|
-
return _context3.abrupt("return", new Promise(noop));
|
412
|
-
case 13:
|
413
|
-
_context3.prev = 13;
|
414
|
-
_context3.next = 16;
|
415
|
-
return (_this$_tokenValidator = this._tokenValidator) === null || _this$_tokenValidator === void 0 ? void 0 : _this$_tokenValidator.validateToken();
|
416
|
-
case 16:
|
417
|
-
_context3.next = 18;
|
418
|
-
return this._domainStorage._messagesStorage.get("domain-message-".concat(DOMAIN_USER_CHANGED_EVENT));
|
419
|
-
case 18:
|
420
|
-
message = _context3.sent;
|
421
|
-
if (message) {
|
422
|
-
userID = message.userID, serviceID = message.serviceID;
|
423
|
-
if (serviceID !== this.config.clientId && (!userID || ((_this$user = this.user) === null || _this$user === void 0 ? void 0 : _this$user.id) !== userID)) {
|
424
|
-
this.forceTokenUpdate();
|
425
|
-
}
|
426
|
-
}
|
427
|
-
// Access token appears to be valid.
|
428
|
-
// We may resolve restoreLocation URL now
|
429
|
-
if (state) {
|
430
|
-
_context3.next = 24;
|
431
|
-
break;
|
432
|
-
}
|
433
|
-
_context3.next = 23;
|
434
|
-
return this._checkForStateRestoration();
|
435
|
-
case 23:
|
436
|
-
state = _context3.sent;
|
437
|
-
case 24:
|
438
|
-
(_this$_initDeferred = this._initDeferred) === null || _this$_initDeferred === void 0 || (_this$_initDeferred$r = _this$_initDeferred.resolve) === null || _this$_initDeferred$r === void 0 || _this$_initDeferred$r.call(_this$_initDeferred, state && state.restoreLocation);
|
439
|
-
return _context3.abrupt("return", (_state = state) === null || _state === void 0 ? void 0 : _state.restoreLocation);
|
440
|
-
case 28:
|
441
|
-
_context3.prev = 28;
|
442
|
-
_context3.t1 = _context3["catch"](13);
|
443
|
-
if (!Auth.storageIsUnavailable) {
|
444
|
-
_context3.next = 35;
|
445
|
-
break;
|
446
|
-
}
|
447
|
-
(_this$_initDeferred2 = this._initDeferred) === null || _this$_initDeferred2 === void 0 || (_this$_initDeferred2$ = _this$_initDeferred2.resolve) === null || _this$_initDeferred2$ === void 0 || _this$_initDeferred2$.call(_this$_initDeferred2); // No way to handle if cookies are disabled
|
448
|
-
_context3.next = 34;
|
449
|
-
return this.requestUser();
|
450
|
-
case 34:
|
451
|
-
return _context3.abrupt("return", null);
|
452
|
-
case 35:
|
453
|
-
return _context3.abrupt("return", _context3.t1 instanceof Error ? this.handleInitValidationError(_context3.t1) : undefined);
|
454
|
-
case 36:
|
455
|
-
case "end":
|
456
|
-
return _context3.stop();
|
457
|
-
}
|
458
|
-
}, _callee3, this, [[2, 8], [13, 28]]);
|
459
|
-
}));
|
460
|
-
function init() {
|
461
|
-
return _init.apply(this, arguments);
|
462
|
-
}
|
463
|
-
return init;
|
464
|
-
}())
|
465
|
-
}, {
|
466
|
-
key: "sendRedirect",
|
467
|
-
value: function () {
|
468
|
-
var _sendRedirect = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(error) {
|
469
|
-
var _this$_requestBuilder,
|
470
|
-
_this3 = this;
|
471
|
-
var authRequest;
|
472
|
-
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
473
|
-
while (1) switch (_context4.prev = _context4.next) {
|
474
|
-
case 0:
|
475
|
-
_context4.next = 2;
|
476
|
-
return (_this$_requestBuilder = this._requestBuilder) === null || _this$_requestBuilder === void 0 ? void 0 : _this$_requestBuilder.prepareAuthRequest();
|
477
|
-
case 2:
|
478
|
-
authRequest = _context4.sent;
|
479
|
-
if (authRequest != null) {
|
480
|
-
this._redirectCurrentPage(authRequest.url);
|
481
|
-
}
|
482
|
-
// HUB-10867 Since we already redirecting the page, there is no actual need to throw an error
|
483
|
-
// and scare user with flashing error
|
484
|
-
// But let's keep it just in case redirect was not successful
|
485
|
-
_context4.next = 6;
|
486
|
-
return new Promise(function (resolve) {
|
487
|
-
return setTimeout(resolve, _this3.config.waitForRedirectTimeout);
|
488
|
-
});
|
489
|
-
case 6:
|
490
|
-
throw error;
|
491
|
-
case 7:
|
492
|
-
case "end":
|
493
|
-
return _context4.stop();
|
494
|
-
}
|
495
|
-
}, _callee4, this);
|
496
|
-
}));
|
497
|
-
function sendRedirect(_x3) {
|
498
|
-
return _sendRedirect.apply(this, arguments);
|
362
|
+
// Redirect flow
|
363
|
+
if ('authRedirect' in error && error.authRedirect && this.config.redirect) {
|
364
|
+
return this.sendRedirect(error);
|
365
|
+
}
|
366
|
+
// Background flow
|
367
|
+
if ('authRedirect' in error && error.authRedirect && !this.config.redirect) {
|
368
|
+
try {
|
369
|
+
await this._backgroundFlow?.authorize();
|
370
|
+
await this._tokenValidator?.validateToken();
|
371
|
+
this._initDeferred?.resolve?.();
|
372
|
+
return undefined;
|
373
|
+
} catch (validationError) {
|
374
|
+
// Fallback to redirect flow
|
375
|
+
return validationError instanceof Error ? this.sendRedirect(validationError) : undefined;
|
499
376
|
}
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
state = _context5.sent;
|
519
|
-
if (!(state && state.nonRedirect)) {
|
520
|
-
_context5.next = 9;
|
521
|
-
break;
|
522
|
-
}
|
523
|
-
state.error = error;
|
524
|
-
(_this$_storage5 = this._storage) === null || _this$_storage5 === void 0 || _this$_storage5.saveState(error.stateId, state);
|
525
|
-
// Return endless promise in the background to avoid service start
|
526
|
-
return _context5.abrupt("return", new Promise(noop));
|
527
|
-
case 9:
|
528
|
-
_context5.next = 13;
|
529
|
-
break;
|
530
|
-
case 11:
|
531
|
-
_context5.prev = 11;
|
532
|
-
_context5.t0 = _context5["catch"](1);
|
533
|
-
case 13:
|
534
|
-
throw error;
|
535
|
-
case 14:
|
536
|
-
case "end":
|
537
|
-
return _context5.stop();
|
538
|
-
}
|
539
|
-
}, _callee5, this, [[1, 11]]);
|
540
|
-
}));
|
541
|
-
function handleInitError(_x4) {
|
542
|
-
return _handleInitError.apply(this, arguments);
|
377
|
+
}
|
378
|
+
this._initDeferred?.reject?.(error);
|
379
|
+
throw error;
|
380
|
+
}
|
381
|
+
/**
|
382
|
+
* Get token from local storage or request it if necessary.
|
383
|
+
* Can redirect to login page.
|
384
|
+
* @return {Promise.<string>}
|
385
|
+
*/
|
386
|
+
async requestToken() {
|
387
|
+
if (this._postponed) {
|
388
|
+
throw new Error('You should log in to be able to make requests');
|
389
|
+
}
|
390
|
+
try {
|
391
|
+
var _await$this$_tokenVal;
|
392
|
+
await this._initDeferred?.promise;
|
393
|
+
if (Auth.storageIsUnavailable) {
|
394
|
+
return null; // Forever guest if storage is unavailable
|
543
395
|
}
|
544
|
-
return
|
545
|
-
}()
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
break;
|
558
|
-
}
|
559
|
-
// eslint-disable-next-line no-console
|
560
|
-
console.error('RingUI Auth: invalid client detected. Logging out', error);
|
561
|
-
_context6.next = 4;
|
562
|
-
return this.logout();
|
563
|
-
case 4:
|
564
|
-
return _context6.abrupt("return", undefined);
|
565
|
-
case 5:
|
566
|
-
if (!('authRedirect' in error && error.authRedirect && this.config.redirect)) {
|
567
|
-
_context6.next = 7;
|
568
|
-
break;
|
569
|
-
}
|
570
|
-
return _context6.abrupt("return", this.sendRedirect(error));
|
571
|
-
case 7:
|
572
|
-
if (!('authRedirect' in error && error.authRedirect && !this.config.redirect)) {
|
573
|
-
_context6.next = 20;
|
574
|
-
break;
|
575
|
-
}
|
576
|
-
_context6.prev = 8;
|
577
|
-
_context6.next = 11;
|
578
|
-
return (_this$_backgroundFlow = this._backgroundFlow) === null || _this$_backgroundFlow === void 0 ? void 0 : _this$_backgroundFlow.authorize();
|
579
|
-
case 11:
|
580
|
-
_context6.next = 13;
|
581
|
-
return (_this$_tokenValidator2 = this._tokenValidator) === null || _this$_tokenValidator2 === void 0 ? void 0 : _this$_tokenValidator2.validateToken();
|
582
|
-
case 13:
|
583
|
-
(_this$_initDeferred3 = this._initDeferred) === null || _this$_initDeferred3 === void 0 || (_this$_initDeferred3$ = _this$_initDeferred3.resolve) === null || _this$_initDeferred3$ === void 0 || _this$_initDeferred3$.call(_this$_initDeferred3);
|
584
|
-
return _context6.abrupt("return", undefined);
|
585
|
-
case 17:
|
586
|
-
_context6.prev = 17;
|
587
|
-
_context6.t0 = _context6["catch"](8);
|
588
|
-
return _context6.abrupt("return", _context6.t0 instanceof Error ? this.sendRedirect(_context6.t0) : undefined);
|
589
|
-
case 20:
|
590
|
-
(_this$_initDeferred4 = this._initDeferred) === null || _this$_initDeferred4 === void 0 || (_this$_initDeferred4$ = _this$_initDeferred4.reject) === null || _this$_initDeferred4$ === void 0 || _this$_initDeferred4$.call(_this$_initDeferred4, error);
|
591
|
-
throw error;
|
592
|
-
case 22:
|
593
|
-
case "end":
|
594
|
-
return _context6.stop();
|
595
|
-
}
|
596
|
-
}, _callee6, this, [[8, 17]]);
|
597
|
-
}));
|
598
|
-
function handleInitValidationError(_x5) {
|
599
|
-
return _handleInitValidationError.apply(this, arguments);
|
396
|
+
return (_await$this$_tokenVal = await this._tokenValidator?.validateTokenLocally()) !== null && _await$this$_tokenVal !== void 0 ? _await$this$_tokenVal : null;
|
397
|
+
} catch (e) {
|
398
|
+
return this.forceTokenUpdate();
|
399
|
+
}
|
400
|
+
}
|
401
|
+
/**
|
402
|
+
* Get new token in the background or redirect to the login page.
|
403
|
+
* @return {Promise.<string>}
|
404
|
+
*/
|
405
|
+
async forceTokenUpdate() {
|
406
|
+
try {
|
407
|
+
if (!this._backendCheckPromise) {
|
408
|
+
this._backendCheckPromise = this._checkBackendsStatusesIfEnabled();
|
600
409
|
}
|
601
|
-
|
602
|
-
}()
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
614
|
-
while (1) switch (_context7.prev = _context7.next) {
|
615
|
-
case 0:
|
616
|
-
if (!this._postponed) {
|
617
|
-
_context7.next = 2;
|
618
|
-
break;
|
619
|
-
}
|
620
|
-
throw new Error('You should log in to be able to make requests');
|
621
|
-
case 2:
|
622
|
-
_context7.prev = 2;
|
623
|
-
_context7.next = 5;
|
624
|
-
return (_this$_initDeferred5 = this._initDeferred) === null || _this$_initDeferred5 === void 0 ? void 0 : _this$_initDeferred5.promise;
|
625
|
-
case 5:
|
626
|
-
if (!Auth.storageIsUnavailable) {
|
627
|
-
_context7.next = 7;
|
628
|
-
break;
|
629
|
-
}
|
630
|
-
return _context7.abrupt("return", null);
|
631
|
-
case 7:
|
632
|
-
_context7.next = 9;
|
633
|
-
return (_this$_tokenValidator3 = this._tokenValidator) === null || _this$_tokenValidator3 === void 0 ? void 0 : _this$_tokenValidator3.validateTokenLocally();
|
634
|
-
case 9:
|
635
|
-
_context7.t1 = _yield$this$_tokenVal = _context7.sent;
|
636
|
-
_context7.t0 = _context7.t1 !== null;
|
637
|
-
if (!_context7.t0) {
|
638
|
-
_context7.next = 13;
|
639
|
-
break;
|
640
|
-
}
|
641
|
-
_context7.t0 = _yield$this$_tokenVal !== void 0;
|
642
|
-
case 13:
|
643
|
-
if (!_context7.t0) {
|
644
|
-
_context7.next = 17;
|
645
|
-
break;
|
646
|
-
}
|
647
|
-
_context7.t2 = _yield$this$_tokenVal;
|
648
|
-
_context7.next = 18;
|
649
|
-
break;
|
650
|
-
case 17:
|
651
|
-
_context7.t2 = null;
|
652
|
-
case 18:
|
653
|
-
return _context7.abrupt("return", _context7.t2);
|
654
|
-
case 21:
|
655
|
-
_context7.prev = 21;
|
656
|
-
_context7.t3 = _context7["catch"](2);
|
657
|
-
return _context7.abrupt("return", this.forceTokenUpdate());
|
658
|
-
case 24:
|
659
|
-
case "end":
|
660
|
-
return _context7.stop();
|
661
|
-
}
|
662
|
-
}, _callee7, this, [[2, 21]]);
|
663
|
-
}));
|
664
|
-
function requestToken() {
|
665
|
-
return _requestToken.apply(this, arguments);
|
410
|
+
await this._backendCheckPromise;
|
411
|
+
} catch (e) {
|
412
|
+
throw new Error('Cannot refresh token: backend is not available. Postponed by user.');
|
413
|
+
} finally {
|
414
|
+
this._backendCheckPromise = null;
|
415
|
+
}
|
416
|
+
try {
|
417
|
+
var _await$this$_backgrou;
|
418
|
+
return (_await$this$_backgrou = await this._backgroundFlow?.authorize()) !== null && _await$this$_backgrou !== void 0 ? _await$this$_backgrou : null;
|
419
|
+
} catch (error) {
|
420
|
+
if (!(error instanceof Error)) {
|
421
|
+
return null;
|
666
422
|
}
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
value: (function () {
|
677
|
-
var _forceTokenUpdate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
|
678
|
-
var _this4 = this;
|
679
|
-
var _yield$this$_backgrou, _this$_backgroundFlow2, _this$_requestBuilder2, authRequest;
|
680
|
-
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
681
|
-
while (1) switch (_context9.prev = _context9.next) {
|
682
|
-
case 0:
|
683
|
-
_context9.prev = 0;
|
684
|
-
if (!this._backendCheckPromise) {
|
685
|
-
this._backendCheckPromise = this._checkBackendsStatusesIfEnabled();
|
686
|
-
}
|
687
|
-
_context9.next = 4;
|
688
|
-
return this._backendCheckPromise;
|
689
|
-
case 4:
|
690
|
-
_context9.next = 9;
|
691
|
-
break;
|
692
|
-
case 6:
|
693
|
-
_context9.prev = 6;
|
694
|
-
_context9.t0 = _context9["catch"](0);
|
695
|
-
throw new Error('Cannot refresh token: backend is not available. Postponed by user.');
|
696
|
-
case 9:
|
697
|
-
_context9.prev = 9;
|
698
|
-
this._backendCheckPromise = null;
|
699
|
-
return _context9.finish(9);
|
700
|
-
case 12:
|
701
|
-
_context9.prev = 12;
|
702
|
-
_context9.next = 15;
|
703
|
-
return (_this$_backgroundFlow2 = this._backgroundFlow) === null || _this$_backgroundFlow2 === void 0 ? void 0 : _this$_backgroundFlow2.authorize();
|
704
|
-
case 15:
|
705
|
-
_context9.t2 = _yield$this$_backgrou = _context9.sent;
|
706
|
-
_context9.t1 = _context9.t2 !== null;
|
707
|
-
if (!_context9.t1) {
|
708
|
-
_context9.next = 19;
|
709
|
-
break;
|
710
|
-
}
|
711
|
-
_context9.t1 = _yield$this$_backgrou !== void 0;
|
712
|
-
case 19:
|
713
|
-
if (!_context9.t1) {
|
714
|
-
_context9.next = 23;
|
715
|
-
break;
|
716
|
-
}
|
717
|
-
_context9.t3 = _yield$this$_backgrou;
|
718
|
-
_context9.next = 24;
|
719
|
-
break;
|
720
|
-
case 23:
|
721
|
-
_context9.t3 = null;
|
722
|
-
case 24:
|
723
|
-
return _context9.abrupt("return", _context9.t3);
|
724
|
-
case 27:
|
725
|
-
_context9.prev = 27;
|
726
|
-
_context9.t4 = _context9["catch"](12);
|
727
|
-
if (_context9.t4 instanceof Error) {
|
728
|
-
_context9.next = 31;
|
729
|
-
break;
|
730
|
-
}
|
731
|
-
return _context9.abrupt("return", null);
|
732
|
-
case 31:
|
733
|
-
if (!this._canShowDialogs()) {
|
734
|
-
_context9.next = 35;
|
735
|
-
break;
|
736
|
-
}
|
737
|
-
return _context9.abrupt("return", new Promise(function (resolve) {
|
738
|
-
var onTryAgain = /*#__PURE__*/function () {
|
739
|
-
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
|
740
|
-
var _this4$_backgroundFlo, result;
|
741
|
-
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
742
|
-
while (1) switch (_context8.prev = _context8.next) {
|
743
|
-
case 0:
|
744
|
-
_context8.prev = 0;
|
745
|
-
_context8.next = 3;
|
746
|
-
return (_this4$_backgroundFlo = _this4._backgroundFlow) === null || _this4$_backgroundFlo === void 0 ? void 0 : _this4$_backgroundFlo.authorize();
|
747
|
-
case 3:
|
748
|
-
result = _context8.sent;
|
749
|
-
resolve(result !== null && result !== void 0 ? result : null);
|
750
|
-
_context8.next = 11;
|
751
|
-
break;
|
752
|
-
case 7:
|
753
|
-
_context8.prev = 7;
|
754
|
-
_context8.t0 = _context8["catch"](0);
|
755
|
-
if (_context8.t0 instanceof Error) {
|
756
|
-
_this4._showAuthDialog({
|
757
|
-
nonInteractive: true,
|
758
|
-
error: _context8.t0,
|
759
|
-
onTryAgain
|
760
|
-
});
|
761
|
-
}
|
762
|
-
throw _context8.t0;
|
763
|
-
case 11:
|
764
|
-
case "end":
|
765
|
-
return _context8.stop();
|
766
|
-
}
|
767
|
-
}, _callee8, null, [[0, 7]]);
|
768
|
-
}));
|
769
|
-
return function onTryAgain() {
|
770
|
-
return _ref4.apply(this, arguments);
|
771
|
-
};
|
772
|
-
}();
|
773
|
-
_this4._showAuthDialog({
|
423
|
+
if (this._canShowDialogs()) {
|
424
|
+
return new Promise(resolve => {
|
425
|
+
const onTryAgain = async () => {
|
426
|
+
try {
|
427
|
+
const result = await this._backgroundFlow?.authorize();
|
428
|
+
resolve(result !== null && result !== void 0 ? result : null);
|
429
|
+
} catch (retryError) {
|
430
|
+
if (retryError instanceof Error) {
|
431
|
+
this._showAuthDialog({
|
774
432
|
nonInteractive: true,
|
775
|
-
error:
|
433
|
+
error: retryError,
|
776
434
|
onTryAgain
|
777
435
|
});
|
778
|
-
}));
|
779
|
-
case 35:
|
780
|
-
_context9.next = 37;
|
781
|
-
return (_this$_requestBuilder2 = this._requestBuilder) === null || _this$_requestBuilder2 === void 0 ? void 0 : _this$_requestBuilder2.prepareAuthRequest();
|
782
|
-
case 37:
|
783
|
-
authRequest = _context9.sent;
|
784
|
-
if (authRequest != null) {
|
785
|
-
this._redirectCurrentPage(authRequest.url);
|
786
|
-
}
|
787
|
-
case 39:
|
788
|
-
throw new TokenValidator.TokenValidationError(_context9.t4.message);
|
789
|
-
case 40:
|
790
|
-
case "end":
|
791
|
-
return _context9.stop();
|
792
|
-
}
|
793
|
-
}, _callee9, this, [[0, 6, 9, 12], [12, 27]]);
|
794
|
-
}));
|
795
|
-
function forceTokenUpdate() {
|
796
|
-
return _forceTokenUpdate.apply(this, arguments);
|
797
|
-
}
|
798
|
-
return forceTokenUpdate;
|
799
|
-
}())
|
800
|
-
}, {
|
801
|
-
key: "loadCurrentService",
|
802
|
-
value: function () {
|
803
|
-
var _loadCurrentService = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
|
804
|
-
var _ref5, serviceName, serviceImage;
|
805
|
-
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
806
|
-
while (1) switch (_context10.prev = _context10.next) {
|
807
|
-
case 0:
|
808
|
-
if (!this._service.serviceName) {
|
809
|
-
_context10.next = 2;
|
810
|
-
break;
|
811
|
-
}
|
812
|
-
return _context10.abrupt("return");
|
813
|
-
case 2:
|
814
|
-
_context10.prev = 2;
|
815
|
-
_context10.next = 5;
|
816
|
-
return this.http.get("oauth2/interactive/login/settings?client_id=".concat(this.config.clientId));
|
817
|
-
case 5:
|
818
|
-
_context10.t0 = _context10.sent;
|
819
|
-
if (_context10.t0) {
|
820
|
-
_context10.next = 8;
|
821
|
-
break;
|
822
436
|
}
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
});
|
832
|
-
_context10.next = 16;
|
833
|
-
break;
|
834
|
-
case 14:
|
835
|
-
_context10.prev = 14;
|
836
|
-
_context10.t1 = _context10["catch"](2);
|
837
|
-
case 16:
|
838
|
-
case "end":
|
839
|
-
return _context10.stop();
|
840
|
-
}
|
841
|
-
}, _callee10, this, [[2, 14]]);
|
842
|
-
}));
|
843
|
-
function loadCurrentService() {
|
844
|
-
return _loadCurrentService.apply(this, arguments);
|
845
|
-
}
|
846
|
-
return loadCurrentService;
|
847
|
-
}()
|
848
|
-
}, {
|
849
|
-
key: "getAPIPath",
|
850
|
-
value: function getAPIPath() {
|
851
|
-
return this.config.serverUri + Auth.API_PATH;
|
852
|
-
}
|
853
|
-
/**
|
854
|
-
* @return {Promise.<object>}
|
855
|
-
*/
|
856
|
-
}, {
|
857
|
-
key: "getUser",
|
858
|
-
value: function getUser(accessToken) {
|
859
|
-
var _this5 = this;
|
860
|
-
if (this.config.cacheCurrentUser) {
|
861
|
-
var _this$_storage6;
|
862
|
-
return (_this$_storage6 = this._storage) === null || _this$_storage6 === void 0 ? void 0 : _this$_storage6.getCachedUser(function () {
|
863
|
-
return _this5.http.authorizedFetch(Auth.API_PROFILE_PATH, accessToken, _this5.config.userParams);
|
437
|
+
throw retryError;
|
438
|
+
}
|
439
|
+
};
|
440
|
+
this._showAuthDialog({
|
441
|
+
nonInteractive: true,
|
442
|
+
error: error,
|
443
|
+
onTryAgain
|
444
|
+
});
|
864
445
|
});
|
865
446
|
} else {
|
866
|
-
|
447
|
+
const authRequest = await this._requestBuilder?.prepareAuthRequest();
|
448
|
+
if (authRequest != null) {
|
449
|
+
this._redirectCurrentPage(authRequest.url);
|
450
|
+
}
|
867
451
|
}
|
452
|
+
throw new TokenValidator.TokenValidationError(error.message);
|
868
453
|
}
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
454
|
+
}
|
455
|
+
async loadCurrentService() {
|
456
|
+
if (this._service.serviceName) {
|
457
|
+
return;
|
458
|
+
}
|
459
|
+
try {
|
460
|
+
const {
|
461
|
+
serviceName,
|
462
|
+
iconUrl: serviceImage
|
463
|
+
} = (await this.http.get(`oauth2/interactive/login/settings?client_id=${this.config.clientId}`)) || {};
|
464
|
+
this.setCurrentService({
|
465
|
+
serviceImage,
|
466
|
+
serviceName
|
467
|
+
});
|
468
|
+
} catch (e) {
|
469
|
+
// noop
|
470
|
+
}
|
471
|
+
}
|
472
|
+
getAPIPath() {
|
473
|
+
return this.config.serverUri + Auth.API_PATH;
|
474
|
+
}
|
475
|
+
/**
|
476
|
+
* @return {Promise.<object>}
|
477
|
+
*/
|
478
|
+
getUser(accessToken) {
|
479
|
+
if (this.config.cacheCurrentUser) {
|
480
|
+
return this._storage?.getCachedUser(() => this.http.authorizedFetch(Auth.API_PROFILE_PATH, accessToken, this.config.userParams));
|
481
|
+
} else {
|
482
|
+
return this.http.authorizedFetch(Auth.API_PROFILE_PATH, accessToken, this.config.userParams);
|
483
|
+
}
|
484
|
+
}
|
485
|
+
/**
|
486
|
+
* @return {Promise.<object>}
|
487
|
+
*/
|
488
|
+
async requestUser() {
|
489
|
+
if (this.user) {
|
490
|
+
return this.user;
|
491
|
+
}
|
492
|
+
const accessToken = await this.requestToken();
|
493
|
+
// If user was fetched during token request
|
494
|
+
if (this.user) {
|
495
|
+
return this.user;
|
496
|
+
}
|
497
|
+
const user = await this.getUser(accessToken);
|
498
|
+
this.user = user;
|
499
|
+
return user;
|
500
|
+
}
|
501
|
+
async updateUser() {
|
502
|
+
this._setPostponed(false);
|
503
|
+
const accessToken = await this.requestToken();
|
504
|
+
this._storage?.wipeCachedCurrentUser();
|
505
|
+
const user = await this.getUser(accessToken);
|
506
|
+
this.user = user;
|
507
|
+
this.listeners.trigger(USER_CHANGED_EVENT, user);
|
508
|
+
}
|
509
|
+
async _detectUserChange(accessToken) {
|
510
|
+
const windowWasOpen = this._isLoginWindowOpen;
|
511
|
+
const user = await this.getUser(accessToken);
|
512
|
+
const onApply = () => {
|
513
|
+
this.user = user;
|
514
|
+
this.listeners.trigger(USER_CHANGED_EVENT, user);
|
515
|
+
};
|
516
|
+
if (user && this.user && this.user.id !== user.id) {
|
517
|
+
if (!this._canShowDialogs() || this.user.guest || windowWasOpen) {
|
518
|
+
onApply();
|
519
|
+
return;
|
910
520
|
}
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
var _updateUser = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
|
917
|
-
var _this$_storage7;
|
918
|
-
var accessToken, user;
|
919
|
-
return _regeneratorRuntime().wrap(function _callee12$(_context12) {
|
920
|
-
while (1) switch (_context12.prev = _context12.next) {
|
921
|
-
case 0:
|
922
|
-
this._setPostponed(false);
|
923
|
-
_context12.next = 3;
|
924
|
-
return this.requestToken();
|
925
|
-
case 3:
|
926
|
-
accessToken = _context12.sent;
|
927
|
-
(_this$_storage7 = this._storage) === null || _this$_storage7 === void 0 || _this$_storage7.wipeCachedCurrentUser();
|
928
|
-
_context12.next = 7;
|
929
|
-
return this.getUser(accessToken);
|
930
|
-
case 7:
|
931
|
-
user = _context12.sent;
|
932
|
-
this.user = user;
|
933
|
-
this.listeners.trigger(USER_CHANGED_EVENT, user);
|
934
|
-
case 10:
|
935
|
-
case "end":
|
936
|
-
return _context12.stop();
|
937
|
-
}
|
938
|
-
}, _callee12, this);
|
939
|
-
}));
|
940
|
-
function updateUser() {
|
941
|
-
return _updateUser.apply(this, arguments);
|
521
|
+
if (user.guest) {
|
522
|
+
this._showAuthDialog({
|
523
|
+
nonInteractive: true
|
524
|
+
});
|
525
|
+
return;
|
942
526
|
}
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
964
|
-
|
965
|
-
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
onPostpone: function onPostpone() {
|
988
|
-
_this6.listeners.trigger(USER_CHANGE_POSTPONED_EVENT);
|
989
|
-
_this6.config.onPostponeChangedUser(_this6.user, user);
|
990
|
-
}
|
991
|
-
});
|
992
|
-
case 14:
|
993
|
-
case "end":
|
994
|
-
return _context13.stop();
|
995
|
-
}
|
996
|
-
}, _callee13, this);
|
997
|
-
}));
|
998
|
-
function _detectUserChange(_x6) {
|
999
|
-
return _detectUserChange2.apply(this, arguments);
|
527
|
+
await this._showUserChangedDialog({
|
528
|
+
newUser: user,
|
529
|
+
onApply,
|
530
|
+
onPostpone: () => {
|
531
|
+
this.listeners.trigger(USER_CHANGE_POSTPONED_EVENT);
|
532
|
+
this.config.onPostponeChangedUser(this.user, user);
|
533
|
+
}
|
534
|
+
});
|
535
|
+
}
|
536
|
+
}
|
537
|
+
_beforeLogout(params) {
|
538
|
+
if (this._canShowDialogs()) {
|
539
|
+
this._showAuthDialog(params);
|
540
|
+
return;
|
541
|
+
}
|
542
|
+
this.logout();
|
543
|
+
}
|
544
|
+
_showAuthDialog() {
|
545
|
+
let {
|
546
|
+
nonInteractive,
|
547
|
+
error,
|
548
|
+
canCancel,
|
549
|
+
onTryAgain
|
550
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
551
|
+
const {
|
552
|
+
embeddedLogin,
|
553
|
+
onPostponeLogout,
|
554
|
+
translations
|
555
|
+
} = this.config;
|
556
|
+
const cancelable = this.user?.guest || canCancel;
|
557
|
+
const actualTranslations = translations !== null && translations !== void 0 ? translations : getTranslations();
|
558
|
+
this._createInitDeferred();
|
559
|
+
const closeDialog = () => {
|
560
|
+
/* eslint-disable @typescript-eslint/no-use-before-define */
|
561
|
+
stopTokenListening?.();
|
562
|
+
stopMessageListening?.();
|
563
|
+
hide?.();
|
564
|
+
/* eslint-enable @typescript-eslint/no-use-before-define */
|
565
|
+
};
|
566
|
+
const onConfirm = () => {
|
567
|
+
if (!embeddedLogin) {
|
568
|
+
closeDialog();
|
569
|
+
this.logout();
|
570
|
+
return;
|
1000
571
|
}
|
1001
|
-
|
1002
|
-
}
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1007
|
-
|
572
|
+
this._runEmbeddedLogin();
|
573
|
+
};
|
574
|
+
const onCancel = () => {
|
575
|
+
this._embeddedFlow?.stop();
|
576
|
+
this._storage?.sendMessage(Auth.CLOSE_WINDOW_MESSAGE, Date.now());
|
577
|
+
closeDialog();
|
578
|
+
if (!cancelable) {
|
579
|
+
this._initDeferred?.resolve?.();
|
580
|
+
this.listeners.trigger(LOGOUT_POSTPONED_EVENT);
|
581
|
+
onPostponeLogout();
|
1008
582
|
return;
|
1009
583
|
}
|
1010
|
-
this.
|
584
|
+
if (this.user?.guest && nonInteractive) {
|
585
|
+
this.forceTokenUpdate();
|
586
|
+
} else {
|
587
|
+
this._initDeferred?.resolve?.();
|
588
|
+
}
|
589
|
+
};
|
590
|
+
const onTryAgainClick = async () => {
|
591
|
+
await onTryAgain?.();
|
592
|
+
closeDialog();
|
593
|
+
};
|
594
|
+
const hide = this._authDialogService?.({
|
595
|
+
...this._service,
|
596
|
+
loginCaption: actualTranslations.login,
|
597
|
+
loginToCaption: actualTranslations.loginTo,
|
598
|
+
confirmLabel: actualTranslations.login,
|
599
|
+
tryAgainLabel: actualTranslations.tryAgainLabel,
|
600
|
+
cancelLabel: cancelable ? actualTranslations.cancel : actualTranslations.postpone,
|
601
|
+
errorMessage: this._extractErrorMessage(error, true),
|
602
|
+
onConfirm,
|
603
|
+
onCancel,
|
604
|
+
onTryAgain: onTryAgain ? onTryAgainClick : undefined
|
605
|
+
});
|
606
|
+
const stopTokenListening = this._storage?.onTokenChange(token => {
|
607
|
+
if (token) {
|
608
|
+
closeDialog();
|
609
|
+
this._initDeferred?.resolve?.();
|
610
|
+
}
|
611
|
+
});
|
612
|
+
const stopMessageListening = this._storage?.onMessage(Auth.CLOSE_WINDOW_MESSAGE, () => this._embeddedFlow?.stop());
|
613
|
+
}
|
614
|
+
_showUserChangedDialog(_ref) {
|
615
|
+
var _translations$youHave, _newUser$name, _newUser$name2, _translations$login, _translations$loginTo, _translations$applyCh, _translations$tryAgai, _translations$postpon;
|
616
|
+
let {
|
617
|
+
newUser,
|
618
|
+
onApply,
|
619
|
+
onPostpone
|
620
|
+
} = _ref;
|
621
|
+
const {
|
622
|
+
translations
|
623
|
+
} = this.config;
|
624
|
+
this._createInitDeferred();
|
625
|
+
const done = () => {
|
626
|
+
this._initDeferred?.resolve?.();
|
627
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
628
|
+
hide?.();
|
629
|
+
};
|
630
|
+
const hide = this._authDialogService?.({
|
631
|
+
...this._service,
|
632
|
+
title: (_translations$youHave = translations?.youHaveLoggedInAs) !== null && _translations$youHave !== void 0 ? _translations$youHave : translate('youHaveLoggedInAs').replace('%userName%', (_newUser$name = newUser.name) !== null && _newUser$name !== void 0 ? _newUser$name : '').replace('{{userName}}', (_newUser$name2 = newUser.name) !== null && _newUser$name2 !== void 0 ? _newUser$name2 : ''),
|
633
|
+
loginCaption: (_translations$login = translations?.login) !== null && _translations$login !== void 0 ? _translations$login : translate('login'),
|
634
|
+
loginToCaption: (_translations$loginTo = translations?.loginTo) !== null && _translations$loginTo !== void 0 ? _translations$loginTo : translate('loginTo'),
|
635
|
+
confirmLabel: (_translations$applyCh = translations?.applyChange) !== null && _translations$applyCh !== void 0 ? _translations$applyCh : translate('applyChange'),
|
636
|
+
tryAgainLabel: (_translations$tryAgai = translations?.tryAgainLabel) !== null && _translations$tryAgai !== void 0 ? _translations$tryAgai : translate('tryAgainLabel'),
|
637
|
+
cancelLabel: (_translations$postpon = translations?.postpone) !== null && _translations$postpon !== void 0 ? _translations$postpon : translate('postpone'),
|
638
|
+
onConfirm: () => {
|
639
|
+
done();
|
640
|
+
onApply();
|
641
|
+
},
|
642
|
+
onCancel: () => {
|
643
|
+
done();
|
644
|
+
onPostpone();
|
645
|
+
}
|
646
|
+
});
|
647
|
+
}
|
648
|
+
_extractErrorMessage(error) {
|
649
|
+
let logError = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
650
|
+
if (!error) {
|
651
|
+
return null;
|
652
|
+
}
|
653
|
+
if (logError) {
|
654
|
+
// eslint-disable-next-line no-console
|
655
|
+
console.error('RingUI Auth error', error);
|
656
|
+
}
|
657
|
+
try {
|
658
|
+
// We've got some error from this list
|
659
|
+
// https://www.jetbrains.com/help/youtrack/devportal/OAuth-2.0-Errors.html
|
660
|
+
if ('code' in error && error.code && typeof error.code === 'object' && 'code' in error.code && typeof error.code.code === 'string') {
|
661
|
+
const readableCode = error.code.code.split('_').join(' ');
|
662
|
+
return `Authorization error: ${readableCode}`;
|
663
|
+
}
|
664
|
+
} catch {
|
665
|
+
// noop
|
1011
666
|
}
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
1015
|
-
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1021
|
-
|
1022
|
-
|
1023
|
-
canCancel = _ref6.canCancel,
|
1024
|
-
onTryAgain = _ref6.onTryAgain;
|
1025
|
-
var _this$config2 = this.config,
|
1026
|
-
embeddedLogin = _this$config2.embeddedLogin,
|
1027
|
-
onPostponeLogout = _this$config2.onPostponeLogout,
|
1028
|
-
translations = _this$config2.translations;
|
1029
|
-
var cancelable = ((_this$user2 = this.user) === null || _this$user2 === void 0 ? void 0 : _this$user2.guest) || canCancel;
|
1030
|
-
var actualTranslations = translations !== null && translations !== void 0 ? translations : getTranslations();
|
1031
|
-
this._createInitDeferred();
|
1032
|
-
var closeDialog = function closeDialog() {
|
667
|
+
return error.toString ? error.toString() : null;
|
668
|
+
}
|
669
|
+
_showBackendDownDialog(backendError) {
|
670
|
+
const {
|
671
|
+
onBackendDown,
|
672
|
+
translations
|
673
|
+
} = this.config;
|
674
|
+
const REPEAT_TIMEOUT = 5000;
|
675
|
+
let timerId;
|
676
|
+
return new Promise((resolve, reject) => {
|
677
|
+
const done = () => {
|
1033
678
|
/* eslint-disable @typescript-eslint/no-use-before-define */
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
679
|
+
hide();
|
680
|
+
window.removeEventListener('online', onCheckAgain);
|
681
|
+
stopListeningCloseMessage?.();
|
1037
682
|
/* eslint-enable @typescript-eslint/no-use-before-define */
|
683
|
+
this._storage?.sendMessage(Auth.CLOSE_BACKEND_DOWN_MESSAGE, Date.now());
|
684
|
+
clearTimeout(timerId);
|
1038
685
|
};
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1045
|
-
|
686
|
+
const stopListeningCloseMessage = this._storage?.onMessage(Auth.CLOSE_BACKEND_DOWN_MESSAGE, () => {
|
687
|
+
stopListeningCloseMessage?.();
|
688
|
+
done();
|
689
|
+
resolve();
|
690
|
+
});
|
691
|
+
const onCheckAgain = async () => {
|
692
|
+
await this._checkBackendsAreUp();
|
693
|
+
done();
|
694
|
+
resolve();
|
1046
695
|
};
|
1047
|
-
|
1048
|
-
|
1049
|
-
(
|
1050
|
-
(_this7$_storage = _this7._storage) === null || _this7$_storage === void 0 || _this7$_storage.sendMessage(Auth.CLOSE_WINDOW_MESSAGE, Date.now());
|
1051
|
-
closeDialog();
|
1052
|
-
if (!cancelable) {
|
1053
|
-
var _this7$_initDeferred, _this7$_initDeferred$;
|
1054
|
-
(_this7$_initDeferred = _this7._initDeferred) === null || _this7$_initDeferred === void 0 || (_this7$_initDeferred$ = _this7$_initDeferred.resolve) === null || _this7$_initDeferred$ === void 0 || _this7$_initDeferred$.call(_this7$_initDeferred);
|
1055
|
-
_this7.listeners.trigger(LOGOUT_POSTPONED_EVENT);
|
1056
|
-
onPostponeLogout();
|
1057
|
-
return;
|
1058
|
-
}
|
1059
|
-
if ((_this7$user = _this7.user) !== null && _this7$user !== void 0 && _this7$user.guest && nonInteractive) {
|
1060
|
-
_this7.forceTokenUpdate();
|
1061
|
-
} else {
|
1062
|
-
var _this7$_initDeferred2, _this7$_initDeferred3;
|
1063
|
-
(_this7$_initDeferred2 = _this7._initDeferred) === null || _this7$_initDeferred2 === void 0 || (_this7$_initDeferred3 = _this7$_initDeferred2.resolve) === null || _this7$_initDeferred3 === void 0 || _this7$_initDeferred3.call(_this7$_initDeferred2);
|
1064
|
-
}
|
696
|
+
const onPostpone = () => {
|
697
|
+
done();
|
698
|
+
reject(new Error('Auth(@jetbrains/ring-ui): postponed by user'));
|
1065
699
|
};
|
1066
|
-
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
1071
|
-
_context14.next = 2;
|
1072
|
-
return onTryAgain === null || onTryAgain === void 0 ? void 0 : onTryAgain();
|
1073
|
-
case 2:
|
1074
|
-
closeDialog();
|
1075
|
-
case 3:
|
1076
|
-
case "end":
|
1077
|
-
return _context14.stop();
|
1078
|
-
}
|
1079
|
-
}, _callee14);
|
1080
|
-
}));
|
1081
|
-
return function onTryAgainClick() {
|
1082
|
-
return _ref7.apply(this, arguments);
|
1083
|
-
};
|
1084
|
-
}();
|
1085
|
-
var hide = (_this$_authDialogServ = this._authDialogService) === null || _this$_authDialogServ === void 0 ? void 0 : _this$_authDialogServ.call(this, _objectSpread2(_objectSpread2({}, this._service), {}, {
|
1086
|
-
loginCaption: actualTranslations.login,
|
1087
|
-
loginToCaption: actualTranslations.loginTo,
|
1088
|
-
confirmLabel: actualTranslations.login,
|
1089
|
-
tryAgainLabel: actualTranslations.tryAgainLabel,
|
1090
|
-
cancelLabel: cancelable ? actualTranslations.cancel : actualTranslations.postpone,
|
1091
|
-
errorMessage: this._extractErrorMessage(error, true),
|
1092
|
-
onConfirm,
|
1093
|
-
onCancel,
|
1094
|
-
onTryAgain: onTryAgain ? onTryAgainClick : undefined
|
1095
|
-
}));
|
1096
|
-
var stopTokenListening = (_this$_storage8 = this._storage) === null || _this$_storage8 === void 0 ? void 0 : _this$_storage8.onTokenChange(function (token) {
|
1097
|
-
if (token) {
|
1098
|
-
var _this7$_initDeferred4, _this7$_initDeferred5;
|
1099
|
-
closeDialog();
|
1100
|
-
(_this7$_initDeferred4 = _this7._initDeferred) === null || _this7$_initDeferred4 === void 0 || (_this7$_initDeferred5 = _this7$_initDeferred4.resolve) === null || _this7$_initDeferred5 === void 0 || _this7$_initDeferred5.call(_this7$_initDeferred4);
|
1101
|
-
}
|
700
|
+
const hide = onBackendDown({
|
701
|
+
onCheckAgain,
|
702
|
+
onPostpone,
|
703
|
+
backendError,
|
704
|
+
translations: translations !== null && translations !== void 0 ? translations : getTranslationsWithFallback()
|
1102
705
|
});
|
1103
|
-
|
1104
|
-
|
1105
|
-
|
1106
|
-
|
1107
|
-
}
|
1108
|
-
}, {
|
1109
|
-
key: "_showUserChangedDialog",
|
1110
|
-
value: function _showUserChangedDialog(_ref8) {
|
1111
|
-
var _this8 = this,
|
1112
|
-
_this$_authDialogServ2,
|
1113
|
-
_translations$youHave,
|
1114
|
-
_newUser$name,
|
1115
|
-
_newUser$name2,
|
1116
|
-
_translations$login,
|
1117
|
-
_translations$loginTo,
|
1118
|
-
_translations$applyCh,
|
1119
|
-
_translations$tryAgai,
|
1120
|
-
_translations$postpon;
|
1121
|
-
var newUser = _ref8.newUser,
|
1122
|
-
onApply = _ref8.onApply,
|
1123
|
-
onPostpone = _ref8.onPostpone;
|
1124
|
-
var translations = this.config.translations;
|
1125
|
-
this._createInitDeferred();
|
1126
|
-
var done = function done() {
|
1127
|
-
var _this8$_initDeferred, _this8$_initDeferred$;
|
1128
|
-
(_this8$_initDeferred = _this8._initDeferred) === null || _this8$_initDeferred === void 0 || (_this8$_initDeferred$ = _this8$_initDeferred.resolve) === null || _this8$_initDeferred$ === void 0 || _this8$_initDeferred$.call(_this8$_initDeferred);
|
1129
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
1130
|
-
hide === null || hide === void 0 || hide();
|
1131
|
-
};
|
1132
|
-
var hide = (_this$_authDialogServ2 = this._authDialogService) === null || _this$_authDialogServ2 === void 0 ? void 0 : _this$_authDialogServ2.call(this, _objectSpread2(_objectSpread2({}, this._service), {}, {
|
1133
|
-
title: (_translations$youHave = translations === null || translations === void 0 ? void 0 : translations.youHaveLoggedInAs) !== null && _translations$youHave !== void 0 ? _translations$youHave : translate('youHaveLoggedInAs').replace('%userName%', (_newUser$name = newUser.name) !== null && _newUser$name !== void 0 ? _newUser$name : '').replace('{{userName}}', (_newUser$name2 = newUser.name) !== null && _newUser$name2 !== void 0 ? _newUser$name2 : ''),
|
1134
|
-
loginCaption: (_translations$login = translations === null || translations === void 0 ? void 0 : translations.login) !== null && _translations$login !== void 0 ? _translations$login : translate('login'),
|
1135
|
-
loginToCaption: (_translations$loginTo = translations === null || translations === void 0 ? void 0 : translations.loginTo) !== null && _translations$loginTo !== void 0 ? _translations$loginTo : translate('loginTo'),
|
1136
|
-
confirmLabel: (_translations$applyCh = translations === null || translations === void 0 ? void 0 : translations.applyChange) !== null && _translations$applyCh !== void 0 ? _translations$applyCh : translate('applyChange'),
|
1137
|
-
tryAgainLabel: (_translations$tryAgai = translations === null || translations === void 0 ? void 0 : translations.tryAgainLabel) !== null && _translations$tryAgai !== void 0 ? _translations$tryAgai : translate('tryAgainLabel'),
|
1138
|
-
cancelLabel: (_translations$postpon = translations === null || translations === void 0 ? void 0 : translations.postpone) !== null && _translations$postpon !== void 0 ? _translations$postpon : translate('postpone'),
|
1139
|
-
onConfirm: function onConfirm() {
|
1140
|
-
done();
|
1141
|
-
onApply();
|
1142
|
-
},
|
1143
|
-
onCancel: function onCancel() {
|
1144
|
-
done();
|
1145
|
-
onPostpone();
|
1146
|
-
}
|
1147
|
-
}));
|
1148
|
-
}
|
1149
|
-
}, {
|
1150
|
-
key: "_extractErrorMessage",
|
1151
|
-
value: function _extractErrorMessage(error) {
|
1152
|
-
var logError = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
1153
|
-
if (!error) {
|
1154
|
-
return null;
|
1155
|
-
}
|
1156
|
-
if (logError) {
|
1157
|
-
// eslint-disable-next-line no-console
|
1158
|
-
console.error('RingUI Auth error', error);
|
1159
|
-
}
|
1160
|
-
try {
|
1161
|
-
// We've got some error from this list
|
1162
|
-
// https://www.jetbrains.com/help/youtrack/devportal/OAuth-2.0-Errors.html
|
1163
|
-
if ('code' in error && error.code && typeof error.code === 'object' && 'code' in error.code && typeof error.code.code === 'string') {
|
1164
|
-
var readableCode = error.code.code.split('_').join(' ');
|
1165
|
-
return "Authorization error: ".concat(readableCode);
|
706
|
+
window.addEventListener('online', onCheckAgain);
|
707
|
+
function networkWatchdog() {
|
708
|
+
if (navigator && navigator.onLine) {
|
709
|
+
onCheckAgain();
|
1166
710
|
}
|
1167
|
-
|
1168
|
-
// noop
|
711
|
+
timerId = window.setTimeout(networkWatchdog, REPEAT_TIMEOUT);
|
1169
712
|
}
|
1170
|
-
|
713
|
+
timerId = window.setTimeout(networkWatchdog, REPEAT_TIMEOUT);
|
714
|
+
});
|
715
|
+
}
|
716
|
+
/**
|
717
|
+
* Wipe accessToken and redirect to auth page with required authorization
|
718
|
+
*/
|
719
|
+
async logout(extraParams) {
|
720
|
+
const requestParams = {
|
721
|
+
// eslint-disable-next-line camelcase
|
722
|
+
request_credentials: 'required',
|
723
|
+
...extraParams
|
724
|
+
};
|
725
|
+
await this._checkBackendsStatusesIfEnabled();
|
726
|
+
await this.listeners.trigger('logout');
|
727
|
+
this._updateDomainUser(null);
|
728
|
+
await this._storage?.wipeToken();
|
729
|
+
const authRequest = await this._requestBuilder?.prepareAuthRequest(requestParams);
|
730
|
+
if (authRequest != null) {
|
731
|
+
this._redirectCurrentPage(authRequest.url);
|
1171
732
|
}
|
1172
|
-
}
|
1173
|
-
|
1174
|
-
|
1175
|
-
|
1176
|
-
|
1177
|
-
|
1178
|
-
|
1179
|
-
|
1180
|
-
|
1181
|
-
|
1182
|
-
var _this9$_storage2;
|
1183
|
-
var done = function done() {
|
1184
|
-
var _this9$_storage;
|
1185
|
-
/* eslint-disable @typescript-eslint/no-use-before-define */
|
1186
|
-
hide();
|
1187
|
-
window.removeEventListener('online', onCheckAgain);
|
1188
|
-
stopListeningCloseMessage === null || stopListeningCloseMessage === void 0 || stopListeningCloseMessage();
|
1189
|
-
/* eslint-enable @typescript-eslint/no-use-before-define */
|
1190
|
-
(_this9$_storage = _this9._storage) === null || _this9$_storage === void 0 || _this9$_storage.sendMessage(Auth.CLOSE_BACKEND_DOWN_MESSAGE, Date.now());
|
1191
|
-
clearTimeout(timerId);
|
1192
|
-
};
|
1193
|
-
var stopListeningCloseMessage = (_this9$_storage2 = _this9._storage) === null || _this9$_storage2 === void 0 ? void 0 : _this9$_storage2.onMessage(Auth.CLOSE_BACKEND_DOWN_MESSAGE, function () {
|
1194
|
-
stopListeningCloseMessage === null || stopListeningCloseMessage === void 0 || stopListeningCloseMessage();
|
1195
|
-
done();
|
1196
|
-
resolve();
|
1197
|
-
});
|
1198
|
-
var onCheckAgain = /*#__PURE__*/function () {
|
1199
|
-
var _ref9 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
|
1200
|
-
return _regeneratorRuntime().wrap(function _callee15$(_context15) {
|
1201
|
-
while (1) switch (_context15.prev = _context15.next) {
|
1202
|
-
case 0:
|
1203
|
-
_context15.next = 2;
|
1204
|
-
return _this9._checkBackendsAreUp();
|
1205
|
-
case 2:
|
1206
|
-
done();
|
1207
|
-
resolve();
|
1208
|
-
case 4:
|
1209
|
-
case "end":
|
1210
|
-
return _context15.stop();
|
1211
|
-
}
|
1212
|
-
}, _callee15);
|
1213
|
-
}));
|
1214
|
-
return function onCheckAgain() {
|
1215
|
-
return _ref9.apply(this, arguments);
|
1216
|
-
};
|
1217
|
-
}();
|
1218
|
-
var onPostpone = function onPostpone() {
|
1219
|
-
done();
|
1220
|
-
reject(new Error('Auth(@jetbrains/ring-ui): postponed by user'));
|
1221
|
-
};
|
1222
|
-
var hide = onBackendDown({
|
1223
|
-
onCheckAgain,
|
1224
|
-
onPostpone,
|
1225
|
-
backendError,
|
1226
|
-
translations: translations !== null && translations !== void 0 ? translations : getTranslationsWithFallback()
|
1227
|
-
});
|
1228
|
-
window.addEventListener('online', onCheckAgain);
|
1229
|
-
function networkWatchdog() {
|
1230
|
-
if (navigator && navigator.onLine) {
|
1231
|
-
onCheckAgain();
|
1232
|
-
}
|
1233
|
-
timerId = window.setTimeout(networkWatchdog, REPEAT_TIMEOUT);
|
1234
|
-
}
|
1235
|
-
timerId = window.setTimeout(networkWatchdog, REPEAT_TIMEOUT);
|
1236
|
-
});
|
733
|
+
}
|
734
|
+
async _runEmbeddedLogin() {
|
735
|
+
this._storage?.sendMessage(Auth.CLOSE_WINDOW_MESSAGE, Date.now());
|
736
|
+
try {
|
737
|
+
this._isLoginWindowOpen = true;
|
738
|
+
return await this._embeddedFlow?.authorize();
|
739
|
+
} catch (e) {
|
740
|
+
throw e;
|
741
|
+
} finally {
|
742
|
+
this._isLoginWindowOpen = false;
|
1237
743
|
}
|
1238
|
-
|
1239
|
-
|
1240
|
-
|
1241
|
-
|
1242
|
-
|
1243
|
-
|
1244
|
-
|
1245
|
-
|
1246
|
-
|
1247
|
-
|
1248
|
-
|
1249
|
-
|
1250
|
-
|
1251
|
-
|
1252
|
-
|
1253
|
-
|
1254
|
-
|
1255
|
-
|
1256
|
-
|
1257
|
-
_context16.next = 5;
|
1258
|
-
return this.listeners.trigger('logout');
|
1259
|
-
case 5:
|
1260
|
-
this._updateDomainUser(null);
|
1261
|
-
_context16.next = 8;
|
1262
|
-
return (_this$_storage10 = this._storage) === null || _this$_storage10 === void 0 ? void 0 : _this$_storage10.wipeToken();
|
1263
|
-
case 8:
|
1264
|
-
_context16.next = 10;
|
1265
|
-
return (_this$_requestBuilder3 = this._requestBuilder) === null || _this$_requestBuilder3 === void 0 ? void 0 : _this$_requestBuilder3.prepareAuthRequest(requestParams);
|
1266
|
-
case 10:
|
1267
|
-
authRequest = _context16.sent;
|
1268
|
-
if (authRequest != null) {
|
1269
|
-
this._redirectCurrentPage(authRequest.url);
|
1270
|
-
}
|
1271
|
-
case 12:
|
1272
|
-
case "end":
|
1273
|
-
return _context16.stop();
|
1274
|
-
}
|
1275
|
-
}, _callee16, this);
|
1276
|
-
}));
|
1277
|
-
function logout(_x7) {
|
1278
|
-
return _logout.apply(this, arguments);
|
1279
|
-
}
|
1280
|
-
return logout;
|
1281
|
-
}())
|
1282
|
-
}, {
|
1283
|
-
key: "_runEmbeddedLogin",
|
1284
|
-
value: function () {
|
1285
|
-
var _runEmbeddedLogin2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
|
1286
|
-
var _this$_storage11;
|
1287
|
-
var _this$_embeddedFlow;
|
1288
|
-
return _regeneratorRuntime().wrap(function _callee17$(_context17) {
|
1289
|
-
while (1) switch (_context17.prev = _context17.next) {
|
1290
|
-
case 0:
|
1291
|
-
(_this$_storage11 = this._storage) === null || _this$_storage11 === void 0 || _this$_storage11.sendMessage(Auth.CLOSE_WINDOW_MESSAGE, Date.now());
|
1292
|
-
_context17.prev = 1;
|
1293
|
-
this._isLoginWindowOpen = true;
|
1294
|
-
_context17.next = 5;
|
1295
|
-
return (_this$_embeddedFlow = this._embeddedFlow) === null || _this$_embeddedFlow === void 0 ? void 0 : _this$_embeddedFlow.authorize();
|
1296
|
-
case 5:
|
1297
|
-
return _context17.abrupt("return", _context17.sent);
|
1298
|
-
case 8:
|
1299
|
-
_context17.prev = 8;
|
1300
|
-
_context17.t0 = _context17["catch"](1);
|
1301
|
-
throw _context17.t0;
|
1302
|
-
case 11:
|
1303
|
-
_context17.prev = 11;
|
1304
|
-
this._isLoginWindowOpen = false;
|
1305
|
-
return _context17.finish(11);
|
1306
|
-
case 14:
|
1307
|
-
case "end":
|
1308
|
-
return _context17.stop();
|
1309
|
-
}
|
1310
|
-
}, _callee17, this, [[1, 8, 11, 14]]);
|
1311
|
-
}));
|
1312
|
-
function _runEmbeddedLogin() {
|
1313
|
-
return _runEmbeddedLogin2.apply(this, arguments);
|
1314
|
-
}
|
1315
|
-
return _runEmbeddedLogin;
|
1316
|
-
}()
|
1317
|
-
/**
|
1318
|
-
* Wipe accessToken and redirect to auth page to obtain authorization data
|
1319
|
-
* if user is logged in or log her in otherwise
|
1320
|
-
*/
|
1321
|
-
}, {
|
1322
|
-
key: "login",
|
1323
|
-
value: (function () {
|
1324
|
-
var _login = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18() {
|
1325
|
-
var _this$_backgroundFlow3, accessToken, _user;
|
1326
|
-
return _regeneratorRuntime().wrap(function _callee18$(_context18) {
|
1327
|
-
while (1) switch (_context18.prev = _context18.next) {
|
1328
|
-
case 0:
|
1329
|
-
if (!this.config.embeddedLogin) {
|
1330
|
-
_context18.next = 4;
|
1331
|
-
break;
|
1332
|
-
}
|
1333
|
-
_context18.next = 3;
|
1334
|
-
return this._runEmbeddedLogin();
|
1335
|
-
case 3:
|
1336
|
-
return _context18.abrupt("return");
|
1337
|
-
case 4:
|
1338
|
-
_context18.next = 6;
|
1339
|
-
return this._checkBackendsStatusesIfEnabled();
|
1340
|
-
case 6:
|
1341
|
-
_context18.prev = 6;
|
1342
|
-
_context18.next = 9;
|
1343
|
-
return (_this$_backgroundFlow3 = this._backgroundFlow) === null || _this$_backgroundFlow3 === void 0 ? void 0 : _this$_backgroundFlow3.authorize();
|
1344
|
-
case 9:
|
1345
|
-
accessToken = _context18.sent;
|
1346
|
-
_context18.next = 12;
|
1347
|
-
return this.getUser(accessToken);
|
1348
|
-
case 12:
|
1349
|
-
_user = _context18.sent;
|
1350
|
-
if (_user.guest) {
|
1351
|
-
this._beforeLogout();
|
1352
|
-
} else {
|
1353
|
-
this.user = _user;
|
1354
|
-
this.listeners.trigger(USER_CHANGED_EVENT, _user);
|
1355
|
-
}
|
1356
|
-
_context18.next = 19;
|
1357
|
-
break;
|
1358
|
-
case 16:
|
1359
|
-
_context18.prev = 16;
|
1360
|
-
_context18.t0 = _context18["catch"](6);
|
1361
|
-
this._beforeLogout();
|
1362
|
-
case 19:
|
1363
|
-
case "end":
|
1364
|
-
return _context18.stop();
|
1365
|
-
}
|
1366
|
-
}, _callee18, this, [[6, 16]]);
|
1367
|
-
}));
|
1368
|
-
function login() {
|
1369
|
-
return _login.apply(this, arguments);
|
1370
|
-
}
|
1371
|
-
return login;
|
1372
|
-
}())
|
1373
|
-
}, {
|
1374
|
-
key: "switchUser",
|
1375
|
-
value: function () {
|
1376
|
-
var _switchUser = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
|
1377
|
-
return _regeneratorRuntime().wrap(function _callee19$(_context19) {
|
1378
|
-
while (1) switch (_context19.prev = _context19.next) {
|
1379
|
-
case 0:
|
1380
|
-
if (this.config.embeddedLogin) {
|
1381
|
-
_context19.next = 2;
|
1382
|
-
break;
|
1383
|
-
}
|
1384
|
-
throw new Error('Auth: switchUser only supported for "embeddedLogin" mode');
|
1385
|
-
case 2:
|
1386
|
-
_context19.next = 4;
|
1387
|
-
return this._runEmbeddedLogin();
|
1388
|
-
case 4:
|
1389
|
-
case "end":
|
1390
|
-
return _context19.stop();
|
1391
|
-
}
|
1392
|
-
}, _callee19, this);
|
1393
|
-
}));
|
1394
|
-
function switchUser() {
|
1395
|
-
return _switchUser.apply(this, arguments);
|
1396
|
-
}
|
1397
|
-
return switchUser;
|
1398
|
-
}()
|
1399
|
-
}, {
|
1400
|
-
key: "_makeStateFromResponse",
|
1401
|
-
value: function _makeStateFromResponse(authResponse) {
|
1402
|
-
var state = authResponse.state;
|
1403
|
-
if (!state) {
|
1404
|
-
return {};
|
744
|
+
}
|
745
|
+
/**
|
746
|
+
* Wipe accessToken and redirect to auth page to obtain authorization data
|
747
|
+
* if user is logged in or log her in otherwise
|
748
|
+
*/
|
749
|
+
async login() {
|
750
|
+
if (this.config.embeddedLogin) {
|
751
|
+
await this._runEmbeddedLogin();
|
752
|
+
return;
|
753
|
+
}
|
754
|
+
await this._checkBackendsStatusesIfEnabled();
|
755
|
+
try {
|
756
|
+
const accessToken = await this._backgroundFlow?.authorize();
|
757
|
+
const user = await this.getUser(accessToken);
|
758
|
+
if (user.guest) {
|
759
|
+
this._beforeLogout();
|
760
|
+
} else {
|
761
|
+
this.user = user;
|
762
|
+
this.listeners.trigger(USER_CHANGED_EVENT, user);
|
1405
763
|
}
|
1406
|
-
|
1407
|
-
|
1408
|
-
|
1409
|
-
|
1410
|
-
|
1411
|
-
|
1412
|
-
|
1413
|
-
|
1414
|
-
|
1415
|
-
|
1416
|
-
|
1417
|
-
|
764
|
+
} catch (e) {
|
765
|
+
this._beforeLogout();
|
766
|
+
}
|
767
|
+
}
|
768
|
+
async switchUser() {
|
769
|
+
if (!this.config.embeddedLogin) {
|
770
|
+
throw new Error('Auth: switchUser only supported for "embeddedLogin" mode');
|
771
|
+
}
|
772
|
+
await this._runEmbeddedLogin();
|
773
|
+
}
|
774
|
+
_makeStateFromResponse(authResponse) {
|
775
|
+
const {
|
776
|
+
state
|
777
|
+
} = authResponse;
|
778
|
+
if (!state) {
|
779
|
+
return {};
|
780
|
+
}
|
781
|
+
const {
|
782
|
+
scope: defaultScope
|
783
|
+
} = this.config;
|
784
|
+
try {
|
785
|
+
const urlFromState = new URL(state); // checking if state contains valid URL on same origin, see HUB-11514
|
786
|
+
if (urlFromState.origin !== window.location.origin) {
|
1418
787
|
return {};
|
1419
788
|
}
|
789
|
+
return {
|
790
|
+
restoreLocation: state,
|
791
|
+
created: Date.now(),
|
792
|
+
scopes: defaultScope
|
793
|
+
};
|
794
|
+
} catch (e) {
|
795
|
+
return {};
|
1420
796
|
}
|
1421
|
-
|
1422
|
-
|
1423
|
-
|
1424
|
-
|
1425
|
-
|
1426
|
-
|
1427
|
-
|
1428
|
-
|
1429
|
-
|
1430
|
-
|
1431
|
-
|
1432
|
-
|
1433
|
-
|
1434
|
-
|
1435
|
-
|
1436
|
-
|
1437
|
-
|
1438
|
-
|
1439
|
-
|
1440
|
-
|
1441
|
-
|
1442
|
-
|
1443
|
-
|
1444
|
-
|
1445
|
-
|
1446
|
-
|
1447
|
-
|
1448
|
-
|
1449
|
-
|
1450
|
-
|
1451
|
-
|
1452
|
-
|
1453
|
-
|
1454
|
-
|
1455
|
-
|
1456
|
-
|
1457
|
-
|
1458
|
-
|
1459
|
-
|
1460
|
-
case 11:
|
1461
|
-
newState = _context20.t0;
|
1462
|
-
scopes = scope ? scope.split(' ') : newState.scopes || defaultScope || [];
|
1463
|
-
effectiveExpiresIn = expiresIn ? parseInt(expiresIn, 10) : defaultExpiresIn;
|
1464
|
-
expires = TokenValidator._epoch() + effectiveExpiresIn;
|
1465
|
-
if (!(accessToken != null)) {
|
1466
|
-
_context20.next = 18;
|
1467
|
-
break;
|
1468
|
-
}
|
1469
|
-
_context20.next = 18;
|
1470
|
-
return (_this$_storage13 = this._storage) === null || _this$_storage13 === void 0 ? void 0 : _this$_storage13.saveToken({
|
1471
|
-
accessToken,
|
1472
|
-
scopes,
|
1473
|
-
expires,
|
1474
|
-
lifeTime: effectiveExpiresIn
|
1475
|
-
});
|
1476
|
-
case 18:
|
1477
|
-
return _context20.abrupt("return", newState);
|
1478
|
-
case 19:
|
1479
|
-
case "end":
|
1480
|
-
return _context20.stop();
|
1481
|
-
}
|
1482
|
-
}, _callee20, this);
|
1483
|
-
}));
|
1484
|
-
function _checkForAuthResponse() {
|
1485
|
-
return _checkForAuthResponse2.apply(this, arguments);
|
1486
|
-
}
|
1487
|
-
return _checkForAuthResponse;
|
1488
|
-
}())
|
1489
|
-
}, {
|
1490
|
-
key: "_checkForStateRestoration",
|
1491
|
-
value: function () {
|
1492
|
-
var _checkForStateRestoration2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
|
1493
|
-
var _this$_storage14;
|
1494
|
-
var authResponse, stateId;
|
1495
|
-
return _regeneratorRuntime().wrap(function _callee21$(_context21) {
|
1496
|
-
while (1) switch (_context21.prev = _context21.next) {
|
1497
|
-
case 0:
|
1498
|
-
authResponse = this._responseParser._authResponse;
|
1499
|
-
if (authResponse && this.config.cleanHash) {
|
1500
|
-
this.setHash('');
|
1501
|
-
}
|
1502
|
-
stateId = authResponse === null || authResponse === void 0 ? void 0 : authResponse.restoreAuthState;
|
1503
|
-
_context21.next = 5;
|
1504
|
-
return stateId && ((_this$_storage14 = this._storage) === null || _this$_storage14 === void 0 ? void 0 : _this$_storage14.getState(stateId));
|
1505
|
-
case 5:
|
1506
|
-
_context21.t0 = _context21.sent;
|
1507
|
-
if (_context21.t0) {
|
1508
|
-
_context21.next = 8;
|
1509
|
-
break;
|
1510
|
-
}
|
1511
|
-
_context21.t0 = {};
|
1512
|
-
case 8:
|
1513
|
-
return _context21.abrupt("return", _context21.t0);
|
1514
|
-
case 9:
|
1515
|
-
case "end":
|
1516
|
-
return _context21.stop();
|
1517
|
-
}
|
1518
|
-
}, _callee21, this);
|
1519
|
-
}));
|
1520
|
-
function _checkForStateRestoration() {
|
1521
|
-
return _checkForStateRestoration2.apply(this, arguments);
|
1522
|
-
}
|
1523
|
-
return _checkForStateRestoration;
|
1524
|
-
}()
|
1525
|
-
}, {
|
1526
|
-
key: "_checkBackendsAreUp",
|
1527
|
-
value: function _checkBackendsAreUp() {
|
1528
|
-
var abortCtrl = new AbortController();
|
1529
|
-
var backendCheckTimeout = this.config.backendCheckTimeout;
|
1530
|
-
return Promise.all([promiseWithTimeout(this.http.fetch('settings/public?fields=id', {
|
1531
|
-
signal: abortCtrl.signal
|
1532
|
-
}), backendCheckTimeout, {
|
1533
|
-
error: new Error('The authorization server is taking too long to respond. Please try again later.'),
|
1534
|
-
onTimeout: function onTimeout() {
|
1535
|
-
return abortCtrl.abort();
|
1536
|
-
}
|
1537
|
-
}), this.config.checkBackendIsUp()]).catch(function (err) {
|
1538
|
-
if (err instanceof TypeError) {
|
1539
|
-
throw new TypeError('Could not connect to the server due to network error. Please check your connection and try again.');
|
1540
|
-
}
|
1541
|
-
throw err;
|
797
|
+
}
|
798
|
+
/**
|
799
|
+
* Check if the hash contains an access token.
|
800
|
+
* If it does, extract the state, compare with
|
801
|
+
* config, and store the auth response for later use.
|
802
|
+
*
|
803
|
+
* @return {Promise} promise that is resolved to restoreLocation URL, or rejected
|
804
|
+
* @private
|
805
|
+
*/
|
806
|
+
async _checkForAuthResponse() {
|
807
|
+
// getAuthResponseURL may throw an exception
|
808
|
+
const authResponse = this._responseParser.getAuthResponseFromURL();
|
809
|
+
const {
|
810
|
+
scope: defaultScope,
|
811
|
+
defaultExpiresIn,
|
812
|
+
cleanHash
|
813
|
+
} = this.config;
|
814
|
+
if (authResponse && cleanHash) {
|
815
|
+
this.setHash('');
|
816
|
+
}
|
817
|
+
if (!authResponse) {
|
818
|
+
return undefined;
|
819
|
+
}
|
820
|
+
const {
|
821
|
+
state: stateId,
|
822
|
+
scope,
|
823
|
+
expiresIn,
|
824
|
+
accessToken
|
825
|
+
} = authResponse;
|
826
|
+
const newState = (await (stateId && this._storage?.getState(stateId))) || this._makeStateFromResponse(authResponse);
|
827
|
+
const scopes = scope ? scope.split(' ') : newState.scopes || defaultScope || [];
|
828
|
+
const effectiveExpiresIn = expiresIn ? parseInt(expiresIn, 10) : defaultExpiresIn;
|
829
|
+
const expires = TokenValidator._epoch() + effectiveExpiresIn;
|
830
|
+
if (accessToken != null) {
|
831
|
+
await this._storage?.saveToken({
|
832
|
+
accessToken,
|
833
|
+
scopes,
|
834
|
+
expires,
|
835
|
+
lifeTime: effectiveExpiresIn
|
1542
836
|
});
|
1543
837
|
}
|
1544
|
-
|
1545
|
-
|
1546
|
-
|
1547
|
-
|
1548
|
-
|
1549
|
-
|
1550
|
-
case 0:
|
1551
|
-
if (this.config.enableBackendStatusCheck) {
|
1552
|
-
_context22.next = 2;
|
1553
|
-
break;
|
1554
|
-
}
|
1555
|
-
return _context22.abrupt("return");
|
1556
|
-
case 2:
|
1557
|
-
_context22.prev = 2;
|
1558
|
-
_context22.next = 5;
|
1559
|
-
return this._checkBackendsAreUp();
|
1560
|
-
case 5:
|
1561
|
-
_context22.next = 12;
|
1562
|
-
break;
|
1563
|
-
case 7:
|
1564
|
-
_context22.prev = 7;
|
1565
|
-
_context22.t0 = _context22["catch"](2);
|
1566
|
-
if (!(_context22.t0 instanceof Error)) {
|
1567
|
-
_context22.next = 12;
|
1568
|
-
break;
|
1569
|
-
}
|
1570
|
-
_context22.next = 12;
|
1571
|
-
return this._showBackendDownDialog(_context22.t0);
|
1572
|
-
case 12:
|
1573
|
-
case "end":
|
1574
|
-
return _context22.stop();
|
1575
|
-
}
|
1576
|
-
}, _callee22, this, [[2, 7]]);
|
1577
|
-
}));
|
1578
|
-
function _checkBackendsStatusesIfEnabled() {
|
1579
|
-
return _checkBackendsStatusesIfEnabled2.apply(this, arguments);
|
1580
|
-
}
|
1581
|
-
return _checkBackendsStatusesIfEnabled;
|
1582
|
-
}()
|
1583
|
-
/**
|
1584
|
-
* Adds preconnect tag to help browser to establish connection to URL.
|
1585
|
-
* See https://w3c.github.io/resource-hints/
|
1586
|
-
* @param url Url to preconnect to.
|
1587
|
-
*/
|
1588
|
-
}, {
|
1589
|
-
key: "setUpPreconnect",
|
1590
|
-
value: function setUpPreconnect(url) {
|
1591
|
-
var linkNode = document.createElement('link');
|
1592
|
-
linkNode.rel = 'preconnect';
|
1593
|
-
linkNode.href = url;
|
1594
|
-
linkNode.pr = '1.0';
|
1595
|
-
linkNode.crossOrigin = 'use-credentials';
|
1596
|
-
document.head.appendChild(linkNode);
|
838
|
+
return newState;
|
839
|
+
}
|
840
|
+
async _checkForStateRestoration() {
|
841
|
+
const authResponse = this._responseParser._authResponse;
|
842
|
+
if (authResponse && this.config.cleanHash) {
|
843
|
+
this.setHash('');
|
1597
844
|
}
|
1598
|
-
|
1599
|
-
|
1600
|
-
|
1601
|
-
|
1602
|
-
|
1603
|
-
|
1604
|
-
|
1605
|
-
|
1606
|
-
|
1607
|
-
|
845
|
+
const stateId = authResponse?.restoreAuthState;
|
846
|
+
return (await (stateId && this._storage?.getState(stateId))) || {};
|
847
|
+
}
|
848
|
+
_checkBackendsAreUp() {
|
849
|
+
const abortCtrl = new AbortController();
|
850
|
+
const {
|
851
|
+
backendCheckTimeout
|
852
|
+
} = this.config;
|
853
|
+
return Promise.all([promiseWithTimeout(this.http.fetch('settings/public?fields=id', {
|
854
|
+
signal: abortCtrl.signal
|
855
|
+
}), backendCheckTimeout, {
|
856
|
+
error: new Error('The authorization server is taking too long to respond. Please try again later.'),
|
857
|
+
onTimeout: () => abortCtrl.abort()
|
858
|
+
}), this.config.checkBackendIsUp()]).catch(err => {
|
859
|
+
if (err instanceof TypeError) {
|
860
|
+
throw new TypeError('Could not connect to the server due to network error. Please check your connection and try again.');
|
1608
861
|
}
|
862
|
+
throw err;
|
863
|
+
});
|
864
|
+
}
|
865
|
+
async _checkBackendsStatusesIfEnabled() {
|
866
|
+
if (!this.config.enableBackendStatusCheck) {
|
867
|
+
return;
|
1609
868
|
}
|
1610
|
-
|
1611
|
-
|
1612
|
-
|
1613
|
-
|
1614
|
-
|
1615
|
-
|
1616
|
-
this._redirectCurrentPage(window.location.href);
|
869
|
+
try {
|
870
|
+
await this._checkBackendsAreUp();
|
871
|
+
} catch (backendDownErr) {
|
872
|
+
if (backendDownErr instanceof Error) {
|
873
|
+
await this._showBackendDownDialog(backendDownErr);
|
874
|
+
}
|
1617
875
|
}
|
1618
|
-
}
|
1619
|
-
|
1620
|
-
|
1621
|
-
|
876
|
+
}
|
877
|
+
/**
|
878
|
+
* Adds preconnect tag to help browser to establish connection to URL.
|
879
|
+
* See https://w3c.github.io/resource-hints/
|
880
|
+
* @param url Url to preconnect to.
|
881
|
+
*/
|
882
|
+
setUpPreconnect(url) {
|
883
|
+
const linkNode = document.createElement('link');
|
884
|
+
linkNode.rel = 'preconnect';
|
885
|
+
linkNode.href = url;
|
886
|
+
linkNode.pr = '1.0';
|
887
|
+
linkNode.crossOrigin = 'use-credentials';
|
888
|
+
document.head.appendChild(linkNode);
|
889
|
+
}
|
890
|
+
/**
|
891
|
+
* Redirects current page to the given URL
|
892
|
+
* @param {string} url
|
893
|
+
* @private
|
894
|
+
*/
|
895
|
+
_redirectCurrentPage(url) {
|
896
|
+
{
|
897
|
+
window.location.href = fixUrl(url);
|
1622
898
|
}
|
1623
|
-
|
1624
|
-
|
1625
|
-
|
1626
|
-
|
1627
|
-
|
1628
|
-
|
1629
|
-
|
1630
|
-
|
1631
|
-
|
1632
|
-
|
1633
|
-
|
1634
|
-
|
1635
|
-
|
1636
|
-
|
1637
|
-
|
1638
|
-
|
1639
|
-
|
1640
|
-
|
899
|
+
}
|
900
|
+
/**
|
901
|
+
* Reloads current page
|
902
|
+
*/
|
903
|
+
_reloadCurrentPage() {
|
904
|
+
this._redirectCurrentPage(window.location.href);
|
905
|
+
}
|
906
|
+
_canShowDialogs() {
|
907
|
+
return this.config.embeddedLogin && this._authDialogService;
|
908
|
+
}
|
909
|
+
/**
|
910
|
+
* Sets the location hash
|
911
|
+
* @param {string} hash
|
912
|
+
*/
|
913
|
+
setHash(hash) {
|
914
|
+
if (history.replaceState) {
|
915
|
+
// NB! History.replaceState is used here, because Firefox saves
|
916
|
+
// a record in history.
|
917
|
+
// NB! URL to redirect is formed manually because baseURI could be messed up,
|
918
|
+
// in which case it's not obvious where redirect will lead.
|
919
|
+
const cleanedUrl = [window.location.pathname, window.location.search].join('');
|
920
|
+
const hashIfExist = hash ? `#${hash}` : '';
|
921
|
+
history.replaceState(undefined, '', `${cleanedUrl}${hashIfExist}`);
|
922
|
+
} else {
|
923
|
+
window.location.hash = hash;
|
1641
924
|
}
|
1642
|
-
}
|
1643
|
-
}
|
1644
|
-
_defineProperty(Auth, "DEFAULT_CONFIG", DEFAULT_CONFIG);
|
1645
|
-
_defineProperty(Auth, "API_PATH", 'api/rest/');
|
1646
|
-
_defineProperty(Auth, "API_AUTH_PATH", 'oauth2/auth');
|
1647
|
-
_defineProperty(Auth, "API_PROFILE_PATH", 'users/me');
|
1648
|
-
_defineProperty(Auth, "CLOSE_BACKEND_DOWN_MESSAGE", 'backend-check-succeeded');
|
1649
|
-
_defineProperty(Auth, "CLOSE_WINDOW_MESSAGE", 'close-login-window');
|
1650
|
-
_defineProperty(Auth, "shouldRefreshToken", TokenValidator.shouldRefreshToken);
|
1651
|
-
_defineProperty(Auth, "storageIsUnavailable", !navigator.cookieEnabled);
|
925
|
+
}
|
926
|
+
}
|
1652
927
|
|
1653
928
|
export { DEFAULT_BACKGROUND_TIMEOUT, DEFAULT_EXPIRES_TIMEOUT, DOMAIN_USER_CHANGED_EVENT, LOGOUT_EVENT, LOGOUT_POSTPONED_EVENT, USER_CHANGED_EVENT, USER_CHANGE_POSTPONED_EVENT, Auth as default };
|