@webex/plugin-authorization-browser-first-party 3.12.0-webex-services-ready.4 → 3.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/config.js CHANGED
@@ -1,40 +1,69 @@
1
1
  "use strict";
2
2
 
3
+ var _Object$keys = require("@babel/runtime-corejs2/core-js/object/keys");
4
+ var _Object$getOwnPropertySymbols = require("@babel/runtime-corejs2/core-js/object/get-own-property-symbols");
5
+ var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptor");
6
+ var _Object$getOwnPropertyDescriptors = require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptors");
7
+ var _Object$defineProperties = require("@babel/runtime-corejs2/core-js/object/define-properties");
3
8
  var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
9
+ var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
4
10
  _Object$defineProperty(exports, "__esModule", {
5
11
  value: true
6
12
  });
7
- exports.default = void 0;
13
+ exports.getClientAuthenticationOptions = exports.default = void 0;
14
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/defineProperty"));
15
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/objectWithoutProperties"));
16
+ var _excluded = ["form"];
17
+ function ownKeys(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
18
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
8
19
  /*!
9
20
  * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
10
21
  */
22
+
23
+ var getClientAuthenticationOptions = exports.getClientAuthenticationOptions = function getClientAuthenticationOptions(config) {
24
+ if (config.clientType === 'public') {
25
+ return {
26
+ addAuthHeader: false,
27
+ form: {
28
+ client_id: config.client_id
29
+ }
30
+ };
31
+ }
32
+ return {
33
+ auth: {
34
+ user: config.client_id,
35
+ pass: config.client_secret,
36
+ sendImmediately: true
37
+ }
38
+ };
39
+ };
11
40
  var _default = exports.default = {
12
41
  credentials: {
13
42
  /**
14
- * Controls whether {@link Authorization#initiateLogin()} requests a token
15
- * or an auth code. Anything other than 'confidential' will be treated as
16
- * 'public'
43
+ * Controls how the OAuth client authenticates with the token endpoint.
44
+ * Public clients send their client ID in the request form. Confidential
45
+ * clients use HTTP Basic authentication with their client secret.
17
46
  * @private
18
47
  * @type {string}
19
48
  */
20
49
  clientType: 'public',
21
50
  refreshCallback: function refreshCallback(webex, token) {
22
51
  /* eslint-disable camelcase */
23
- return webex.request({
52
+ var _getClientAuthenticat = getClientAuthenticationOptions(token.config),
53
+ _getClientAuthenticat2 = _getClientAuthenticat.form,
54
+ clientForm = _getClientAuthenticat2 === void 0 ? {} : _getClientAuthenticat2,
55
+ clientAuthentication = (0, _objectWithoutProperties2.default)(_getClientAuthenticat, _excluded);
56
+ return webex.request(_objectSpread(_objectSpread({
24
57
  method: 'POST',
25
58
  uri: token.config.tokenUrl,
26
- form: {
59
+ form: _objectSpread({
27
60
  grant_type: 'refresh_token',
28
61
  redirect_uri: token.config.redirect_uri,
29
62
  refresh_token: token.refresh_token
30
- },
31
- auth: {
32
- user: token.config.client_id,
33
- pass: token.config.client_secret,
34
- sendImmediately: true
35
- },
63
+ }, clientForm)
64
+ }, clientAuthentication), {}, {
36
65
  shouldRefreshAccessToken: false
37
- }).then(function (res) {
66
+ })).then(function (res) {
38
67
  return res.body;
39
68
  });
40
69
  /* eslint-enable camelcase */
@@ -1 +1 @@
1
- {"version":3,"names":["_default","exports","default","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,IAAAA,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAIe;EACbC,WAAW,EAAE;IACX;AACJ;AACA;AACA;AACA;AACA;AACA;IACIC,UAAU,EAAE,QAAQ;IAEpBC,eAAe,WAAfA,eAAeA,CAACC,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","ignoreList":[]}
1
+ {"version":3,"names":["getClientAuthenticationOptions","exports","config","clientType","addAuthHeader","form","client_id","auth","user","pass","client_secret","sendImmediately","_default","default","credentials","refreshCallback","webex","token","_getClientAuthenticat","_getClientAuthenticat2","clientForm","clientAuthentication","_objectWithoutProperties2","_excluded","request","_objectSpread","method","uri","tokenUrl","grant_type","redirect_uri","refresh_token","shouldRefreshAccessToken","then","res","body"],"sources":["config.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nexport const getClientAuthenticationOptions = (config) => {\n if (config.clientType === 'public') {\n return {\n addAuthHeader: false,\n form: {\n client_id: config.client_id,\n },\n };\n }\n\n return {\n auth: {\n user: config.client_id,\n pass: config.client_secret,\n sendImmediately: true,\n },\n };\n};\n\nexport default {\n credentials: {\n /**\n * Controls how the OAuth client authenticates with the token endpoint.\n * Public clients send their client ID in the request form. Confidential\n * clients use HTTP Basic authentication with their client secret.\n * @private\n * @type {string}\n */\n clientType: 'public',\n\n refreshCallback(webex, token) {\n /* eslint-disable camelcase */\n const {form: clientForm = {}, ...clientAuthentication} = getClientAuthenticationOptions(\n token.config\n );\n\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 ...clientForm,\n },\n ...clientAuthentication,\n shouldRefreshAccessToken: false,\n })\n .then((res) => res.body);\n /* eslint-enable camelcase */\n },\n },\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;;AAEO,IAAMA,8BAA8B,GAAAC,OAAA,CAAAD,8BAAA,GAAG,SAAjCA,8BAA8BA,CAAIE,MAAM,EAAK;EACxD,IAAIA,MAAM,CAACC,UAAU,KAAK,QAAQ,EAAE;IAClC,OAAO;MACLC,aAAa,EAAE,KAAK;MACpBC,IAAI,EAAE;QACJC,SAAS,EAAEJ,MAAM,CAACI;MACpB;IACF,CAAC;EACH;EAEA,OAAO;IACLC,IAAI,EAAE;MACJC,IAAI,EAAEN,MAAM,CAACI,SAAS;MACtBG,IAAI,EAAEP,MAAM,CAACQ,aAAa;MAC1BC,eAAe,EAAE;IACnB;EACF,CAAC;AACH,CAAC;AAAC,IAAAC,QAAA,GAAAX,OAAA,CAAAY,OAAA,GAEa;EACbC,WAAW,EAAE;IACX;AACJ;AACA;AACA;AACA;AACA;AACA;IACIX,UAAU,EAAE,QAAQ;IAEpBY,eAAe,WAAfA,eAAeA,CAACC,KAAK,EAAEC,KAAK,EAAE;MAC5B;MACA,IAAAC,qBAAA,GAAyDlB,8BAA8B,CACrFiB,KAAK,CAACf,MACR,CAAC;QAAAiB,sBAAA,GAAAD,qBAAA,CAFMb,IAAI;QAAEe,UAAU,GAAAD,sBAAA,cAAG,CAAC,CAAC,GAAAA,sBAAA;QAAKE,oBAAoB,OAAAC,yBAAA,CAAAT,OAAA,EAAAK,qBAAA,EAAAK,SAAA;MAIrD,OAAOP,KAAK,CACTQ,OAAO,CAAAC,aAAA,CAAAA,aAAA;QACNC,MAAM,EAAE,MAAM;QACdC,GAAG,EAAEV,KAAK,CAACf,MAAM,CAAC0B,QAAQ;QAC1BvB,IAAI,EAAAoB,aAAA;UACFI,UAAU,EAAE,eAAe;UAC3BC,YAAY,EAAEb,KAAK,CAACf,MAAM,CAAC4B,YAAY;UACvCC,aAAa,EAAEd,KAAK,CAACc;QAAa,GAC/BX,UAAU;MACd,GACEC,oBAAoB;QACvBW,wBAAwB,EAAE;MAAK,EAChC,CAAC,CACDC,IAAI,CAAC,UAACC,GAAG;QAAA,OAAKA,GAAG,CAACC,IAAI;MAAA,EAAC;MAC1B;IACF;EACF;AACF,CAAC","ignoreList":[]}
package/dist/index.js CHANGED
@@ -14,6 +14,12 @@ _Object$defineProperty(exports, "Events", {
14
14
  return _authorization.Events;
15
15
  }
16
16
  });
17
+ _Object$defineProperty(exports, "InitialAuthorizationCodeGrantOutcomes", {
18
+ enumerable: true,
19
+ get: function get() {
20
+ return _authorization.InitialAuthorizationCodeGrantOutcomes;
21
+ }
22
+ });
17
23
  _Object$defineProperty(exports, "config", {
18
24
  enumerable: true,
19
25
  get: function get() {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["_webexCore","require","_authorization","_interopRequireWildcard","_config","_interopRequireDefault","e","t","_WeakMap","r","n","__esModule","o","i","f","__proto__","default","_typeof","has","get","set","_t","hasOwnProperty","call","_Object$defineProperty","_Object$getOwnPropertyDescriptor","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, Events} from './authorization';\nexport {default as config} from './config';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,IAAAA,UAAA,GAAAC,OAAA;AAEA,IAAAC,cAAA,GAAAC,uBAAA,CAAAF,OAAA;AACA,IAAAG,OAAA,GAAAC,sBAAA,CAAAJ,OAAA;AAA8B,SAAAE,wBAAAG,CAAA,EAAAC,CAAA,6BAAAC,QAAA,MAAAC,CAAA,OAAAD,QAAA,IAAAE,CAAA,OAAAF,QAAA,YAAAL,uBAAA,YAAAA,wBAAAG,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,gBAAAW,OAAA,CAAAX,CAAA,0BAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAM,GAAA,CAAAZ,CAAA,UAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,GAAAM,CAAA,CAAAQ,GAAA,CAAAd,CAAA,EAAAQ,CAAA,cAAAO,EAAA,IAAAf,CAAA,gBAAAe,EAAA,OAAAC,cAAA,CAAAC,IAAA,CAAAjB,CAAA,EAAAe,EAAA,OAAAR,CAAA,IAAAD,CAAA,GAAAY,sBAAA,KAAAC,gCAAA,CAAAnB,CAAA,EAAAe,EAAA,OAAAR,CAAA,CAAAM,GAAA,IAAAN,CAAA,CAAAO,GAAA,IAAAR,CAAA,CAAAE,CAAA,EAAAO,EAAA,EAAAR,CAAA,IAAAC,CAAA,CAAAO,EAAA,IAAAf,CAAA,CAAAe,EAAA,WAAAP,CAAA,KAAAR,CAAA,EAAAC,CAAA;AAP9B;AACA;AACA;;AAOA,IAAMmB,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","ignoreList":[]}
1
+ {"version":3,"names":["_webexCore","require","_authorization","_interopRequireWildcard","_config","_interopRequireDefault","e","t","_WeakMap","r","n","__esModule","o","i","f","__proto__","default","_typeof","has","get","set","_t","hasOwnProperty","call","_Object$defineProperty","_Object$getOwnPropertyDescriptor","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, Events, InitialAuthorizationCodeGrantOutcomes} from './authorization';\nexport {default as config} from './config';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,IAAAA,UAAA,GAAAC,OAAA;AAEA,IAAAC,cAAA,GAAAC,uBAAA,CAAAF,OAAA;AACA,IAAAG,OAAA,GAAAC,sBAAA,CAAAJ,OAAA;AAA8B,SAAAE,wBAAAG,CAAA,EAAAC,CAAA,6BAAAC,QAAA,MAAAC,CAAA,OAAAD,QAAA,IAAAE,CAAA,OAAAF,QAAA,YAAAL,uBAAA,YAAAA,wBAAAG,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,gBAAAW,OAAA,CAAAX,CAAA,0BAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAM,GAAA,CAAAZ,CAAA,UAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,GAAAM,CAAA,CAAAQ,GAAA,CAAAd,CAAA,EAAAQ,CAAA,cAAAO,EAAA,IAAAf,CAAA,gBAAAe,EAAA,OAAAC,cAAA,CAAAC,IAAA,CAAAjB,CAAA,EAAAe,EAAA,OAAAR,CAAA,IAAAD,CAAA,GAAAY,sBAAA,KAAAC,gCAAA,CAAAnB,CAAA,EAAAe,EAAA,OAAAR,CAAA,CAAAM,GAAA,IAAAN,CAAA,CAAAO,GAAA,IAAAR,CAAA,CAAAE,CAAA,EAAAO,EAAA,EAAAR,CAAA,IAAAC,CAAA,CAAAO,EAAA,IAAAf,CAAA,CAAAe,EAAA,WAAAP,CAAA,KAAAR,CAAA,EAAAC,CAAA;AAP9B;AACA;AACA;;AAOA,IAAMmB,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","ignoreList":[]}
package/package.json CHANGED
@@ -26,23 +26,23 @@
26
26
  "@webex/eslint-config-legacy": "0.0.0",
27
27
  "@webex/jest-config-legacy": "0.0.0",
28
28
  "@webex/legacy-tools": "0.0.0",
29
- "@webex/test-helper-chai": "3.12.0-webex-services-ready.4",
30
- "@webex/test-helper-mocha": "3.12.0-webex-services-ready.4",
31
- "@webex/test-helper-mock-webex": "3.12.0-webex-services-ready.4",
32
- "@webex/test-helper-test-users": "3.12.0-webex-services-ready.4",
29
+ "@webex/test-helper-chai": "3.13.0",
30
+ "@webex/test-helper-mocha": "3.13.0",
31
+ "@webex/test-helper-mock-webex": "3.13.0",
32
+ "@webex/test-helper-test-users": "3.13.0",
33
33
  "eslint": "^8.24.0",
34
34
  "prettier": "^2.7.1",
35
35
  "sinon": "^9.2.4"
36
36
  },
37
37
  "dependencies": {
38
- "@webex/common": "3.12.0-webex-services-ready.4",
39
- "@webex/storage-adapter-local-storage": "3.12.0-webex-services-ready.4",
40
- "@webex/test-helper-automation": "3.12.0-webex-services-ready.4",
41
- "@webex/test-helper-chai": "3.12.0-webex-services-ready.4",
42
- "@webex/test-helper-mocha": "3.12.0-webex-services-ready.4",
43
- "@webex/test-helper-mock-webex": "3.12.0-webex-services-ready.4",
44
- "@webex/test-helper-test-users": "3.12.0-webex-services-ready.4",
45
- "@webex/webex-core": "3.12.0-webex-services-ready.4",
38
+ "@webex/common": "3.13.0",
39
+ "@webex/storage-adapter-local-storage": "3.13.0",
40
+ "@webex/test-helper-automation": "3.13.0",
41
+ "@webex/test-helper-chai": "3.13.0",
42
+ "@webex/test-helper-mocha": "3.13.0",
43
+ "@webex/test-helper-mock-webex": "3.13.0",
44
+ "@webex/test-helper-test-users": "3.13.0",
45
+ "@webex/webex-core": "3.13.0",
46
46
  "crypto-js": "^4.1.1",
47
47
  "lodash": "^4.17.21",
48
48
  "uuid": "^3.3.2"
@@ -56,5 +56,5 @@
56
56
  "test:style": "eslint ./src/**/*.*",
57
57
  "test:unit": "webex-legacy-tools test --unit --runner jest"
58
58
  },
59
- "version": "3.12.0-webex-services-ready.4"
59
+ "version": "3.13.0"
60
60
  }
@@ -20,10 +20,7 @@ import {cloneDeep, isEmpty, omit, isObject} from 'lodash';
20
20
  import uuid from 'uuid';
21
21
  import base64url from 'crypto-js/enc-base64url';
22
22
  import CryptoJS from 'crypto-js';
23
-
24
- // Necessary to require lodash this way in order to stub
25
- // methods in the unit test
26
- const lodash = require('lodash');
23
+ import {getClientAuthenticationOptions} from './config';
27
24
 
28
25
  const OAUTH2_CSRF_TOKEN = 'oauth2-csrf-token';
29
26
  const OAUTH2_CODE_VERIFIER = 'oauth2-code-verifier';
@@ -39,6 +36,18 @@ export const Events = {
39
36
  qRCodeLogin: 'qRCodeLogin',
40
37
  };
41
38
 
39
+ /**
40
+ * Terminal outcomes for the automatic authorization-code exchange performed
41
+ * during authorization plugin initialization.
42
+ *
43
+ * @enum {string}
44
+ */
45
+ export const InitialAuthorizationCodeGrantOutcomes = {
46
+ failure: 'failure',
47
+ notAttempted: 'not_attempted',
48
+ success: 'success',
49
+ };
50
+
42
51
  /**
43
52
  * Browser support for OAuth2 for first-party (Webex Web Client) usage.
44
53
  *
@@ -69,6 +78,37 @@ export const Events = {
69
78
  */
70
79
  const Authorization = WebexPlugin.extend({
71
80
  derived: {
81
+ /**
82
+ * Retains the terminal outcome of the automatic authorization-code exchange
83
+ * performed during this authorization plugin instance's initialization.
84
+ *
85
+ * This historical value does not represent current authorization state,
86
+ * credentials hydrated from storage, guest authentication, or
87
+ * authorization-code exchanges requested later on the same SDK instance. It
88
+ * is not reset by logout. OAuth redirect errors and CSRF validation failures
89
+ * occur before the exchange, so the value remains not_attempted; these errors
90
+ * can throw before ready becomes true.
91
+ *
92
+ * Calling logout({noRedirect: true}) does not cancel an initialization
93
+ * exchange already in flight. If that exchange later settles, it can still
94
+ * update credentials and this retained outcome.
95
+ *
96
+ * Interpret only after authorization readiness:
97
+ * - not_attempted: initialization did not invoke requestAuthorizationCodeGrant()
98
+ * - success: the initialization exchange fulfilled
99
+ * - failure: the initialization exchange threw or rejected
100
+ *
101
+ * @instance
102
+ * @memberof AuthorizationBrowserFirstParty
103
+ * @readonly
104
+ * @type {string}
105
+ */
106
+ initialAuthorizationCodeGrantOutcome: {
107
+ deps: ['_initialAuthorizationCodeGrantOutcome'],
108
+ fn() {
109
+ return this._initialAuthorizationCodeGrantOutcome;
110
+ },
111
+ },
72
112
  /**
73
113
  * Alias of {@link AuthorizationBrowserFirstParty#isAuthorizing}
74
114
  * @instance
@@ -94,6 +134,14 @@ const Authorization = WebexPlugin.extend({
94
134
  default: false,
95
135
  type: 'boolean',
96
136
  },
137
+ /**
138
+ * Internal backing state for the initial authorization-code grant outcome.
139
+ * @private
140
+ */
141
+ _initialAuthorizationCodeGrantOutcome: {
142
+ default: InitialAuthorizationCodeGrantOutcomes.notAttempted,
143
+ type: 'string',
144
+ },
97
145
  /**
98
146
  * Indicates that the plugin has finished any automatic startup
99
147
  * processing (e.g., exchanging a returned authorization code)
@@ -233,7 +281,13 @@ const Authorization = WebexPlugin.extend({
233
281
  .collectPreauthCatalog(preauthCatalogParams)
234
282
  .catch(() => Promise.resolve()) // Non-fatal if catalog collection fails
235
283
  .then(() => this.requestAuthorizationCodeGrant({code, codeVerifier}))
284
+ .then(() => {
285
+ this._initialAuthorizationCodeGrantOutcome =
286
+ InitialAuthorizationCodeGrantOutcomes.success;
287
+ })
236
288
  .catch((error) => {
289
+ this._initialAuthorizationCodeGrantOutcome =
290
+ InitialAuthorizationCodeGrantOutcomes.failure;
237
291
  this.logger.warn('authorization: failed initial authorization code grant request', error);
238
292
  })
239
293
  .then(() => {
@@ -424,7 +478,12 @@ const Authorization = WebexPlugin.extend({
424
478
  this._verifySecurityToken(location.query, {requireMatch: true});
425
479
  this._cleanUrl(location);
426
480
 
427
- const {id_token: idToken, email, error, state: {csrf_token, ...state}} = location.query;
481
+ const {
482
+ id_token: idToken,
483
+ email,
484
+ error,
485
+ state: {csrf_token, ...state},
486
+ } = location.query;
428
487
 
429
488
  return {idToken, email, error, state};
430
489
  },
@@ -486,16 +545,15 @@ const Authorization = WebexPlugin.extend({
486
545
  form.code_verifier = options.codeVerifier;
487
546
  }
488
547
 
548
+ const {form: clientForm = {}, ...clientAuthentication} =
549
+ getClientAuthenticationOptions(this.config);
550
+
489
551
  return this.webex
490
552
  .request({
491
553
  method: 'POST',
492
554
  uri: this.config.tokenUrl,
493
- form,
494
- auth: {
495
- user: this.config.client_id,
496
- pass: this.config.client_secret,
497
- sendImmediately: true,
498
- },
555
+ form: {...form, ...clientForm},
556
+ ...clientAuthentication,
499
557
  shouldRefreshAccessToken: false, // This is the token acquisition call itself
500
558
  })
501
559
  .then((res) => {
@@ -825,7 +883,8 @@ const Authorization = WebexPlugin.extend({
825
883
  * during authorization code exchange; removes it once consumed.
826
884
  *
827
885
  * Implementation details:
828
- * - Creates a 128 character string using base64url safe alphabet.
886
+ * - Creates a 128 character string using a cryptographically secure random
887
+ * source and the base64url safe alphabet.
829
888
  * - Computes SHA256 hash, encodes to base64url (no padding).
830
889
  *
831
890
  * @instance
@@ -838,10 +897,14 @@ const Authorization = WebexPlugin.extend({
838
897
 
839
898
  // eslint-disable-next-line no-underscore-dangle
840
899
  const safeCharacterMap = base64url._safe_map;
900
+ const randomValues = new Uint8Array(128);
901
+
902
+ this.webex.getWindow().crypto.getRandomValues(randomValues);
841
903
 
842
- const codeVerifier = lodash
843
- .times(128, () => safeCharacterMap[lodash.random(0, safeCharacterMap.length - 1)])
844
- .join('');
904
+ const codeVerifier = Array.from(
905
+ randomValues,
906
+ (randomValue) => safeCharacterMap[randomValue & (safeCharacterMap.length - 1)]
907
+ ).join('');
845
908
 
846
909
  const codeChallenge = CryptoJS.SHA256(codeVerifier).toString(base64url);
847
910
 
package/src/config.js CHANGED
@@ -2,12 +2,31 @@
2
2
  * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
3
  */
4
4
 
5
+ export const getClientAuthenticationOptions = (config) => {
6
+ if (config.clientType === 'public') {
7
+ return {
8
+ addAuthHeader: false,
9
+ form: {
10
+ client_id: config.client_id,
11
+ },
12
+ };
13
+ }
14
+
15
+ return {
16
+ auth: {
17
+ user: config.client_id,
18
+ pass: config.client_secret,
19
+ sendImmediately: true,
20
+ },
21
+ };
22
+ };
23
+
5
24
  export default {
6
25
  credentials: {
7
26
  /**
8
- * Controls whether {@link Authorization#initiateLogin()} requests a token
9
- * or an auth code. Anything other than 'confidential' will be treated as
10
- * 'public'
27
+ * Controls how the OAuth client authenticates with the token endpoint.
28
+ * Public clients send their client ID in the request form. Confidential
29
+ * clients use HTTP Basic authentication with their client secret.
11
30
  * @private
12
31
  * @type {string}
13
32
  */
@@ -15,6 +34,10 @@ export default {
15
34
 
16
35
  refreshCallback(webex, token) {
17
36
  /* eslint-disable camelcase */
37
+ const {form: clientForm = {}, ...clientAuthentication} = getClientAuthenticationOptions(
38
+ token.config
39
+ );
40
+
18
41
  return webex
19
42
  .request({
20
43
  method: 'POST',
@@ -23,12 +46,9 @@ export default {
23
46
  grant_type: 'refresh_token',
24
47
  redirect_uri: token.config.redirect_uri,
25
48
  refresh_token: token.refresh_token,
49
+ ...clientForm,
26
50
  },
27
- auth: {
28
- user: token.config.client_id,
29
- pass: token.config.client_secret,
30
- sendImmediately: true,
31
- },
51
+ ...clientAuthentication,
32
52
  shouldRefreshAccessToken: false,
33
53
  })
34
54
  .then((res) => res.body);
package/src/index.js CHANGED
@@ -14,5 +14,5 @@ registerPlugin('authorization', Authorization, {
14
14
  proxies,
15
15
  });
16
16
 
17
- export {default, Events} from './authorization';
17
+ export {default, Events, InitialAuthorizationCodeGrantOutcomes} from './authorization';
18
18
  export {default as config} from './config';