@webex/webex-core 3.0.0-beta.13 → 3.0.0-beta.131
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config.js +1 -11
- package/dist/config.js.map +1 -1
- package/dist/credentials-config.js +44 -64
- package/dist/credentials-config.js.map +1 -1
- package/dist/index.js +0 -76
- package/dist/index.js.map +1 -1
- package/dist/interceptors/auth.js +22 -55
- package/dist/interceptors/auth.js.map +1 -1
- package/dist/interceptors/default-options.js +0 -20
- package/dist/interceptors/default-options.js.map +1 -1
- package/dist/interceptors/embargo.js +0 -21
- package/dist/interceptors/embargo.js.map +1 -1
- package/dist/interceptors/network-timing.js +2 -21
- package/dist/interceptors/network-timing.js.map +1 -1
- package/dist/interceptors/payload-transformer.js +2 -22
- package/dist/interceptors/payload-transformer.js.map +1 -1
- package/dist/interceptors/rate-limit.js +25 -57
- package/dist/interceptors/rate-limit.js.map +1 -1
- package/dist/interceptors/redirect.js +4 -33
- package/dist/interceptors/redirect.js.map +1 -1
- package/dist/interceptors/request-event.js +3 -30
- package/dist/interceptors/request-event.js.map +1 -1
- package/dist/interceptors/request-logger.js +1 -30
- package/dist/interceptors/request-logger.js.map +1 -1
- package/dist/interceptors/request-timing.js +3 -22
- package/dist/interceptors/request-timing.js.map +1 -1
- package/dist/interceptors/response-logger.js +2 -31
- package/dist/interceptors/response-logger.js.map +1 -1
- package/dist/interceptors/user-agent.js +2 -29
- package/dist/interceptors/user-agent.js.map +1 -1
- package/dist/interceptors/webex-tracking-id.js +5 -28
- package/dist/interceptors/webex-tracking-id.js.map +1 -1
- package/dist/interceptors/webex-user-agent.js +5 -38
- package/dist/interceptors/webex-user-agent.js.map +1 -1
- package/dist/lib/batcher.js +3 -51
- package/dist/lib/batcher.js.map +1 -1
- package/dist/lib/credentials/credentials.js +55 -119
- package/dist/lib/credentials/credentials.js.map +1 -1
- package/dist/lib/credentials/grant-errors.js +0 -49
- package/dist/lib/credentials/grant-errors.js.map +1 -1
- package/dist/lib/credentials/index.js +1 -13
- package/dist/lib/credentials/index.js.map +1 -1
- package/dist/lib/credentials/scope.js +1 -7
- package/dist/lib/credentials/scope.js.map +1 -1
- package/dist/lib/credentials/token-collection.js +1 -7
- package/dist/lib/credentials/token-collection.js.map +1 -1
- package/dist/lib/credentials/token.js +39 -118
- package/dist/lib/credentials/token.js.map +1 -1
- package/dist/lib/page.js +13 -26
- package/dist/lib/page.js.map +1 -1
- package/dist/lib/services/constants.js +0 -2
- package/dist/lib/services/constants.js.map +1 -1
- package/dist/lib/services/index.js +1 -28
- package/dist/lib/services/index.js.map +1 -1
- package/dist/lib/services/interceptors/server-error.js +2 -23
- package/dist/lib/services/interceptors/server-error.js.map +1 -1
- package/dist/lib/services/interceptors/service.js +12 -34
- package/dist/lib/services/interceptors/service.js.map +1 -1
- package/dist/lib/services/metrics.js +0 -2
- package/dist/lib/services/metrics.js.map +1 -1
- package/dist/lib/services/service-catalog.js +10 -90
- package/dist/lib/services/service-catalog.js.map +1 -1
- package/dist/lib/services/service-fed-ramp.js +0 -2
- package/dist/lib/services/service-fed-ramp.js.map +1 -1
- package/dist/lib/services/service-host.js +47 -62
- package/dist/lib/services/service-host.js.map +1 -1
- package/dist/lib/services/service-registry.js +78 -90
- package/dist/lib/services/service-registry.js.map +1 -1
- package/dist/lib/services/service-state.js +3 -15
- package/dist/lib/services/service-state.js.map +1 -1
- package/dist/lib/services/service-url.js +4 -25
- package/dist/lib/services/service-url.js.map +1 -1
- package/dist/lib/services/services.js +122 -238
- package/dist/lib/services/services.js.map +1 -1
- package/dist/lib/stateless-webex-plugin.js +5 -28
- package/dist/lib/stateless-webex-plugin.js.map +1 -1
- package/dist/lib/storage/decorators.js +19 -62
- package/dist/lib/storage/decorators.js.map +1 -1
- package/dist/lib/storage/errors.js +0 -23
- package/dist/lib/storage/errors.js.map +1 -1
- package/dist/lib/storage/index.js +2 -16
- package/dist/lib/storage/index.js.map +1 -1
- package/dist/lib/storage/make-webex-plugin-store.js +11 -41
- package/dist/lib/storage/make-webex-plugin-store.js.map +1 -1
- package/dist/lib/storage/make-webex-store.js +8 -30
- package/dist/lib/storage/make-webex-store.js.map +1 -1
- package/dist/lib/storage/memory-store-adapter.js +1 -19
- package/dist/lib/storage/memory-store-adapter.js.map +1 -1
- package/dist/lib/webex-core-plugin-mixin.js +9 -29
- package/dist/lib/webex-core-plugin-mixin.js.map +1 -1
- package/dist/lib/webex-http-error.js +1 -31
- package/dist/lib/webex-http-error.js.map +1 -1
- package/dist/lib/webex-internal-core-plugin-mixin.js +9 -29
- package/dist/lib/webex-internal-core-plugin-mixin.js.map +1 -1
- package/dist/lib/webex-plugin.js +6 -40
- package/dist/lib/webex-plugin.js.map +1 -1
- package/dist/plugins/logger.js +3 -17
- package/dist/plugins/logger.js.map +1 -1
- package/dist/webex-core.js +79 -203
- package/dist/webex-core.js.map +1 -1
- package/dist/webex-internal-core.js +0 -10
- package/dist/webex-internal-core.js.map +1 -1
- package/package.json +14 -14
- package/src/config.js +9 -11
- package/src/credentials-config.js +110 -72
- package/src/index.js +4 -14
- package/src/interceptors/auth.js +36 -37
- package/src/interceptors/default-options.js +0 -1
- package/src/interceptors/embargo.js +1 -1
- package/src/interceptors/payload-transformer.js +1 -2
- package/src/interceptors/rate-limit.js +8 -5
- package/src/interceptors/redirect.js +14 -8
- package/src/interceptors/request-event.js +4 -8
- package/src/interceptors/request-logger.js +8 -5
- package/src/interceptors/response-logger.js +11 -8
- package/src/interceptors/user-agent.js +1 -2
- package/src/interceptors/webex-user-agent.js +3 -9
- package/src/lib/batcher.js +70 -69
- package/src/lib/credentials/credentials.js +131 -122
- package/src/lib/credentials/grant-errors.js +6 -7
- package/src/lib/credentials/index.js +1 -4
- package/src/lib/credentials/scope.js +1 -4
- package/src/lib/credentials/token-collection.js +1 -1
- package/src/lib/credentials/token.js +86 -80
- package/src/lib/page.js +10 -11
- package/src/lib/services/constants.js +3 -13
- package/src/lib/services/index.js +2 -2
- package/src/lib/services/interceptors/server-error.js +12 -7
- package/src/lib/services/interceptors/service.js +6 -5
- package/src/lib/services/metrics.js +1 -1
- package/src/lib/services/service-catalog.js +110 -100
- package/src/lib/services/service-fed-ramp.js +1 -2
- package/src/lib/services/service-host.js +10 -17
- package/src/lib/services/service-registry.js +69 -96
- package/src/lib/services/service-state.js +4 -6
- package/src/lib/services/service-url.js +24 -23
- package/src/lib/services/services.js +260 -251
- package/src/lib/stateless-webex-plugin.js +4 -2
- package/src/lib/storage/decorators.js +68 -66
- package/src/lib/storage/index.js +4 -6
- package/src/lib/storage/make-webex-plugin-store.js +34 -21
- package/src/lib/storage/make-webex-store.js +6 -7
- package/src/lib/storage/memory-store-adapter.js +3 -3
- package/src/lib/webex-core-plugin-mixin.js +10 -7
- package/src/lib/webex-http-error.js +7 -8
- package/src/lib/webex-internal-core-plugin-mixin.js +9 -6
- package/src/lib/webex-plugin.js +41 -34
- package/src/plugins/logger.js +8 -3
- package/src/webex-core.js +185 -116
- package/src/webex-internal-core.js +15 -9
- package/test/integration/spec/credentials/credentials.js +26 -30
- package/test/integration/spec/credentials/token.js +36 -33
- package/test/integration/spec/services/service-catalog.js +177 -156
- package/test/integration/spec/services/services.js +313 -304
- package/test/integration/spec/webex-core.js +98 -86
- package/test/unit/spec/_setup.js +26 -18
- package/test/unit/spec/credentials/credentials.js +217 -154
- package/test/unit/spec/credentials/token.js +94 -76
- package/test/unit/spec/interceptors/auth.js +291 -243
- package/test/unit/spec/interceptors/default-options.js +36 -24
- package/test/unit/spec/interceptors/embargo.js +32 -27
- package/test/unit/spec/interceptors/network-timing.js +2 -2
- package/test/unit/spec/interceptors/payload-transformer.js +61 -52
- package/test/unit/spec/interceptors/rate-limit.js +104 -75
- package/test/unit/spec/interceptors/redirect.js +22 -20
- package/test/unit/spec/interceptors/request-timing.js +18 -22
- package/test/unit/spec/interceptors/user-agent.js +28 -16
- package/test/unit/spec/interceptors/webex-tracking-id.js +14 -8
- package/test/unit/spec/interceptors/webex-user-agent.js +83 -37
- package/test/unit/spec/lib/batcher.js +36 -32
- package/test/unit/spec/lib/page.js +36 -32
- package/test/unit/spec/lib/webex-plugin.js +1 -1
- package/test/unit/spec/services/interceptors/server-error.js +67 -90
- package/test/unit/spec/services/interceptors/service.js +17 -28
- package/test/unit/spec/services/service-catalog.js +19 -27
- package/test/unit/spec/services/service-host.js +29 -26
- package/test/unit/spec/services/service-registry.js +128 -170
- package/test/unit/spec/services/service-state.js +13 -22
- package/test/unit/spec/services/service-url.js +24 -43
- package/test/unit/spec/services/services.js +85 -41
- package/test/unit/spec/storage/persist.js +6 -9
- package/test/unit/spec/storage/wait-for-value.js +22 -21
- package/test/unit/spec/webex-core.js +78 -57
- package/test/unit/spec/webex-internal-core.js +56 -31
|
@@ -1,65 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _Object$keys2 = require("@babel/runtime-corejs2/core-js/object/keys");
|
|
4
|
+
var _Object$getOwnPropertySymbols = require("@babel/runtime-corejs2/core-js/object/get-own-property-symbols");
|
|
5
|
+
var _Object$getOwnPropertyDescriptor2 = require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptor");
|
|
6
|
+
var _Object$getOwnPropertyDescriptors = require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptors");
|
|
7
|
+
var _Object$defineProperties = require("@babel/runtime-corejs2/core-js/object/define-properties");
|
|
3
8
|
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
|
|
4
|
-
|
|
5
9
|
var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
|
|
6
|
-
|
|
7
10
|
_Object$defineProperty(exports, "__esModule", {
|
|
8
11
|
value: true
|
|
9
12
|
});
|
|
10
|
-
|
|
11
13
|
exports.default = void 0;
|
|
12
|
-
|
|
13
14
|
var _deleteProperty = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/reflect/delete-property"));
|
|
14
|
-
|
|
15
15
|
var _stringify = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/json/stringify"));
|
|
16
|
-
|
|
17
|
-
var _assign = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/assign"));
|
|
18
|
-
|
|
19
16
|
var _keys = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/keys"));
|
|
20
|
-
|
|
21
17
|
var _apply = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/reflect/apply"));
|
|
22
|
-
|
|
23
18
|
var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
|
|
24
|
-
|
|
25
19
|
var _now = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/date/now"));
|
|
26
|
-
|
|
27
20
|
var _getOwnPropertyDescriptor = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptor"));
|
|
28
|
-
|
|
21
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/defineProperty"));
|
|
29
22
|
var _applyDecoratedDescriptor2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/applyDecoratedDescriptor"));
|
|
30
|
-
|
|
31
23
|
var _isEmpty2 = _interopRequireDefault(require("lodash/isEmpty"));
|
|
32
|
-
|
|
33
24
|
var _isObject2 = _interopRequireDefault(require("lodash/isObject"));
|
|
34
|
-
|
|
35
25
|
var _cloneDeep2 = _interopRequireDefault(require("lodash/cloneDeep"));
|
|
36
|
-
|
|
37
26
|
var _clone2 = _interopRequireDefault(require("lodash/clone"));
|
|
38
|
-
|
|
39
27
|
var _querystring = _interopRequireDefault(require("querystring"));
|
|
40
|
-
|
|
41
28
|
var _url = _interopRequireDefault(require("url"));
|
|
42
|
-
|
|
43
29
|
var _jsonwebtoken = _interopRequireDefault(require("jsonwebtoken"));
|
|
44
|
-
|
|
45
30
|
var _common = require("@webex/common");
|
|
46
|
-
|
|
47
31
|
var _commonTimers = require("@webex/common-timers");
|
|
48
|
-
|
|
49
32
|
var _webexPlugin = _interopRequireDefault(require("../webex-plugin"));
|
|
50
|
-
|
|
51
33
|
var _decorators = require("../storage/decorators");
|
|
52
|
-
|
|
53
34
|
var _grantErrors = _interopRequireDefault(require("./grant-errors"));
|
|
54
|
-
|
|
55
35
|
var _scope = require("./scope");
|
|
56
|
-
|
|
57
36
|
var _token = _interopRequireDefault(require("./token"));
|
|
58
|
-
|
|
59
37
|
var _tokenCollection = _interopRequireDefault(require("./token-collection"));
|
|
60
|
-
|
|
61
38
|
var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _obj;
|
|
62
|
-
|
|
39
|
+
function ownKeys(object, enumerableOnly) { var keys = _Object$keys2(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return _Object$getOwnPropertyDescriptor2(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
40
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor2(source, key)); }); } return target; }
|
|
63
41
|
/**
|
|
64
42
|
* @class
|
|
65
43
|
*/
|
|
@@ -88,9 +66,24 @@ var Credentials = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
|
|
|
88
66
|
if (this.config.jwtRefreshCallback) {
|
|
89
67
|
return true;
|
|
90
68
|
}
|
|
91
|
-
|
|
92
69
|
return Boolean(this.supertoken && this.supertoken.canRefresh);
|
|
93
70
|
}
|
|
71
|
+
},
|
|
72
|
+
isUnverifiedGuest: {
|
|
73
|
+
deps: ['supertoken'],
|
|
74
|
+
/**
|
|
75
|
+
* Returns true if the user is an unverified guest
|
|
76
|
+
* @returns {boolean}
|
|
77
|
+
*/
|
|
78
|
+
fn: function fn() {
|
|
79
|
+
var isGuest = false;
|
|
80
|
+
try {
|
|
81
|
+
isGuest = JSON.parse(_common.base64.decode(this.supertoken.access_token.split('.')[1])).user_type === 'guest';
|
|
82
|
+
} catch (_unused) {
|
|
83
|
+
/* the non-guest token is formatted differently so catch is expected */
|
|
84
|
+
}
|
|
85
|
+
return isGuest;
|
|
86
|
+
}
|
|
94
87
|
}
|
|
95
88
|
},
|
|
96
89
|
props: {
|
|
@@ -102,7 +95,6 @@ var Credentials = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
|
|
|
102
95
|
default: false,
|
|
103
96
|
type: 'boolean'
|
|
104
97
|
},
|
|
105
|
-
|
|
106
98
|
/**
|
|
107
99
|
* Becomes `true` once the {@link loaded} event fires.
|
|
108
100
|
* @see {@link WebexPlugin#ready}
|
|
@@ -119,7 +111,6 @@ var Credentials = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
|
|
|
119
111
|
type: 'any'
|
|
120
112
|
}
|
|
121
113
|
},
|
|
122
|
-
|
|
123
114
|
/**
|
|
124
115
|
* Generates an OAuth Login URL. Prefers the api.ciscospark.com proxy if the
|
|
125
116
|
* instance is initialize with an authorizatUrl, but fallsback to idbroker
|
|
@@ -133,23 +124,18 @@ var Credentials = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
|
|
|
133
124
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
|
134
125
|
clientType: 'public'
|
|
135
126
|
};
|
|
136
|
-
|
|
137
127
|
/* eslint-disable camelcase */
|
|
138
128
|
if (options.state && !(0, _isObject2.default)(options.state)) {
|
|
139
129
|
throw new Error('if specified, `options.state` must be an object');
|
|
140
130
|
}
|
|
141
|
-
|
|
142
131
|
options.client_id = this.config.client_id;
|
|
143
132
|
options.redirect_uri = this.config.redirect_uri;
|
|
144
133
|
options.scope = this.config.scope;
|
|
145
134
|
options = (0, _cloneDeep2.default)(options);
|
|
146
|
-
|
|
147
135
|
if (!options.response_type) {
|
|
148
136
|
options.response_type = options.clientType === 'public' ? 'token' : 'code';
|
|
149
137
|
}
|
|
150
|
-
|
|
151
138
|
(0, _deleteProperty.default)(options, 'clientType');
|
|
152
|
-
|
|
153
139
|
if (options.state) {
|
|
154
140
|
if (!(0, _isEmpty2.default)(options.state)) {
|
|
155
141
|
options.state = _common.base64.toBase64Url((0, _stringify.default)(options.state));
|
|
@@ -157,11 +143,9 @@ var Credentials = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
|
|
|
157
143
|
delete options.state;
|
|
158
144
|
}
|
|
159
145
|
}
|
|
160
|
-
|
|
161
146
|
return "".concat(this.config.authorizeUrl, "?").concat(_querystring.default.stringify(options));
|
|
162
147
|
/* eslint-enable camelcase */
|
|
163
148
|
},
|
|
164
|
-
|
|
165
149
|
/**
|
|
166
150
|
* Get the determined OrgId.
|
|
167
151
|
*
|
|
@@ -170,7 +154,6 @@ var Credentials = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
|
|
|
170
154
|
*/
|
|
171
155
|
getOrgId: function getOrgId() {
|
|
172
156
|
this.logger.info('credentials: attempting to retrieve the OrgId from token');
|
|
173
|
-
|
|
174
157
|
try {
|
|
175
158
|
// Attempt to extract a client-authenticated token's OrgId.
|
|
176
159
|
this.logger.info('credentials: trying to extract OrgId from JWT');
|
|
@@ -179,10 +162,8 @@ var Credentials = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
|
|
|
179
162
|
// Attempt to extract a user token's OrgId.
|
|
180
163
|
this.logger.info('credentials: could not extract OrgId from JWT');
|
|
181
164
|
this.logger.info('credentials: attempting to extract OrgId from user token');
|
|
182
|
-
|
|
183
165
|
try {
|
|
184
166
|
var _this$supertoken;
|
|
185
|
-
|
|
186
167
|
return this.extractOrgIdFromUserToken((_this$supertoken = this.supertoken) === null || _this$supertoken === void 0 ? void 0 : _this$supertoken.access_token);
|
|
187
168
|
} catch (f) {
|
|
188
169
|
this.logger.info('credentials: could not extract OrgId from user token');
|
|
@@ -190,7 +171,6 @@ var Credentials = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
|
|
|
190
171
|
}
|
|
191
172
|
}
|
|
192
173
|
},
|
|
193
|
-
|
|
194
174
|
/**
|
|
195
175
|
* Extract the OrgId [realm] from a provided JWT.
|
|
196
176
|
*
|
|
@@ -201,23 +181,20 @@ var Credentials = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
|
|
|
201
181
|
*/
|
|
202
182
|
extractOrgIdFromJWT: function extractOrgIdFromJWT() {
|
|
203
183
|
var token = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
204
|
-
|
|
205
184
|
// Decoded the provided token.
|
|
206
|
-
var decodedJWT = _jsonwebtoken.default.decode(token);
|
|
207
|
-
|
|
185
|
+
var decodedJWT = _jsonwebtoken.default.decode(token);
|
|
208
186
|
|
|
187
|
+
// Validate that the provided token is a JWT.
|
|
209
188
|
if (!decodedJWT) {
|
|
210
189
|
throw new Error('unable to extract the OrgId from the provided JWT');
|
|
211
190
|
}
|
|
212
|
-
|
|
213
191
|
if (!decodedJWT.realm) {
|
|
214
192
|
throw new Error('the provided JWT does not contain an OrgId');
|
|
215
|
-
}
|
|
216
|
-
|
|
193
|
+
}
|
|
217
194
|
|
|
195
|
+
// Return the OrgId [realm].
|
|
218
196
|
return decodedJWT.realm;
|
|
219
197
|
},
|
|
220
|
-
|
|
221
198
|
/**
|
|
222
199
|
* Extract the OrgId [realm] from a provided user token.
|
|
223
200
|
*
|
|
@@ -229,16 +206,16 @@ var Credentials = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
|
|
|
229
206
|
extractOrgIdFromUserToken: function extractOrgIdFromUserToken() {
|
|
230
207
|
var token = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
231
208
|
// Split the provided token into subsections.
|
|
232
|
-
var fields = token.split('_');
|
|
209
|
+
var fields = token.split('_');
|
|
233
210
|
|
|
211
|
+
// Validate that the provided token has the proper amount of sections.
|
|
234
212
|
if (fields.length !== 3) {
|
|
235
213
|
throw new Error('the provided token is not a valid format');
|
|
236
|
-
}
|
|
237
|
-
|
|
214
|
+
}
|
|
238
215
|
|
|
216
|
+
// Return the token section that contains the OrgId.
|
|
239
217
|
return fields[2];
|
|
240
218
|
},
|
|
241
|
-
|
|
242
219
|
/**
|
|
243
220
|
* Generates a Logout URL
|
|
244
221
|
* @instance
|
|
@@ -248,12 +225,11 @@ var Credentials = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
|
|
|
248
225
|
*/
|
|
249
226
|
buildLogoutUrl: function buildLogoutUrl() {
|
|
250
227
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
251
|
-
return "".concat(this.config.logoutUrl, "?").concat(_querystring.default.stringify((
|
|
228
|
+
return "".concat(this.config.logoutUrl, "?").concat(_querystring.default.stringify(_objectSpread({
|
|
252
229
|
cisService: this.config.service,
|
|
253
230
|
goto: this.config.redirect_uri
|
|
254
231
|
}, options)));
|
|
255
232
|
},
|
|
256
|
-
|
|
257
233
|
/**
|
|
258
234
|
* Generates a number between 60% - 90% of expired value
|
|
259
235
|
* @instance
|
|
@@ -267,7 +243,6 @@ var Credentials = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
|
|
|
267
243
|
},
|
|
268
244
|
constructor: function constructor() {
|
|
269
245
|
var _this = this;
|
|
270
|
-
|
|
271
246
|
// HACK to deal with the fact that AmpersandState#dataTypes#set is a pure
|
|
272
247
|
// function.
|
|
273
248
|
this._dataTypes = (0, _cloneDeep2.default)(this._dataTypes);
|
|
@@ -275,15 +250,13 @@ var Credentials = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
|
|
|
275
250
|
if (_this._dataTypes[key].set) {
|
|
276
251
|
_this._dataTypes[key].set = _this._dataTypes[key].set.bind(_this);
|
|
277
252
|
}
|
|
278
|
-
});
|
|
279
|
-
|
|
253
|
+
});
|
|
254
|
+
// END HACK
|
|
280
255
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
281
256
|
args[_key] = arguments[_key];
|
|
282
257
|
}
|
|
283
|
-
|
|
284
258
|
(0, _apply.default)(_webexPlugin.default, this, args);
|
|
285
259
|
},
|
|
286
|
-
|
|
287
260
|
/**
|
|
288
261
|
* Downscopes a token
|
|
289
262
|
* @instance
|
|
@@ -294,20 +267,16 @@ var Credentials = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
|
|
|
294
267
|
*/
|
|
295
268
|
downscope: function downscope(scope) {
|
|
296
269
|
var _this2 = this;
|
|
297
|
-
|
|
298
270
|
return this.supertoken.downscope(scope).catch(function (reason) {
|
|
299
271
|
_this2.logger.trace("credentials: failed to downscope supertoken to ".concat(scope), reason);
|
|
300
|
-
|
|
301
272
|
_this2.logger.trace("credentials: falling back to supertoken for ".concat(scope));
|
|
302
|
-
|
|
303
|
-
return _promise.default.resolve(new _token.default((0, _assign.default)({
|
|
273
|
+
return _promise.default.resolve(new _token.default(_objectSpread({
|
|
304
274
|
scope: scope
|
|
305
275
|
}, _this2.supertoken.serialize())), {
|
|
306
276
|
parent: _this2
|
|
307
277
|
});
|
|
308
278
|
});
|
|
309
279
|
},
|
|
310
|
-
|
|
311
280
|
/**
|
|
312
281
|
* Requests a client credentials grant and returns the token. Given the
|
|
313
282
|
* limited use for such tokens as this time, this method does not cache its
|
|
@@ -319,7 +288,6 @@ var Credentials = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
|
|
|
319
288
|
*/
|
|
320
289
|
getClientToken: function getClientToken() {
|
|
321
290
|
var _this3 = this;
|
|
322
|
-
|
|
323
291
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
324
292
|
this.logger.info('credentials: requesting client credentials grant');
|
|
325
293
|
return this.webex.request({
|
|
@@ -338,7 +306,6 @@ var Credentials = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
|
|
|
338
306
|
},
|
|
339
307
|
shouldRefreshAccessToken: false
|
|
340
308
|
/* eslint-enable camelcase */
|
|
341
|
-
|
|
342
309
|
}).then(function (res) {
|
|
343
310
|
return new _token.default(res.body, {
|
|
344
311
|
parent: _this3
|
|
@@ -347,13 +314,10 @@ var Credentials = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
|
|
|
347
314
|
if (res.statusCode !== 400) {
|
|
348
315
|
return _promise.default.reject(res);
|
|
349
316
|
}
|
|
350
|
-
|
|
351
317
|
var ErrorConstructor = _grantErrors.default.select(res.body.error);
|
|
352
|
-
|
|
353
318
|
return _promise.default.reject(new ErrorConstructor(res._res || res));
|
|
354
319
|
});
|
|
355
320
|
},
|
|
356
|
-
|
|
357
321
|
/**
|
|
358
322
|
* Resolves with a token with the specified scopes. If no scope is specified,
|
|
359
323
|
* defaults to omit(webex.credentials.scope, 'spark:kms'). If no such token is
|
|
@@ -365,46 +329,36 @@ var Credentials = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
|
|
|
365
329
|
*/
|
|
366
330
|
getUserToken: function getUserToken(scope) {
|
|
367
331
|
var _this4 = this;
|
|
368
|
-
|
|
369
332
|
return _promise.default.resolve(!this.isRefreshing || new _promise.default(function (resolve) {
|
|
370
333
|
_this4.logger.info('credentials: token refresh inflight; delaying getUserToken until refresh completes');
|
|
371
|
-
|
|
372
334
|
_this4.once('change:isRefreshing', function () {
|
|
373
335
|
_this4.logger.info('credentials: token refresh complete; reinvoking getUserToken');
|
|
374
|
-
|
|
375
336
|
resolve();
|
|
376
337
|
});
|
|
377
338
|
})).then(function () {
|
|
378
339
|
if (!_this4.canAuthorize) {
|
|
379
340
|
_this4.logger.info('credentials: cannot produce an access token from current state');
|
|
380
|
-
|
|
381
341
|
return _promise.default.reject(new Error('Current state cannot produce an access token'));
|
|
382
342
|
}
|
|
383
|
-
|
|
384
343
|
if (!scope) {
|
|
385
344
|
scope = (0, _scope.filterScope)('spark:kms', _this4.config.scope);
|
|
386
345
|
}
|
|
387
|
-
|
|
388
346
|
scope = (0, _scope.sortScope)(scope);
|
|
389
|
-
|
|
390
347
|
if (scope === (0, _scope.sortScope)(_this4.config.scope)) {
|
|
391
348
|
return _promise.default.resolve(_this4.supertoken);
|
|
392
349
|
}
|
|
350
|
+
var token = _this4.userTokens.get(scope);
|
|
393
351
|
|
|
394
|
-
|
|
352
|
+
// we should also check for the token.access_token since token object does
|
|
395
353
|
// not get cleared on unsetting while logging out.
|
|
396
|
-
|
|
397
|
-
|
|
398
354
|
if (!token || !token.access_token) {
|
|
399
355
|
return _this4.downscope(scope).then((0, _common.tap)(function (t) {
|
|
400
356
|
return _this4.userTokens.add(t);
|
|
401
357
|
}));
|
|
402
358
|
}
|
|
403
|
-
|
|
404
359
|
return _promise.default.resolve(token);
|
|
405
360
|
});
|
|
406
361
|
},
|
|
407
|
-
|
|
408
362
|
/**
|
|
409
363
|
* Initializer
|
|
410
364
|
* @instance
|
|
@@ -416,37 +370,32 @@ var Credentials = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
|
|
|
416
370
|
*/
|
|
417
371
|
initialize: function initialize(attrs, options) {
|
|
418
372
|
var _this5 = this;
|
|
419
|
-
|
|
420
373
|
if (attrs) {
|
|
421
374
|
if (typeof attrs === 'string') {
|
|
422
375
|
this.supertoken = attrs;
|
|
423
376
|
}
|
|
424
|
-
|
|
425
377
|
if (attrs.access_token) {
|
|
426
378
|
this.supertoken = attrs;
|
|
427
379
|
}
|
|
428
|
-
|
|
429
380
|
if (attrs.authorization) {
|
|
430
381
|
if (attrs.authorization.supertoken) {
|
|
431
382
|
this.supertoken = attrs.authorization.supertoken;
|
|
432
383
|
} else {
|
|
433
384
|
this.supertoken = attrs.authorization;
|
|
434
385
|
}
|
|
435
|
-
}
|
|
436
|
-
|
|
386
|
+
}
|
|
437
387
|
|
|
388
|
+
// schedule refresh
|
|
438
389
|
if (this.supertoken && this.supertoken.expires) {
|
|
439
390
|
this.scheduleRefresh(this.supertoken.expires);
|
|
440
391
|
}
|
|
441
392
|
}
|
|
442
|
-
|
|
443
393
|
(0, _apply.default)(_webexPlugin.default.prototype.initialize, this, [attrs, options]);
|
|
444
394
|
this.listenToOnce(this.parent, 'change:config', function () {
|
|
445
395
|
if (_this5.config.authorizationString) {
|
|
446
396
|
var parsed = _url.default.parse(_this5.config.authorizationString, true);
|
|
447
|
-
/* eslint-disable camelcase */
|
|
448
|
-
|
|
449
397
|
|
|
398
|
+
/* eslint-disable camelcase */
|
|
450
399
|
_this5.config.client_id = parsed.query.client_id;
|
|
451
400
|
_this5.config.redirect_uri = parsed.query.redirect_uri;
|
|
452
401
|
_this5.config.scope = parsed.query.scope;
|
|
@@ -454,11 +403,11 @@ var Credentials = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
|
|
|
454
403
|
/* eslint-enable camelcase */
|
|
455
404
|
}
|
|
456
405
|
});
|
|
406
|
+
|
|
457
407
|
this.webex.once('loaded', function () {
|
|
458
408
|
_this5.ready = true;
|
|
459
409
|
});
|
|
460
410
|
},
|
|
461
|
-
|
|
462
411
|
/**
|
|
463
412
|
* Clears all tokens from store them from the stores.
|
|
464
413
|
*
|
|
@@ -469,19 +418,18 @@ var Credentials = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
|
|
|
469
418
|
* @returns {Promise}
|
|
470
419
|
*/
|
|
471
420
|
invalidate: function invalidate() {
|
|
472
|
-
this.logger.info('credentials: invalidating tokens');
|
|
421
|
+
this.logger.info('credentials: invalidating tokens');
|
|
473
422
|
|
|
423
|
+
// clear refresh timer
|
|
474
424
|
if (this.refreshTimer) {
|
|
475
425
|
clearTimeout(this.refreshTimer);
|
|
476
426
|
this.unset('refreshTimer');
|
|
477
427
|
}
|
|
478
|
-
|
|
479
428
|
try {
|
|
480
429
|
this.unset('supertoken');
|
|
481
430
|
} catch (err) {
|
|
482
431
|
this.logger.warn('credentials: failed to clear supertoken', err);
|
|
483
432
|
}
|
|
484
|
-
|
|
485
433
|
while (this.userTokens.models.length) {
|
|
486
434
|
try {
|
|
487
435
|
this.userTokens.remove(this.userTokens.models[0]);
|
|
@@ -489,13 +437,12 @@ var Credentials = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
|
|
|
489
437
|
this.logger.warn('credentials: failed to remove user token', err);
|
|
490
438
|
}
|
|
491
439
|
}
|
|
440
|
+
this.logger.info('credentials: finished removing tokens');
|
|
492
441
|
|
|
493
|
-
|
|
442
|
+
// Return a promise to give the storage layer a tick or two to clear
|
|
494
443
|
// localStorage
|
|
495
|
-
|
|
496
444
|
return _promise.default.resolve();
|
|
497
445
|
},
|
|
498
|
-
|
|
499
446
|
/**
|
|
500
447
|
* Removes the supertoken and child tokens, then refreshes the supertoken;
|
|
501
448
|
* subsequent calls to {@link Credentials#getUserToken()} will re-downscope
|
|
@@ -507,47 +454,44 @@ var Credentials = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
|
|
|
507
454
|
*/
|
|
508
455
|
refresh: function refresh() {
|
|
509
456
|
var _this6 = this;
|
|
510
|
-
|
|
511
457
|
this.logger.info('credentials: refresh requested');
|
|
512
458
|
var supertoken = this.supertoken;
|
|
513
|
-
var tokens = (0, _clone2.default)(this.userTokens.models);
|
|
459
|
+
var tokens = (0, _clone2.default)(this.userTokens.models);
|
|
460
|
+
|
|
461
|
+
// This is kind of a leaky abstraction, since it relies on the authorization
|
|
514
462
|
// plugin, but the only alternatives I see are
|
|
515
463
|
// 1. put all JWT support in core
|
|
516
464
|
// 2. have separate jwt and non-jwt auth plugins
|
|
517
465
|
// while I like #2 from a code simplicity standpoint, the third-party DX
|
|
518
466
|
// isn't great
|
|
519
|
-
|
|
520
467
|
if (this.config.jwtRefreshCallback) {
|
|
521
|
-
return this.config.jwtRefreshCallback(this.webex)
|
|
468
|
+
return this.config.jwtRefreshCallback(this.webex)
|
|
469
|
+
// eslint-disable-next-line no-shadow
|
|
470
|
+
.then(function (jwt) {
|
|
522
471
|
return _this6.webex.authorization.requestAccessTokenFromJwt({
|
|
523
472
|
jwt: jwt
|
|
524
473
|
});
|
|
525
474
|
});
|
|
526
475
|
}
|
|
527
|
-
|
|
528
476
|
if (this.webex.internal.services) {
|
|
529
477
|
this.webex.internal.services.updateCredentialsConfig();
|
|
530
478
|
}
|
|
531
|
-
|
|
532
479
|
return supertoken.refresh().then(function (st) {
|
|
533
480
|
// clear refresh timer
|
|
534
481
|
if (_this6.refreshTimer) {
|
|
535
482
|
clearTimeout(_this6.refreshTimer);
|
|
536
|
-
|
|
537
483
|
_this6.unset('refreshTimer');
|
|
538
484
|
}
|
|
539
|
-
|
|
540
485
|
_this6.supertoken = st;
|
|
541
486
|
return _promise.default.all(tokens.map(function (token) {
|
|
542
|
-
return _this6.downscope(token.scope)
|
|
487
|
+
return _this6.downscope(token.scope)
|
|
488
|
+
// eslint-disable-next-line max-nested-callbacks
|
|
543
489
|
.then(function (t) {
|
|
544
490
|
_this6.logger.info("credentials: revoking token for ".concat(token.scope));
|
|
545
|
-
|
|
546
491
|
return token.revoke().catch(function (err) {
|
|
547
492
|
_this6.logger.warn('credentials: failed to revoke user token', err);
|
|
548
493
|
}).then(function () {
|
|
549
494
|
_this6.userTokens.remove(token.scope);
|
|
550
|
-
|
|
551
495
|
_this6.userTokens.add(t);
|
|
552
496
|
});
|
|
553
497
|
});
|
|
@@ -556,11 +500,9 @@ var Credentials = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
|
|
|
556
500
|
_this6.scheduleRefresh(_this6.supertoken.expires);
|
|
557
501
|
}).catch(function (error) {
|
|
558
502
|
var InvalidRequestError = _grantErrors.default.InvalidRequestError;
|
|
559
|
-
|
|
560
503
|
if (error instanceof InvalidRequestError) {
|
|
561
504
|
// Error: The refresh token provided is expired, revoked, malformed, or invalid. Hence emit an event to the client, an opportunity to logout.
|
|
562
505
|
_this6.unset('supertoken');
|
|
563
|
-
|
|
564
506
|
while (_this6.userTokens.models.length) {
|
|
565
507
|
try {
|
|
566
508
|
_this6.userTokens.remove(_this6.userTokens.models[0]);
|
|
@@ -568,14 +510,11 @@ var Credentials = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
|
|
|
568
510
|
_this6.logger.warn('credentials: failed to remove user token', err);
|
|
569
511
|
}
|
|
570
512
|
}
|
|
571
|
-
|
|
572
513
|
_this6.webex.trigger('client:InvalidRequestError');
|
|
573
514
|
}
|
|
574
|
-
|
|
575
515
|
return _promise.default.reject(error);
|
|
576
516
|
});
|
|
577
517
|
},
|
|
578
|
-
|
|
579
518
|
/**
|
|
580
519
|
* Schedules a token refresh or refreshes the token if token has expired
|
|
581
520
|
* @instance
|
|
@@ -586,9 +525,7 @@ var Credentials = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
|
|
|
586
525
|
*/
|
|
587
526
|
scheduleRefresh: function scheduleRefresh(expires) {
|
|
588
527
|
var _this7 = this;
|
|
589
|
-
|
|
590
528
|
var expiresIn = expires - (0, _now.default)();
|
|
591
|
-
|
|
592
529
|
if (expiresIn > 0) {
|
|
593
530
|
var timeoutLength = this.calcRefreshTimeout(expiresIn);
|
|
594
531
|
this.refreshTimer = (0, _commonTimers.safeSetTimeout)(function () {
|
|
@@ -598,9 +535,8 @@ var Credentials = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
|
|
|
598
535
|
this.refresh();
|
|
599
536
|
}
|
|
600
537
|
},
|
|
601
|
-
version: "3.0.0-beta.
|
|
538
|
+
version: "3.0.0-beta.131"
|
|
602
539
|
}, ((0, _applyDecoratedDescriptor2.default)(_obj, "getUserToken", [_dec, _dec2], (0, _getOwnPropertyDescriptor.default)(_obj, "getUserToken"), _obj), (0, _applyDecoratedDescriptor2.default)(_obj, "initialize", [_dec3], (0, _getOwnPropertyDescriptor.default)(_obj, "initialize"), _obj), (0, _applyDecoratedDescriptor2.default)(_obj, "invalidate", [_common.oneFlight, _dec4], (0, _getOwnPropertyDescriptor.default)(_obj, "invalidate"), _obj), (0, _applyDecoratedDescriptor2.default)(_obj, "refresh", [_common.oneFlight, _dec5, _dec6], (0, _getOwnPropertyDescriptor.default)(_obj, "refresh"), _obj)), _obj)));
|
|
603
|
-
|
|
604
540
|
var _default = Credentials;
|
|
605
541
|
exports.default = _default;
|
|
606
542
|
//# sourceMappingURL=credentials.js.map
|