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