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