@webex/plugin-authorization-browser-first-party 3.0.0-beta.9 → 3.0.0-beta.91
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 +8 -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 +33 -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 +177 -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
|
|
@@ -155,7 +121,6 @@ var Authorization = _webexCore.WebexPlugin.extend((_dec = (0, _common.whileInFli
|
|
|
155
121
|
});
|
|
156
122
|
return ret;
|
|
157
123
|
},
|
|
158
|
-
|
|
159
124
|
/**
|
|
160
125
|
* Kicks off an oauth flow
|
|
161
126
|
* @instance
|
|
@@ -166,21 +131,18 @@ var Authorization = _webexCore.WebexPlugin.extend((_dec = (0, _common.whileInFli
|
|
|
166
131
|
initiateLogin: function initiateLogin() {
|
|
167
132
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
168
133
|
options = (0, _cloneDeep2.default)(options);
|
|
169
|
-
|
|
170
134
|
if (options.email) {
|
|
171
135
|
options.emailHash = _cryptoJs.default.SHA256(options.email).toString();
|
|
172
136
|
}
|
|
173
|
-
|
|
174
137
|
delete options.email;
|
|
175
138
|
options.state = options.state || {};
|
|
176
|
-
options.state.csrf_token = this._generateSecurityToken();
|
|
177
|
-
|
|
139
|
+
options.state.csrf_token = this._generateSecurityToken();
|
|
140
|
+
// catalog uses emailhash and redirectCI uses emailHash
|
|
178
141
|
options.state.emailhash = options.emailHash;
|
|
179
142
|
options.code_challenge = this._generateCodeChallenge();
|
|
180
143
|
options.code_challenge_method = 'S256';
|
|
181
144
|
return this.initiateAuthorizationCodeGrant(options);
|
|
182
145
|
},
|
|
183
|
-
|
|
184
146
|
/**
|
|
185
147
|
* Kicks off the Implicit Code grant flow. Typically called via
|
|
186
148
|
* {@link AuthorizationBrowserFirstParty#initiateLogin}
|
|
@@ -196,7 +158,6 @@ var Authorization = _webexCore.WebexPlugin.extend((_dec = (0, _common.whileInFli
|
|
|
196
158
|
}, options));
|
|
197
159
|
return _promise.default.resolve();
|
|
198
160
|
},
|
|
199
|
-
|
|
200
161
|
/**
|
|
201
162
|
* Called by {@link WebexCore#logout()}. Redirects to the logout page
|
|
202
163
|
* @instance
|
|
@@ -207,12 +168,10 @@ var Authorization = _webexCore.WebexPlugin.extend((_dec = (0, _common.whileInFli
|
|
|
207
168
|
*/
|
|
208
169
|
logout: function logout() {
|
|
209
170
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
210
|
-
|
|
211
171
|
if (!options.noRedirect) {
|
|
212
172
|
this.webex.getWindow().location = this.webex.credentials.buildLogoutUrl(options);
|
|
213
173
|
}
|
|
214
174
|
},
|
|
215
|
-
|
|
216
175
|
/**
|
|
217
176
|
* Exchanges an authorization code for an access token
|
|
218
177
|
* @instance
|
|
@@ -223,25 +182,20 @@ var Authorization = _webexCore.WebexPlugin.extend((_dec = (0, _common.whileInFli
|
|
|
223
182
|
*/
|
|
224
183
|
requestAuthorizationCodeGrant: function requestAuthorizationCodeGrant() {
|
|
225
184
|
var _this2 = this;
|
|
226
|
-
|
|
227
185
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
228
186
|
this.logger.info('credentials: requesting authorization code grant');
|
|
229
|
-
|
|
230
187
|
if (!options.code) {
|
|
231
188
|
return _promise.default.reject(new Error('`options.code` is required'));
|
|
232
189
|
}
|
|
233
|
-
|
|
234
190
|
var form = {
|
|
235
191
|
grant_type: 'authorization_code',
|
|
236
192
|
redirect_uri: this.config.redirect_uri,
|
|
237
193
|
code: options.code,
|
|
238
194
|
self_contained_token: true
|
|
239
195
|
};
|
|
240
|
-
|
|
241
196
|
if (options.codeVerifier) {
|
|
242
197
|
form.code_verifier = options.codeVerifier;
|
|
243
198
|
}
|
|
244
|
-
|
|
245
199
|
return this.webex.request({
|
|
246
200
|
method: 'POST',
|
|
247
201
|
uri: this.config.tokenUrl,
|
|
@@ -260,13 +214,10 @@ var Authorization = _webexCore.WebexPlugin.extend((_dec = (0, _common.whileInFli
|
|
|
260
214
|
if (res.statusCode !== 400) {
|
|
261
215
|
return _promise.default.reject(res);
|
|
262
216
|
}
|
|
263
|
-
|
|
264
217
|
var ErrorConstructor = _webexCore.grantErrors.select(res.body.error);
|
|
265
|
-
|
|
266
218
|
return _promise.default.reject(new ErrorConstructor(res._res || res));
|
|
267
219
|
});
|
|
268
220
|
},
|
|
269
|
-
|
|
270
221
|
/**
|
|
271
222
|
* Checks if the result of the login redirect contains an error string
|
|
272
223
|
* @instance
|
|
@@ -277,14 +228,11 @@ var Authorization = _webexCore.WebexPlugin.extend((_dec = (0, _common.whileInFli
|
|
|
277
228
|
*/
|
|
278
229
|
_checkForErrors: function _checkForErrors(location) {
|
|
279
230
|
var query = location.query;
|
|
280
|
-
|
|
281
231
|
if (query && query.error) {
|
|
282
232
|
var ErrorConstructor = _webexCore.grantErrors.select(query.error);
|
|
283
|
-
|
|
284
233
|
throw new ErrorConstructor(query);
|
|
285
234
|
}
|
|
286
235
|
},
|
|
287
|
-
|
|
288
236
|
/**
|
|
289
237
|
* Removes no-longer needed values from the url (access token, csrf token, etc)
|
|
290
238
|
* @instance
|
|
@@ -295,22 +243,18 @@ var Authorization = _webexCore.WebexPlugin.extend((_dec = (0, _common.whileInFli
|
|
|
295
243
|
*/
|
|
296
244
|
_cleanUrl: function _cleanUrl(location) {
|
|
297
245
|
location = (0, _cloneDeep2.default)(location);
|
|
298
|
-
|
|
299
246
|
if (this.webex.getWindow().history && this.webex.getWindow().history.replaceState) {
|
|
300
247
|
(0, _deleteProperty.default)(location.query, 'code');
|
|
301
|
-
|
|
302
248
|
if ((0, _isEmpty2.default)((0, _omit2.default)(location.query.state, 'csrf_token'))) {
|
|
303
249
|
(0, _deleteProperty.default)(location.query, 'state');
|
|
304
250
|
} else {
|
|
305
251
|
location.query.state = _common.base64.encode((0, _stringify.default)((0, _omit2.default)(location.query.state, 'csrf_token')));
|
|
306
252
|
}
|
|
307
|
-
|
|
308
253
|
location.search = _querystring.default.stringify(location.query);
|
|
309
254
|
(0, _deleteProperty.default)(location, 'query');
|
|
310
255
|
this.webex.getWindow().history.replaceState({}, null, _url.default.format(location));
|
|
311
256
|
}
|
|
312
257
|
},
|
|
313
|
-
|
|
314
258
|
/**
|
|
315
259
|
* Generates PKCE code verifier and code challenge and sets the the code verifier in sessionStorage
|
|
316
260
|
* @instance
|
|
@@ -319,19 +263,17 @@ var Authorization = _webexCore.WebexPlugin.extend((_dec = (0, _common.whileInFli
|
|
|
319
263
|
* @returns {string}
|
|
320
264
|
*/
|
|
321
265
|
_generateCodeChallenge: function _generateCodeChallenge() {
|
|
322
|
-
this.logger.info('authorization: generating PKCE code challenge');
|
|
266
|
+
this.logger.info('authorization: generating PKCE code challenge');
|
|
323
267
|
|
|
268
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
324
269
|
var safeCharacterMap = _encBase64url.default._safe_map;
|
|
325
270
|
var codeVerifier = lodash.times(128, function () {
|
|
326
271
|
return safeCharacterMap[lodash.random(0, safeCharacterMap.length - 1)];
|
|
327
272
|
}).join('');
|
|
328
|
-
|
|
329
273
|
var codeChallenge = _cryptoJs.default.SHA256(codeVerifier).toString(_encBase64url.default);
|
|
330
|
-
|
|
331
274
|
this.webex.getWindow().sessionStorage.setItem(OAUTH2_CODE_VERIFIER, codeVerifier);
|
|
332
275
|
return codeChallenge;
|
|
333
276
|
},
|
|
334
|
-
|
|
335
277
|
/**
|
|
336
278
|
* Generates a CSRF token and sticks in in sessionStorage
|
|
337
279
|
* @instance
|
|
@@ -341,13 +283,10 @@ var Authorization = _webexCore.WebexPlugin.extend((_dec = (0, _common.whileInFli
|
|
|
341
283
|
*/
|
|
342
284
|
_generateSecurityToken: function _generateSecurityToken() {
|
|
343
285
|
this.logger.info('authorization: generating csrf token');
|
|
344
|
-
|
|
345
286
|
var token = _uuid.default.v4();
|
|
346
|
-
|
|
347
287
|
this.webex.getWindow().sessionStorage.setItem('oauth2-csrf-token', token);
|
|
348
288
|
return token;
|
|
349
289
|
},
|
|
350
|
-
|
|
351
290
|
/**
|
|
352
291
|
* Checks if the CSRF token in sessionStorage is the same as the one returned
|
|
353
292
|
* in the url.
|
|
@@ -360,28 +299,22 @@ var Authorization = _webexCore.WebexPlugin.extend((_dec = (0, _common.whileInFli
|
|
|
360
299
|
_verifySecurityToken: function _verifySecurityToken(query) {
|
|
361
300
|
var sessionToken = this.webex.getWindow().sessionStorage.getItem(OAUTH2_CSRF_TOKEN);
|
|
362
301
|
this.webex.getWindow().sessionStorage.removeItem(OAUTH2_CSRF_TOKEN);
|
|
363
|
-
|
|
364
302
|
if (!sessionToken) {
|
|
365
303
|
return;
|
|
366
304
|
}
|
|
367
|
-
|
|
368
305
|
if (!query.state) {
|
|
369
306
|
throw new Error("Expected CSRF token ".concat(sessionToken, ", but not found in redirect query"));
|
|
370
307
|
}
|
|
371
|
-
|
|
372
308
|
if (!query.state.csrf_token) {
|
|
373
309
|
throw new Error("Expected CSRF token ".concat(sessionToken, ", but not found in redirect query"));
|
|
374
310
|
}
|
|
375
|
-
|
|
376
311
|
var token = query.state.csrf_token;
|
|
377
|
-
|
|
378
312
|
if (token !== sessionToken) {
|
|
379
313
|
throw new Error("CSRF token ".concat(token, " does not match stored token ").concat(sessionToken));
|
|
380
314
|
}
|
|
381
315
|
},
|
|
382
|
-
version: "3.0.0-beta.
|
|
316
|
+
version: "3.0.0-beta.91"
|
|
383
317
|
}, ((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
318
|
var _default = Authorization;
|
|
386
319
|
exports.default = _default;
|
|
387
320
|
//# 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,IAAAA,qBAAA,EAAc,eAAd,CAhJmB,UAAmB;EACvCC,OAAO,EAAE;IACP;AACJ;AACA;AACA;AACA;AACA;IACIC,gBAAgB,EAAE;MAChBC,IAAI,EAAE,CAAC,eAAD,CADU;MAEhBC,EAFgB,gBAEX;QACH,OAAO,KAAKC,aAAZ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AY2B,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","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 } 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 .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,GA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C,iBAAiB,CAAC;IAErF,IAAI,CAACuB,KAAK,CAACC,SAAS,EAAE,CAACU,cAAc,CAACE,UAAU,CAACpC,iBAAiB,CAAC;IACnE,IAAI,CAACsH,YAAY,EAAE;MACjB;IACF;IAEA,IAAI,CAAC1F,KAAK,CAACC,KAAK,EAAE;MAChB,MAAM,IAAI0C,KAAK,+BAAwB+C,YAAY,uCAAoC;IACzF;IAEA,IAAI,CAAC1F,KAAK,CAACC,KAAK,CAAC2B,UAAU,EAAE;MAC3B,MAAM,IAAIe,KAAK,+BAAwB+C,YAAY,uCAAoC;IACzF;IAEA,IAAMH,KAAK,GAAGvF,KAAK,CAACC,KAAK,CAAC2B,UAAU;IAEpC,IAAI2D,KAAK,KAAKG,YAAY,EAAE;MAC1B,MAAM,IAAI/C,KAAK,sBAAe4C,KAAK,0CAAgCG,YAAY,EAAG;IACpF;EACF,CAAC;EAAA;AACH,CAAC,yQAxKEC,iBAAS,iGAwKV;AAAC,eAEYrH,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.91",
|
|
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.91",
|
|
29
|
+
"@webex/plugin-authorization-browser-first-party": "3.0.0-beta.91",
|
|
30
|
+
"@webex/storage-adapter-local-storage": "3.0.0-beta.91",
|
|
31
|
+
"@webex/test-helper-automation": "3.0.0-beta.91",
|
|
32
|
+
"@webex/test-helper-chai": "3.0.0-beta.91",
|
|
33
|
+
"@webex/test-helper-mocha": "3.0.0-beta.91",
|
|
34
|
+
"@webex/test-helper-mock-webex": "3.0.0-beta.91",
|
|
35
|
+
"@webex/test-helper-test-users": "3.0.0-beta.91",
|
|
36
|
+
"@webex/webex-core": "3.0.0-beta.91",
|
|
37
37
|
"crypto-js": "^4.1.1",
|
|
38
38
|
"lodash": "^4.17.21",
|
|
39
39
|
"uuid": "^3.3.2"
|