@webex/plugin-authorization-browser-first-party 3.0.0-beta.4 → 3.0.0-beta.400
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/authorization.js +10 -75
- package/dist/authorization.js.map +1 -1
- package/dist/config.js +0 -3
- package/dist/config.js.map +1 -1
- package/dist/index.js +1 -8
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
- package/src/authorization.js +36 -36
- package/src/config.js +18 -17
- package/src/index.js +2 -5
- package/test/automation/fixtures/app.js +15 -15
- package/test/automation/fixtures/index.html +18 -15
- package/test/automation/spec/authorization-code-grant.js +86 -68
- package/test/unit/spec/authorization.js +202 -155
package/dist/authorization.js
CHANGED
|
@@ -1,57 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
|
|
4
|
-
|
|
5
4
|
var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
|
|
6
|
-
|
|
7
5
|
_Object$defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
|
-
|
|
11
8
|
exports.default = void 0;
|
|
12
|
-
|
|
13
9
|
var _apply = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/reflect/apply"));
|
|
14
|
-
|
|
15
10
|
var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
|
|
16
|
-
|
|
17
11
|
var _assign = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/assign"));
|
|
18
|
-
|
|
19
12
|
var _deleteProperty = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/reflect/delete-property"));
|
|
20
|
-
|
|
21
13
|
var _stringify = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/json/stringify"));
|
|
22
|
-
|
|
23
14
|
var _getOwnPropertyDescriptor = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptor"));
|
|
24
|
-
|
|
25
15
|
var _applyDecoratedDescriptor2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/applyDecoratedDescriptor"));
|
|
26
|
-
|
|
27
16
|
var _omit2 = _interopRequireDefault(require("lodash/omit"));
|
|
28
|
-
|
|
29
17
|
var _isEmpty2 = _interopRequireDefault(require("lodash/isEmpty"));
|
|
30
|
-
|
|
31
18
|
var _cloneDeep2 = _interopRequireDefault(require("lodash/cloneDeep"));
|
|
32
|
-
|
|
33
19
|
var _querystring = _interopRequireDefault(require("querystring"));
|
|
34
|
-
|
|
35
20
|
var _url = _interopRequireDefault(require("url"));
|
|
36
|
-
|
|
37
21
|
var _common = require("@webex/common");
|
|
38
|
-
|
|
39
22
|
var _webexCore = require("@webex/webex-core");
|
|
40
|
-
|
|
41
23
|
var _uuid = _interopRequireDefault(require("uuid"));
|
|
42
|
-
|
|
43
24
|
var _encBase64url = _interopRequireDefault(require("crypto-js/enc-base64url"));
|
|
44
|
-
|
|
45
25
|
var _cryptoJs = _interopRequireDefault(require("crypto-js"));
|
|
46
|
-
|
|
47
26
|
var _dec, _dec2, _obj;
|
|
48
|
-
|
|
49
27
|
// Necessary to require lodash this way in order to stub
|
|
50
28
|
// methods in the unit test
|
|
51
29
|
var lodash = require('lodash');
|
|
52
|
-
|
|
53
30
|
var OAUTH2_CSRF_TOKEN = 'oauth2-csrf-token';
|
|
54
31
|
var OAUTH2_CODE_VERIFIER = 'oauth2-code-verifier';
|
|
32
|
+
|
|
55
33
|
/**
|
|
56
34
|
* Browser support for OAuth2. Automatically parses the URL query for an
|
|
57
35
|
* authorization code
|
|
@@ -62,7 +40,6 @@ var OAUTH2_CODE_VERIFIER = 'oauth2-code-verifier';
|
|
|
62
40
|
* @name AuthorizationBrowserFirstParty
|
|
63
41
|
* @private
|
|
64
42
|
*/
|
|
65
|
-
|
|
66
43
|
var Authorization = _webexCore.WebexPlugin.extend((_dec = (0, _common.whileInFlight)('isAuthorizing'), _dec2 = (0, _common.whileInFlight)('isAuthorizing'), (_obj = {
|
|
67
44
|
derived: {
|
|
68
45
|
/**
|
|
@@ -95,7 +72,6 @@ var Authorization = _webexCore.WebexPlugin.extend((_dec = (0, _common.whileInFli
|
|
|
95
72
|
}
|
|
96
73
|
},
|
|
97
74
|
namespace: 'Credentials',
|
|
98
|
-
|
|
99
75
|
/**
|
|
100
76
|
* Initializer
|
|
101
77
|
* @instance
|
|
@@ -106,39 +82,29 @@ var Authorization = _webexCore.WebexPlugin.extend((_dec = (0, _common.whileInFli
|
|
|
106
82
|
// eslint-disable-next-line complexity
|
|
107
83
|
initialize: function initialize() {
|
|
108
84
|
var _this = this;
|
|
109
|
-
|
|
110
85
|
for (var _len = arguments.length, attrs = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
111
86
|
attrs[_key] = arguments[_key];
|
|
112
87
|
}
|
|
113
|
-
|
|
114
88
|
var ret = (0, _apply.default)(_webexCore.WebexPlugin.prototype.initialize, this, attrs);
|
|
115
|
-
|
|
116
89
|
var location = _url.default.parse(this.webex.getWindow().location.href, true);
|
|
117
|
-
|
|
118
90
|
this._checkForErrors(location);
|
|
119
|
-
|
|
120
91
|
var code = location.query.code;
|
|
121
|
-
|
|
122
92
|
if (!code) {
|
|
123
93
|
this.ready = true;
|
|
124
94
|
return ret;
|
|
125
95
|
}
|
|
126
|
-
|
|
127
96
|
if (location.query.state) {
|
|
128
97
|
location.query.state = JSON.parse(_common.base64.decode(location.query.state));
|
|
129
98
|
} else {
|
|
130
99
|
location.query.state = {};
|
|
131
100
|
}
|
|
132
|
-
|
|
133
101
|
var codeVerifier = this.webex.getWindow().sessionStorage.getItem(OAUTH2_CODE_VERIFIER);
|
|
134
102
|
this.webex.getWindow().sessionStorage.removeItem(OAUTH2_CODE_VERIFIER);
|
|
135
103
|
var emailhash = location.query.state.emailhash;
|
|
136
|
-
|
|
137
104
|
this._verifySecurityToken(location.query);
|
|
105
|
+
this._cleanUrl(location);
|
|
138
106
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
107
|
+
// Wait until nextTick in case `credentials` hasn't initialized yet
|
|
142
108
|
process.nextTick(function () {
|
|
143
109
|
_this.webex.internal.services.collectPreauthCatalog({
|
|
144
110
|
emailhash: emailhash
|
|
@@ -149,13 +115,14 @@ var Authorization = _webexCore.WebexPlugin.extend((_dec = (0, _common.whileInFli
|
|
|
149
115
|
code: code,
|
|
150
116
|
codeVerifier: codeVerifier
|
|
151
117
|
});
|
|
118
|
+
}).catch(function (error) {
|
|
119
|
+
_this.logger.warn('authorization: failed initial authorization code grant request', error);
|
|
152
120
|
}).then(function () {
|
|
153
121
|
_this.ready = true;
|
|
154
122
|
});
|
|
155
123
|
});
|
|
156
124
|
return ret;
|
|
157
125
|
},
|
|
158
|
-
|
|
159
126
|
/**
|
|
160
127
|
* Kicks off an oauth flow
|
|
161
128
|
* @instance
|
|
@@ -166,21 +133,18 @@ var Authorization = _webexCore.WebexPlugin.extend((_dec = (0, _common.whileInFli
|
|
|
166
133
|
initiateLogin: function initiateLogin() {
|
|
167
134
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
168
135
|
options = (0, _cloneDeep2.default)(options);
|
|
169
|
-
|
|
170
136
|
if (options.email) {
|
|
171
137
|
options.emailHash = _cryptoJs.default.SHA256(options.email).toString();
|
|
172
138
|
}
|
|
173
|
-
|
|
174
139
|
delete options.email;
|
|
175
140
|
options.state = options.state || {};
|
|
176
|
-
options.state.csrf_token = this._generateSecurityToken();
|
|
177
|
-
|
|
141
|
+
options.state.csrf_token = this._generateSecurityToken();
|
|
142
|
+
// catalog uses emailhash and redirectCI uses emailHash
|
|
178
143
|
options.state.emailhash = options.emailHash;
|
|
179
144
|
options.code_challenge = this._generateCodeChallenge();
|
|
180
145
|
options.code_challenge_method = 'S256';
|
|
181
146
|
return this.initiateAuthorizationCodeGrant(options);
|
|
182
147
|
},
|
|
183
|
-
|
|
184
148
|
/**
|
|
185
149
|
* Kicks off the Implicit Code grant flow. Typically called via
|
|
186
150
|
* {@link AuthorizationBrowserFirstParty#initiateLogin}
|
|
@@ -196,7 +160,6 @@ var Authorization = _webexCore.WebexPlugin.extend((_dec = (0, _common.whileInFli
|
|
|
196
160
|
}, options));
|
|
197
161
|
return _promise.default.resolve();
|
|
198
162
|
},
|
|
199
|
-
|
|
200
163
|
/**
|
|
201
164
|
* Called by {@link WebexCore#logout()}. Redirects to the logout page
|
|
202
165
|
* @instance
|
|
@@ -207,12 +170,10 @@ var Authorization = _webexCore.WebexPlugin.extend((_dec = (0, _common.whileInFli
|
|
|
207
170
|
*/
|
|
208
171
|
logout: function logout() {
|
|
209
172
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
210
|
-
|
|
211
173
|
if (!options.noRedirect) {
|
|
212
174
|
this.webex.getWindow().location = this.webex.credentials.buildLogoutUrl(options);
|
|
213
175
|
}
|
|
214
176
|
},
|
|
215
|
-
|
|
216
177
|
/**
|
|
217
178
|
* Exchanges an authorization code for an access token
|
|
218
179
|
* @instance
|
|
@@ -223,25 +184,20 @@ var Authorization = _webexCore.WebexPlugin.extend((_dec = (0, _common.whileInFli
|
|
|
223
184
|
*/
|
|
224
185
|
requestAuthorizationCodeGrant: function requestAuthorizationCodeGrant() {
|
|
225
186
|
var _this2 = this;
|
|
226
|
-
|
|
227
187
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
228
188
|
this.logger.info('credentials: requesting authorization code grant');
|
|
229
|
-
|
|
230
189
|
if (!options.code) {
|
|
231
190
|
return _promise.default.reject(new Error('`options.code` is required'));
|
|
232
191
|
}
|
|
233
|
-
|
|
234
192
|
var form = {
|
|
235
193
|
grant_type: 'authorization_code',
|
|
236
194
|
redirect_uri: this.config.redirect_uri,
|
|
237
195
|
code: options.code,
|
|
238
196
|
self_contained_token: true
|
|
239
197
|
};
|
|
240
|
-
|
|
241
198
|
if (options.codeVerifier) {
|
|
242
199
|
form.code_verifier = options.codeVerifier;
|
|
243
200
|
}
|
|
244
|
-
|
|
245
201
|
return this.webex.request({
|
|
246
202
|
method: 'POST',
|
|
247
203
|
uri: this.config.tokenUrl,
|
|
@@ -260,13 +216,10 @@ var Authorization = _webexCore.WebexPlugin.extend((_dec = (0, _common.whileInFli
|
|
|
260
216
|
if (res.statusCode !== 400) {
|
|
261
217
|
return _promise.default.reject(res);
|
|
262
218
|
}
|
|
263
|
-
|
|
264
219
|
var ErrorConstructor = _webexCore.grantErrors.select(res.body.error);
|
|
265
|
-
|
|
266
220
|
return _promise.default.reject(new ErrorConstructor(res._res || res));
|
|
267
221
|
});
|
|
268
222
|
},
|
|
269
|
-
|
|
270
223
|
/**
|
|
271
224
|
* Checks if the result of the login redirect contains an error string
|
|
272
225
|
* @instance
|
|
@@ -277,14 +230,11 @@ var Authorization = _webexCore.WebexPlugin.extend((_dec = (0, _common.whileInFli
|
|
|
277
230
|
*/
|
|
278
231
|
_checkForErrors: function _checkForErrors(location) {
|
|
279
232
|
var query = location.query;
|
|
280
|
-
|
|
281
233
|
if (query && query.error) {
|
|
282
234
|
var ErrorConstructor = _webexCore.grantErrors.select(query.error);
|
|
283
|
-
|
|
284
235
|
throw new ErrorConstructor(query);
|
|
285
236
|
}
|
|
286
237
|
},
|
|
287
|
-
|
|
288
238
|
/**
|
|
289
239
|
* Removes no-longer needed values from the url (access token, csrf token, etc)
|
|
290
240
|
* @instance
|
|
@@ -295,22 +245,18 @@ var Authorization = _webexCore.WebexPlugin.extend((_dec = (0, _common.whileInFli
|
|
|
295
245
|
*/
|
|
296
246
|
_cleanUrl: function _cleanUrl(location) {
|
|
297
247
|
location = (0, _cloneDeep2.default)(location);
|
|
298
|
-
|
|
299
248
|
if (this.webex.getWindow().history && this.webex.getWindow().history.replaceState) {
|
|
300
249
|
(0, _deleteProperty.default)(location.query, 'code');
|
|
301
|
-
|
|
302
250
|
if ((0, _isEmpty2.default)((0, _omit2.default)(location.query.state, 'csrf_token'))) {
|
|
303
251
|
(0, _deleteProperty.default)(location.query, 'state');
|
|
304
252
|
} else {
|
|
305
253
|
location.query.state = _common.base64.encode((0, _stringify.default)((0, _omit2.default)(location.query.state, 'csrf_token')));
|
|
306
254
|
}
|
|
307
|
-
|
|
308
255
|
location.search = _querystring.default.stringify(location.query);
|
|
309
256
|
(0, _deleteProperty.default)(location, 'query');
|
|
310
257
|
this.webex.getWindow().history.replaceState({}, null, _url.default.format(location));
|
|
311
258
|
}
|
|
312
259
|
},
|
|
313
|
-
|
|
314
260
|
/**
|
|
315
261
|
* Generates PKCE code verifier and code challenge and sets the the code verifier in sessionStorage
|
|
316
262
|
* @instance
|
|
@@ -319,19 +265,17 @@ var Authorization = _webexCore.WebexPlugin.extend((_dec = (0, _common.whileInFli
|
|
|
319
265
|
* @returns {string}
|
|
320
266
|
*/
|
|
321
267
|
_generateCodeChallenge: function _generateCodeChallenge() {
|
|
322
|
-
this.logger.info('authorization: generating PKCE code challenge');
|
|
268
|
+
this.logger.info('authorization: generating PKCE code challenge');
|
|
323
269
|
|
|
270
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
324
271
|
var safeCharacterMap = _encBase64url.default._safe_map;
|
|
325
272
|
var codeVerifier = lodash.times(128, function () {
|
|
326
273
|
return safeCharacterMap[lodash.random(0, safeCharacterMap.length - 1)];
|
|
327
274
|
}).join('');
|
|
328
|
-
|
|
329
275
|
var codeChallenge = _cryptoJs.default.SHA256(codeVerifier).toString(_encBase64url.default);
|
|
330
|
-
|
|
331
276
|
this.webex.getWindow().sessionStorage.setItem(OAUTH2_CODE_VERIFIER, codeVerifier);
|
|
332
277
|
return codeChallenge;
|
|
333
278
|
},
|
|
334
|
-
|
|
335
279
|
/**
|
|
336
280
|
* Generates a CSRF token and sticks in in sessionStorage
|
|
337
281
|
* @instance
|
|
@@ -341,13 +285,10 @@ var Authorization = _webexCore.WebexPlugin.extend((_dec = (0, _common.whileInFli
|
|
|
341
285
|
*/
|
|
342
286
|
_generateSecurityToken: function _generateSecurityToken() {
|
|
343
287
|
this.logger.info('authorization: generating csrf token');
|
|
344
|
-
|
|
345
288
|
var token = _uuid.default.v4();
|
|
346
|
-
|
|
347
289
|
this.webex.getWindow().sessionStorage.setItem('oauth2-csrf-token', token);
|
|
348
290
|
return token;
|
|
349
291
|
},
|
|
350
|
-
|
|
351
292
|
/**
|
|
352
293
|
* Checks if the CSRF token in sessionStorage is the same as the one returned
|
|
353
294
|
* in the url.
|
|
@@ -360,28 +301,22 @@ var Authorization = _webexCore.WebexPlugin.extend((_dec = (0, _common.whileInFli
|
|
|
360
301
|
_verifySecurityToken: function _verifySecurityToken(query) {
|
|
361
302
|
var sessionToken = this.webex.getWindow().sessionStorage.getItem(OAUTH2_CSRF_TOKEN);
|
|
362
303
|
this.webex.getWindow().sessionStorage.removeItem(OAUTH2_CSRF_TOKEN);
|
|
363
|
-
|
|
364
304
|
if (!sessionToken) {
|
|
365
305
|
return;
|
|
366
306
|
}
|
|
367
|
-
|
|
368
307
|
if (!query.state) {
|
|
369
308
|
throw new Error("Expected CSRF token ".concat(sessionToken, ", but not found in redirect query"));
|
|
370
309
|
}
|
|
371
|
-
|
|
372
310
|
if (!query.state.csrf_token) {
|
|
373
311
|
throw new Error("Expected CSRF token ".concat(sessionToken, ", but not found in redirect query"));
|
|
374
312
|
}
|
|
375
|
-
|
|
376
313
|
var token = query.state.csrf_token;
|
|
377
|
-
|
|
378
314
|
if (token !== sessionToken) {
|
|
379
315
|
throw new Error("CSRF token ".concat(token, " does not match stored token ").concat(sessionToken));
|
|
380
316
|
}
|
|
381
317
|
},
|
|
382
|
-
version: "3.0.0-beta.
|
|
318
|
+
version: "3.0.0-beta.400"
|
|
383
319
|
}, ((0, _applyDecoratedDescriptor2.default)(_obj, "initiateAuthorizationCodeGrant", [_dec], (0, _getOwnPropertyDescriptor.default)(_obj, "initiateAuthorizationCodeGrant"), _obj), (0, _applyDecoratedDescriptor2.default)(_obj, "requestAuthorizationCodeGrant", [_dec2, _common.oneFlight], (0, _getOwnPropertyDescriptor.default)(_obj, "requestAuthorizationCodeGrant"), _obj)), _obj)));
|
|
384
|
-
|
|
385
320
|
var _default = Authorization;
|
|
386
321
|
exports.default = _default;
|
|
387
322
|
//# sourceMappingURL=authorization.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["lodash","require","OAUTH2_CSRF_TOKEN","OAUTH2_CODE_VERIFIER","Authorization","WebexPlugin","extend","whileInFlight","derived","isAuthenticating","deps","fn","isAuthorizing","session","default","type","ready","namespace","initialize","attrs","ret","prototype","location","url","parse","webex","getWindow","href","_checkForErrors","code","query","state","JSON","base64","decode","codeVerifier","sessionStorage","getItem","removeItem","emailhash","_verifySecurityToken","_cleanUrl","process","nextTick","internal","services","collectPreauthCatalog","catch","resolve","then","requestAuthorizationCodeGrant","initiateLogin","options","email","emailHash","CryptoJS","SHA256","toString","csrf_token","_generateSecurityToken","code_challenge","_generateCodeChallenge","code_challenge_method","initiateAuthorizationCodeGrant","logger","info","credentials","buildLoginUrl","response_type","logout","noRedirect","buildLogoutUrl","reject","Error","form","grant_type","redirect_uri","config","self_contained_token","code_verifier","request","method","uri","tokenUrl","auth","user","client_id","pass","client_secret","sendImmediately","shouldRefreshAccessToken","res","set","supertoken","body","statusCode","ErrorConstructor","grantErrors","select","error","_res","history","replaceState","encode","search","querystring","stringify","format","safeCharacterMap","base64url","_safe_map","times","random","length","join","codeChallenge","setItem","token","uuid","v4","sessionToken","oneFlight"],"sources":["authorization.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\n/* eslint camelcase: [0] */\n\nimport querystring from 'querystring';\nimport url from 'url';\n\nimport {base64, oneFlight, whileInFlight} from '@webex/common';\nimport {grantErrors, WebexPlugin} from '@webex/webex-core';\nimport {cloneDeep, isEmpty, omit} from 'lodash';\nimport uuid from 'uuid';\nimport base64url from 'crypto-js/enc-base64url';\nimport CryptoJS from 'crypto-js';\n\n// Necessary to require lodash this way in order to stub\n// methods in the unit test\nconst lodash = require('lodash');\n\nconst OAUTH2_CSRF_TOKEN = 'oauth2-csrf-token';\nconst OAUTH2_CODE_VERIFIER = 'oauth2-code-verifier';\n\n/**\n * Browser support for OAuth2. Automatically parses the URL query for an\n * authorization code\n *\n * Use of this plugin for anything other than the Webex Web Client is strongly\n * discouraged and may be broken at any time\n * @class\n * @name AuthorizationBrowserFirstParty\n * @private\n */\nconst Authorization = WebexPlugin.extend({\n derived: {\n /**\n * Alias of {@link AuthorizationBrowserFirstParty#isAuthorizing}\n * @instance\n * @memberof AuthorizationBrowserFirstParty\n * @type {boolean}\n */\n isAuthenticating: {\n deps: ['isAuthorizing'],\n fn() {\n return this.isAuthorizing;\n }\n }\n },\n\n session: {\n /**\n * Indicates if an Authorization Code exchange is inflight\n * @instance\n * @memberof AuthorizationBrowserFirstParty\n * @type {boolean}\n */\n isAuthorizing: {\n default: false,\n type: 'boolean'\n },\n ready: {\n default: false,\n type: 'boolean'\n }\n },\n\n namespace: 'Credentials',\n\n /**\n * Initializer\n * @instance\n * @memberof AuthorizationBrowserFirstParty\n * @private\n * @returns {Authorization}\n */\n // eslint-disable-next-line complexity\n initialize(...attrs) {\n const ret = Reflect.apply(WebexPlugin.prototype.initialize, this, attrs);\n const location = url.parse(this.webex.getWindow().location.href, true);\n\n this._checkForErrors(location);\n\n const {code} = location.query;\n\n if (!code) {\n this.ready = true;\n\n return ret;\n }\n\n if (location.query.state) {\n location.query.state = JSON.parse(base64.decode(location.query.state));\n }\n else {\n location.query.state = {};\n }\n\n const codeVerifier = this.webex.getWindow().sessionStorage.getItem(OAUTH2_CODE_VERIFIER);\n\n this.webex.getWindow().sessionStorage.removeItem(OAUTH2_CODE_VERIFIER);\n\n\n const {emailhash} = location.query.state;\n\n this._verifySecurityToken(location.query);\n this._cleanUrl(location);\n\n // Wait until nextTick in case `credentials` hasn't initialized yet\n process.nextTick(() => {\n this.webex.internal.services.collectPreauthCatalog({emailhash})\n .catch(() => Promise.resolve())\n .then(() => this.requestAuthorizationCodeGrant({code, codeVerifier}))\n .then(() => {\n this.ready = true;\n });\n });\n\n\n return ret;\n },\n\n /**\n * Kicks off an oauth flow\n * @instance\n * @memberof AuthorizationBrowserFirstParty\n * @param {Object} options\n * @returns {Promise}\n */\n initiateLogin(options = {}) {\n options = cloneDeep(options);\n if (options.email) {\n options.emailHash = CryptoJS.SHA256(options.email).toString();\n }\n delete options.email;\n options.state = options.state || {};\n options.state.csrf_token = this._generateSecurityToken();\n // catalog uses emailhash and redirectCI uses emailHash\n options.state.emailhash = options.emailHash;\n\n options.code_challenge = this._generateCodeChallenge();\n options.code_challenge_method = 'S256';\n\n\n return this.initiateAuthorizationCodeGrant(options);\n },\n\n @whileInFlight('isAuthorizing')\n /**\n * Kicks off the Implicit Code grant flow. Typically called via\n * {@link AuthorizationBrowserFirstParty#initiateLogin}\n * @instance\n * @memberof AuthorizationBrowserFirstParty\n * @param {Object} options\n * @returns {Promise}\n */\n initiateAuthorizationCodeGrant(options) {\n this.logger.info('authorization: initiating authorization code grant flow');\n this.webex.getWindow().location = this.webex.credentials.buildLoginUrl(Object.assign({response_type: 'code'}, options));\n\n return Promise.resolve();\n },\n\n /**\n * Called by {@link WebexCore#logout()}. Redirects to the logout page\n * @instance\n * @memberof AuthorizationBrowserFirstParty\n * @param {Object} options\n * @param {boolean} options.noRedirect if true, does not redirect\n * @returns {Promise}\n */\n logout(options = {}) {\n if (!options.noRedirect) {\n this.webex.getWindow().location = this.webex.credentials.buildLogoutUrl(options);\n }\n },\n\n\n @whileInFlight('isAuthorizing')\n @oneFlight\n /**\n * Exchanges an authorization code for an access token\n * @instance\n * @memberof AuthorizationBrowserFirstParty\n * @param {Object} options\n * @param {Object} options.code\n * @returns {Promise}\n */\n requestAuthorizationCodeGrant(options = {}) {\n this.logger.info('credentials: requesting authorization code grant');\n\n if (!options.code) {\n return Promise.reject(new Error('`options.code` is required'));\n }\n\n const form = {\n grant_type: 'authorization_code',\n redirect_uri: this.config.redirect_uri,\n code: options.code,\n self_contained_token: true\n };\n\n if (options.codeVerifier) {\n form.code_verifier = options.codeVerifier;\n }\n\n return this.webex.request({\n method: 'POST',\n uri: this.config.tokenUrl,\n form,\n auth: {\n user: this.config.client_id,\n pass: this.config.client_secret,\n sendImmediately: true\n },\n shouldRefreshAccessToken: false\n })\n .then((res) => {\n this.webex.credentials.set({supertoken: res.body});\n })\n .catch((res) => {\n if (res.statusCode !== 400) {\n return Promise.reject(res);\n }\n\n const ErrorConstructor = grantErrors.select(res.body.error);\n\n return Promise.reject(new ErrorConstructor(res._res || res));\n });\n },\n\n /**\n * Checks if the result of the login redirect contains an error string\n * @instance\n * @memberof AuthorizationBrowserFirstParty\n * @param {Object} location\n * @private\n * @returns {Promise}\n */\n _checkForErrors(location) {\n const {query} = location;\n\n if (query && query.error) {\n const ErrorConstructor = grantErrors.select(query.error);\n\n throw new ErrorConstructor(query);\n }\n },\n\n /**\n * Removes no-longer needed values from the url (access token, csrf token, etc)\n * @instance\n * @memberof AuthorizationBrowserFirstParty\n * @param {Object} location\n * @private\n * @returns {Promise}\n */\n _cleanUrl(location) {\n location = cloneDeep(location);\n if (this.webex.getWindow().history && this.webex.getWindow().history.replaceState) {\n Reflect.deleteProperty(location.query, 'code');\n if (isEmpty(omit(location.query.state, 'csrf_token'))) {\n Reflect.deleteProperty(location.query, 'state');\n }\n else {\n location.query.state = base64.encode(JSON.stringify(omit(location.query.state, 'csrf_token')));\n }\n location.search = querystring.stringify(location.query);\n Reflect.deleteProperty(location, 'query');\n this.webex.getWindow().history.replaceState({}, null, url.format(location));\n }\n },\n\n /**\n * Generates PKCE code verifier and code challenge and sets the the code verifier in sessionStorage\n * @instance\n * @memberof AuthorizationBrowserFirstParty\n * @private\n * @returns {string}\n */\n _generateCodeChallenge() {\n this.logger.info('authorization: generating PKCE code challenge');\n\n // eslint-disable-next-line no-underscore-dangle\n const safeCharacterMap = base64url._safe_map;\n\n const codeVerifier = lodash.times(\n 128,\n () => safeCharacterMap[lodash.random(0, safeCharacterMap.length - 1)]\n ).join('');\n\n const codeChallenge = CryptoJS.SHA256(codeVerifier).toString(base64url);\n\n this.webex.getWindow().sessionStorage.setItem(\n OAUTH2_CODE_VERIFIER, codeVerifier\n );\n\n return codeChallenge;\n },\n\n /**\n * Generates a CSRF token and sticks in in sessionStorage\n * @instance\n * @memberof AuthorizationBrowserFirstParty\n * @private\n * @returns {Promise}\n */\n _generateSecurityToken() {\n this.logger.info('authorization: generating csrf token');\n\n const token = uuid.v4();\n\n this.webex.getWindow().sessionStorage.setItem('oauth2-csrf-token', token);\n\n return token;\n },\n\n /**\n * Checks if the CSRF token in sessionStorage is the same as the one returned\n * in the url.\n * @instance\n * @memberof AuthorizationBrowserFirstParty\n * @param {Object} query\n * @private\n * @returns {Promise}\n */\n _verifySecurityToken(query) {\n const sessionToken = this.webex.getWindow().sessionStorage.getItem(OAUTH2_CSRF_TOKEN);\n\n this.webex.getWindow().sessionStorage.removeItem(OAUTH2_CSRF_TOKEN);\n if (!sessionToken) {\n return;\n }\n\n if (!query.state) {\n throw new Error(`Expected CSRF token ${sessionToken}, but not found in redirect query`);\n }\n\n if (!query.state.csrf_token) {\n throw new Error(`Expected CSRF token ${sessionToken}, but not found in redirect query`);\n }\n\n const token = query.state.csrf_token;\n\n if (token !== sessionToken) {\n throw new Error(`CSRF token ${token} does not match stored token ${sessionToken}`);\n }\n }\n});\n\nexport default Authorization;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA;;AACA;;AAEA;;AACA;;AAEA;;AACA;;AACA;;;;AAEA;AACA;AACA,IAAMA,MAAM,GAAGC,OAAO,CAAC,QAAD,CAAtB;;AAEA,IAAMC,iBAAiB,GAAG,mBAA1B;AACA,IAAMC,oBAAoB,GAAG,sBAA7B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,IAAMC,aAAa,GAAGC,sBAAA,CAAYC,MAAZ,SAiHnB,IAAAC,qBAAA,EAAc,eAAd,CAjHmB,UAgJnB,IAA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jD;;IACA,IAAI,CAACsH,YAAL,EAAmB;MACjB;IACD;;IAED,IAAI,CAAC1F,KAAK,CAACC,KAAX,EAAkB;MAChB,MAAM,IAAI0C,KAAJ,+BAAiC+C,YAAjC,uCAAN;IACD;;IAED,IAAI,CAAC1F,KAAK,CAACC,KAAN,CAAY2B,UAAjB,EAA6B;MAC3B,MAAM,IAAIe,KAAJ,+BAAiC+C,YAAjC,uCAAN;IACD;;IAED,IAAMH,KAAK,GAAGvF,KAAK,CAACC,KAAN,CAAY2B,UAA1B;;IAEA,IAAI2D,KAAK,KAAKG,YAAd,EAA4B;MAC1B,MAAM,IAAI/C,KAAJ,sBAAwB4C,KAAxB,0CAA6DG,YAA7D,EAAN;IACD;EACF,CAzTsC;EAAA;AAAA,CAAnB,yQAiJnBC,iBAjJmB,iGAAtB;;eA4TerH,a"}
|
|
1
|
+
{"version":3,"names":["lodash","require","OAUTH2_CSRF_TOKEN","OAUTH2_CODE_VERIFIER","Authorization","WebexPlugin","extend","whileInFlight","derived","isAuthenticating","deps","fn","isAuthorizing","session","default","type","ready","namespace","initialize","attrs","ret","prototype","location","url","parse","webex","getWindow","href","_checkForErrors","code","query","state","JSON","base64","decode","codeVerifier","sessionStorage","getItem","removeItem","emailhash","_verifySecurityToken","_cleanUrl","process","nextTick","internal","services","collectPreauthCatalog","catch","resolve","then","requestAuthorizationCodeGrant","error","logger","warn","initiateLogin","options","email","emailHash","CryptoJS","SHA256","toString","csrf_token","_generateSecurityToken","code_challenge","_generateCodeChallenge","code_challenge_method","initiateAuthorizationCodeGrant","info","credentials","buildLoginUrl","response_type","logout","noRedirect","buildLogoutUrl","reject","Error","form","grant_type","redirect_uri","config","self_contained_token","code_verifier","request","method","uri","tokenUrl","auth","user","client_id","pass","client_secret","sendImmediately","shouldRefreshAccessToken","res","set","supertoken","body","statusCode","ErrorConstructor","grantErrors","select","_res","history","replaceState","encode","search","querystring","stringify","format","safeCharacterMap","base64url","_safe_map","times","random","length","join","codeChallenge","setItem","token","uuid","v4","sessionToken","oneFlight"],"sources":["authorization.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\n/* eslint camelcase: [0] */\n\nimport querystring from 'querystring';\nimport url from 'url';\n\nimport {base64, oneFlight, whileInFlight} from '@webex/common';\nimport {grantErrors, WebexPlugin} from '@webex/webex-core';\nimport {cloneDeep, isEmpty, omit} from 'lodash';\nimport uuid from 'uuid';\nimport base64url from 'crypto-js/enc-base64url';\nimport CryptoJS from 'crypto-js';\n\n// Necessary to require lodash this way in order to stub\n// methods in the unit test\nconst lodash = require('lodash');\n\nconst OAUTH2_CSRF_TOKEN = 'oauth2-csrf-token';\nconst OAUTH2_CODE_VERIFIER = 'oauth2-code-verifier';\n\n/**\n * Browser support for OAuth2. Automatically parses the URL query for an\n * authorization code\n *\n * Use of this plugin for anything other than the Webex Web Client is strongly\n * discouraged and may be broken at any time\n * @class\n * @name AuthorizationBrowserFirstParty\n * @private\n */\nconst Authorization = WebexPlugin.extend({\n derived: {\n /**\n * Alias of {@link AuthorizationBrowserFirstParty#isAuthorizing}\n * @instance\n * @memberof AuthorizationBrowserFirstParty\n * @type {boolean}\n */\n isAuthenticating: {\n deps: ['isAuthorizing'],\n fn() {\n return this.isAuthorizing;\n },\n },\n },\n\n session: {\n /**\n * Indicates if an Authorization Code exchange is inflight\n * @instance\n * @memberof AuthorizationBrowserFirstParty\n * @type {boolean}\n */\n isAuthorizing: {\n default: false,\n type: 'boolean',\n },\n ready: {\n default: false,\n type: 'boolean',\n },\n },\n\n namespace: 'Credentials',\n\n /**\n * Initializer\n * @instance\n * @memberof AuthorizationBrowserFirstParty\n * @private\n * @returns {Authorization}\n */\n // eslint-disable-next-line complexity\n initialize(...attrs) {\n const ret = Reflect.apply(WebexPlugin.prototype.initialize, this, attrs);\n const location = url.parse(this.webex.getWindow().location.href, true);\n\n this._checkForErrors(location);\n\n const {code} = location.query;\n\n if (!code) {\n this.ready = true;\n\n return ret;\n }\n\n if (location.query.state) {\n location.query.state = JSON.parse(base64.decode(location.query.state));\n } else {\n location.query.state = {};\n }\n\n const codeVerifier = this.webex.getWindow().sessionStorage.getItem(OAUTH2_CODE_VERIFIER);\n\n this.webex.getWindow().sessionStorage.removeItem(OAUTH2_CODE_VERIFIER);\n\n const {emailhash} = location.query.state;\n\n this._verifySecurityToken(location.query);\n this._cleanUrl(location);\n\n // Wait until nextTick in case `credentials` hasn't initialized yet\n process.nextTick(() => {\n this.webex.internal.services\n .collectPreauthCatalog({emailhash})\n .catch(() => Promise.resolve())\n .then(() => this.requestAuthorizationCodeGrant({code, codeVerifier}))\n .catch((error) => {\n this.logger.warn('authorization: failed initial authorization code grant request', error)\n })\n .then(() => {\n this.ready = true;\n });\n });\n\n return ret;\n },\n\n /**\n * Kicks off an oauth flow\n * @instance\n * @memberof AuthorizationBrowserFirstParty\n * @param {Object} options\n * @returns {Promise}\n */\n initiateLogin(options = {}) {\n options = cloneDeep(options);\n if (options.email) {\n options.emailHash = CryptoJS.SHA256(options.email).toString();\n }\n delete options.email;\n options.state = options.state || {};\n options.state.csrf_token = this._generateSecurityToken();\n // catalog uses emailhash and redirectCI uses emailHash\n options.state.emailhash = options.emailHash;\n\n options.code_challenge = this._generateCodeChallenge();\n options.code_challenge_method = 'S256';\n\n return this.initiateAuthorizationCodeGrant(options);\n },\n\n @whileInFlight('isAuthorizing')\n /**\n * Kicks off the Implicit Code grant flow. Typically called via\n * {@link AuthorizationBrowserFirstParty#initiateLogin}\n * @instance\n * @memberof AuthorizationBrowserFirstParty\n * @param {Object} options\n * @returns {Promise}\n */\n initiateAuthorizationCodeGrant(options) {\n this.logger.info('authorization: initiating authorization code grant flow');\n this.webex.getWindow().location = this.webex.credentials.buildLoginUrl(\n Object.assign({response_type: 'code'}, options)\n );\n\n return Promise.resolve();\n },\n\n /**\n * Called by {@link WebexCore#logout()}. Redirects to the logout page\n * @instance\n * @memberof AuthorizationBrowserFirstParty\n * @param {Object} options\n * @param {boolean} options.noRedirect if true, does not redirect\n * @returns {Promise}\n */\n logout(options = {}) {\n if (!options.noRedirect) {\n this.webex.getWindow().location = this.webex.credentials.buildLogoutUrl(options);\n }\n },\n\n @whileInFlight('isAuthorizing')\n @oneFlight\n /**\n * Exchanges an authorization code for an access token\n * @instance\n * @memberof AuthorizationBrowserFirstParty\n * @param {Object} options\n * @param {Object} options.code\n * @returns {Promise}\n */\n requestAuthorizationCodeGrant(options = {}) {\n this.logger.info('credentials: requesting authorization code grant');\n\n if (!options.code) {\n return Promise.reject(new Error('`options.code` is required'));\n }\n\n const form = {\n grant_type: 'authorization_code',\n redirect_uri: this.config.redirect_uri,\n code: options.code,\n self_contained_token: true,\n };\n\n if (options.codeVerifier) {\n form.code_verifier = options.codeVerifier;\n }\n\n return this.webex\n .request({\n method: 'POST',\n uri: this.config.tokenUrl,\n form,\n auth: {\n user: this.config.client_id,\n pass: this.config.client_secret,\n sendImmediately: true,\n },\n shouldRefreshAccessToken: false,\n })\n .then((res) => {\n this.webex.credentials.set({supertoken: res.body});\n })\n .catch((res) => {\n if (res.statusCode !== 400) {\n return Promise.reject(res);\n }\n\n const ErrorConstructor = grantErrors.select(res.body.error);\n\n return Promise.reject(new ErrorConstructor(res._res || res));\n });\n },\n\n /**\n * Checks if the result of the login redirect contains an error string\n * @instance\n * @memberof AuthorizationBrowserFirstParty\n * @param {Object} location\n * @private\n * @returns {Promise}\n */\n _checkForErrors(location) {\n const {query} = location;\n\n if (query && query.error) {\n const ErrorConstructor = grantErrors.select(query.error);\n\n throw new ErrorConstructor(query);\n }\n },\n\n /**\n * Removes no-longer needed values from the url (access token, csrf token, etc)\n * @instance\n * @memberof AuthorizationBrowserFirstParty\n * @param {Object} location\n * @private\n * @returns {Promise}\n */\n _cleanUrl(location) {\n location = cloneDeep(location);\n if (this.webex.getWindow().history && this.webex.getWindow().history.replaceState) {\n Reflect.deleteProperty(location.query, 'code');\n if (isEmpty(omit(location.query.state, 'csrf_token'))) {\n Reflect.deleteProperty(location.query, 'state');\n } else {\n location.query.state = base64.encode(\n JSON.stringify(omit(location.query.state, 'csrf_token'))\n );\n }\n location.search = querystring.stringify(location.query);\n Reflect.deleteProperty(location, 'query');\n this.webex.getWindow().history.replaceState({}, null, url.format(location));\n }\n },\n\n /**\n * Generates PKCE code verifier and code challenge and sets the the code verifier in sessionStorage\n * @instance\n * @memberof AuthorizationBrowserFirstParty\n * @private\n * @returns {string}\n */\n _generateCodeChallenge() {\n this.logger.info('authorization: generating PKCE code challenge');\n\n // eslint-disable-next-line no-underscore-dangle\n const safeCharacterMap = base64url._safe_map;\n\n const codeVerifier = lodash\n .times(128, () => safeCharacterMap[lodash.random(0, safeCharacterMap.length - 1)])\n .join('');\n\n const codeChallenge = CryptoJS.SHA256(codeVerifier).toString(base64url);\n\n this.webex.getWindow().sessionStorage.setItem(OAUTH2_CODE_VERIFIER, codeVerifier);\n\n return codeChallenge;\n },\n\n /**\n * Generates a CSRF token and sticks in in sessionStorage\n * @instance\n * @memberof AuthorizationBrowserFirstParty\n * @private\n * @returns {Promise}\n */\n _generateSecurityToken() {\n this.logger.info('authorization: generating csrf token');\n\n const token = uuid.v4();\n\n this.webex.getWindow().sessionStorage.setItem('oauth2-csrf-token', token);\n\n return token;\n },\n\n /**\n * Checks if the CSRF token in sessionStorage is the same as the one returned\n * in the url.\n * @instance\n * @memberof AuthorizationBrowserFirstParty\n * @param {Object} query\n * @private\n * @returns {Promise}\n */\n _verifySecurityToken(query) {\n const sessionToken = this.webex.getWindow().sessionStorage.getItem(OAUTH2_CSRF_TOKEN);\n\n this.webex.getWindow().sessionStorage.removeItem(OAUTH2_CSRF_TOKEN);\n if (!sessionToken) {\n return;\n }\n\n if (!query.state) {\n throw new Error(`Expected CSRF token ${sessionToken}, but not found in redirect query`);\n }\n\n if (!query.state.csrf_token) {\n throw new Error(`Expected CSRF token ${sessionToken}, but not found in redirect query`);\n }\n\n const token = query.state.csrf_token;\n\n if (token !== sessionToken) {\n throw new Error(`CSRF token ${token} does not match stored token ${sessionToken}`);\n }\n },\n});\n\nexport default Authorization;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAMA;AACA;AAEA;AACA;AAEA;AACA;AACA;AAAiC;AAEjC;AACA;AACA,IAAMA,MAAM,GAAGC,OAAO,CAAC,QAAQ,CAAC;AAEhC,IAAMC,iBAAiB,GAAG,mBAAmB;AAC7C,IAAMC,oBAAoB,GAAG,sBAAsB;;AAEnD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAMC,aAAa,GAAGC,sBAAW,CAACC,MAAM,SAiHrC,IAAAC,qBAAa,EAAC,eAAe,CAAC,UAgC9B,IAAAA,qBAAa,EAAC,eAAe,CAAC,UAjJQ;EACvCC,OAAO,EAAE;IACP;AACJ;AACA;AACA;AACA;AACA;IACIC,gBAAgB,EAAE;MAChBC,IAAI,EAAE,CAAC,eAAe,CAAC;MACvBC,EAAE,gBAAG;QACH,OAAO,IAAI,CAACC,aAAa;MAC3B;IACF;EACF,CAAC;EAEDC,OAAO,EAAE;IACP;AACJ;AACA;AACA;AACA;AACA;IACID,aAAa,EAAE;MACbE,OAAO,EAAE,KAAK;MACdC,IAAI,EAAE;IACR,CAAC;IACDC,KAAK,EAAE;MACLF,OAAO,EAAE,KAAK;MACdC,IAAI,EAAE;IACR;EACF,CAAC;EAEDE,SAAS,EAAE,aAAa;EAExB;AACF;AACA;AACA;AACA;AACA;AACA;EACE;EACAC,UAAU,wBAAW;IAAA;IAAA,kCAAPC,KAAK;MAALA,KAAK;IAAA;IACjB,IAAMC,GAAG,GAAG,oBAAcf,sBAAW,CAACgB,SAAS,CAACH,UAAU,EAAE,IAAI,EAAEC,KAAK,CAAC;IACxE,IAAMG,QAAQ,GAAGC,YAAG,CAACC,KAAK,CAAC,IAAI,CAACC,KAAK,CAACC,SAAS,EAAE,CAACJ,QAAQ,CAACK,IAAI,EAAE,IAAI,CAAC;IAEtE,IAAI,CAACC,eAAe,CAACN,QAAQ,CAAC;IAE9B,IAAO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I,CAAC,sCAAsC,CAAC;IAExD,IAAMmD,KAAK,GAAGC,aAAI,CAACC,EAAE,EAAE;IAEvB,IAAI,CAAC/F,KAAK,CAACC,SAAS,EAAE,CAACU,cAAc,CAACiF,OAAO,CAAC,mBAAmB,EAAEC,KAAK,CAAC;IAEzE,OAAOA,KAAK;EACd,CAAC;EAED;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACE9E,oBAAoB,gCAACV,KAAK,EAAE;IAC1B,IAAM2F,YAAY,GAAG,IAAI,CAAChG,KAAK,CAACC,SAAS,EAAE,CAACU,cAAc,CAACC,OAAO,CAACnC,iBAAiB,CAAC;IAErF,IAAI,CAACuB,KAAK,CAACC,SAAS,EAAE,CAACU,cAAc,CAACE,UAAU,CAACpC,iBAAiB,CAAC;IACnE,IAAI,CAACuH,YAAY,EAAE;MACjB;IACF;IAEA,IAAI,CAAC3F,KAAK,CAACC,KAAK,EAAE;MAChB,MAAM,IAAI4C,KAAK,+BAAwB8C,YAAY,uCAAoC;IACzF;IAEA,IAAI,CAAC3F,KAAK,CAACC,KAAK,CAAC8B,UAAU,EAAE;MAC3B,MAAM,IAAIc,KAAK,+BAAwB8C,YAAY,uCAAoC;IACzF;IAEA,IAAMH,KAAK,GAAGxF,KAAK,CAACC,KAAK,CAAC8B,UAAU;IAEpC,IAAIyD,KAAK,KAAKG,YAAY,EAAE;MAC1B,MAAM,IAAI9C,KAAK,sBAAe2C,KAAK,0CAAgCG,YAAY,EAAG;IACpF;EACF,CAAC;EAAA;AACH,CAAC,yQAxKEC,iBAAS,iGAwKV;AAAC,eAEYtH,aAAa;AAAA"}
|
package/dist/config.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
|
|
4
|
-
|
|
5
4
|
_Object$defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
|
-
|
|
9
7
|
exports.default = void 0;
|
|
10
|
-
|
|
11
8
|
/*!
|
|
12
9
|
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
13
10
|
*/
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["credentials","clientType","refreshCallback","webex","token","request","method","uri","config","tokenUrl","form","grant_type","redirect_uri","refresh_token","auth","user","client_id","pass","client_secret","sendImmediately","shouldRefreshAccessToken","then","res","body"],"sources":["config.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nexport default {\n credentials: {\n /**\n * Controls whether {@link Authorization#initiateLogin()} requests a token\n * or an auth code. Anything other than 'confidential' will be treated as\n * 'public'\n * @private\n * @type {string}\n */\n clientType: 'public',\n\n refreshCallback(webex, token) {\n /* eslint-disable camelcase */\n return webex.request({\n
|
|
1
|
+
{"version":3,"names":["credentials","clientType","refreshCallback","webex","token","request","method","uri","config","tokenUrl","form","grant_type","redirect_uri","refresh_token","auth","user","client_id","pass","client_secret","sendImmediately","shouldRefreshAccessToken","then","res","body"],"sources":["config.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nexport default {\n credentials: {\n /**\n * Controls whether {@link Authorization#initiateLogin()} requests a token\n * or an auth code. Anything other than 'confidential' will be treated as\n * 'public'\n * @private\n * @type {string}\n */\n clientType: 'public',\n\n refreshCallback(webex, token) {\n /* eslint-disable camelcase */\n return webex\n .request({\n method: 'POST',\n uri: token.config.tokenUrl,\n form: {\n grant_type: 'refresh_token',\n redirect_uri: token.config.redirect_uri,\n refresh_token: token.refresh_token,\n },\n auth: {\n user: token.config.client_id,\n pass: token.config.client_secret,\n sendImmediately: true,\n },\n shouldRefreshAccessToken: false,\n })\n .then((res) => res.body);\n /* eslint-enable camelcase */\n },\n },\n};\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AAFA,eAIe;EACbA,WAAW,EAAE;IACX;AACJ;AACA;AACA;AACA;AACA;AACA;IACIC,UAAU,EAAE,QAAQ;IAEpBC,eAAe,2BAACC,KAAK,EAAEC,KAAK,EAAE;MAC5B;MACA,OAAOD,KAAK,CACTE,OAAO,CAAC;QACPC,MAAM,EAAE,MAAM;QACdC,GAAG,EAAEH,KAAK,CAACI,MAAM,CAACC,QAAQ;QAC1BC,IAAI,EAAE;UACJC,UAAU,EAAE,eAAe;UAC3BC,YAAY,EAAER,KAAK,CAACI,MAAM,CAACI,YAAY;UACvCC,aAAa,EAAET,KAAK,CAACS;QACvB,CAAC;QACDC,IAAI,EAAE;UACJC,IAAI,EAAEX,KAAK,CAACI,MAAM,CAACQ,SAAS;UAC5BC,IAAI,EAAEb,KAAK,CAACI,MAAM,CAACU,aAAa;UAChCC,eAAe,EAAE;QACnB,CAAC;QACDC,wBAAwB,EAAE;MAC5B,CAAC,CAAC,CACDC,IAAI,CAAC,UAACC,GAAG;QAAA,OAAKA,GAAG,CAACC,IAAI;MAAA,EAAC;MAC1B;IACF;EACF;AACF,CAAC;AAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,36 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
|
|
4
|
-
|
|
5
4
|
var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
|
|
6
|
-
|
|
7
5
|
_Object$defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
|
-
|
|
11
8
|
_Object$defineProperty(exports, "config", {
|
|
12
9
|
enumerable: true,
|
|
13
10
|
get: function get() {
|
|
14
11
|
return _config.default;
|
|
15
12
|
}
|
|
16
13
|
});
|
|
17
|
-
|
|
18
14
|
_Object$defineProperty(exports, "default", {
|
|
19
15
|
enumerable: true,
|
|
20
16
|
get: function get() {
|
|
21
17
|
return _authorization.default;
|
|
22
18
|
}
|
|
23
19
|
});
|
|
24
|
-
|
|
25
20
|
var _webexCore = require("@webex/webex-core");
|
|
26
|
-
|
|
27
21
|
var _authorization = _interopRequireDefault(require("./authorization"));
|
|
28
|
-
|
|
29
22
|
var _config = _interopRequireDefault(require("./config"));
|
|
30
|
-
|
|
31
23
|
/*!
|
|
32
24
|
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
33
25
|
*/
|
|
26
|
+
|
|
34
27
|
var proxies = ['isAuthorizing', 'isAuthenticating'];
|
|
35
28
|
(0, _webexCore.registerPlugin)('authorization', _authorization.default, {
|
|
36
29
|
config: _config.default,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["proxies","registerPlugin","Authorization","config"],"sources":["index.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport {registerPlugin} from '@webex/webex-core';\n\nimport Authorization from './authorization';\nimport config from './config';\n\nconst proxies = [
|
|
1
|
+
{"version":3,"names":["proxies","registerPlugin","Authorization","config"],"sources":["index.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport {registerPlugin} from '@webex/webex-core';\n\nimport Authorization from './authorization';\nimport config from './config';\n\nconst proxies = ['isAuthorizing', 'isAuthenticating'];\n\nregisterPlugin('authorization', Authorization, {\n config,\n proxies,\n});\n\nexport {default} from './authorization';\nexport {default as config} from './config';\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAIA;AAEA;AACA;AAPA;AACA;AACA;;AAOA,IAAMA,OAAO,GAAG,CAAC,eAAe,EAAE,kBAAkB,CAAC;AAErD,IAAAC,yBAAc,EAAC,eAAe,EAAEC,sBAAa,EAAE;EAC7CC,MAAM,EAANA,eAAM;EACNH,OAAO,EAAPA;AACF,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webex/plugin-authorization-browser-first-party",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.400",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Ian W. Remmel <iremmel@cisco.com>",
|
|
@@ -25,15 +25,15 @@
|
|
|
25
25
|
"sinon": "^9.2.4"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@webex/common": "3.0.0-beta.
|
|
29
|
-
"@webex/plugin-authorization-browser-first-party": "3.0.0-beta.
|
|
30
|
-
"@webex/storage-adapter-local-storage": "3.0.0-beta.
|
|
31
|
-
"@webex/test-helper-automation": "3.0.0-beta.
|
|
32
|
-
"@webex/test-helper-chai": "3.0.0-beta.
|
|
33
|
-
"@webex/test-helper-mocha": "3.0.0-beta.
|
|
34
|
-
"@webex/test-helper-mock-webex": "3.0.0-beta.
|
|
35
|
-
"@webex/test-helper-test-users": "3.0.0-beta.
|
|
36
|
-
"@webex/webex-core": "3.0.0-beta.
|
|
28
|
+
"@webex/common": "3.0.0-beta.400",
|
|
29
|
+
"@webex/plugin-authorization-browser-first-party": "3.0.0-beta.400",
|
|
30
|
+
"@webex/storage-adapter-local-storage": "3.0.0-beta.400",
|
|
31
|
+
"@webex/test-helper-automation": "3.0.0-beta.400",
|
|
32
|
+
"@webex/test-helper-chai": "3.0.0-beta.400",
|
|
33
|
+
"@webex/test-helper-mocha": "3.0.0-beta.400",
|
|
34
|
+
"@webex/test-helper-mock-webex": "3.0.0-beta.400",
|
|
35
|
+
"@webex/test-helper-test-users": "3.0.0-beta.400",
|
|
36
|
+
"@webex/webex-core": "3.0.0-beta.400",
|
|
37
37
|
"crypto-js": "^4.1.1",
|
|
38
38
|
"lodash": "^4.17.21",
|
|
39
39
|
"uuid": "^3.3.2"
|