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