@webex/plugin-authorization-browser-first-party 3.13.0-next.10 → 3.13.0-next.11

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.
@@ -953,7 +953,7 @@ var Authorization = _webexCore.WebexPlugin.extend((_dec = (0, _common.whileInFli
953
953
  throw new Error("CSRF token ".concat(token, " does not match stored token ").concat(sessionToken));
954
954
  }
955
955
  },
956
- version: "3.13.0-next.10"
956
+ version: "3.13.0-next.11"
957
957
  }, (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));
958
958
  var _default = exports.default = Authorization;
959
959
  //# sourceMappingURL=authorization.js.map
package/dist/config.js CHANGED
@@ -47,7 +47,18 @@ var _default = exports.default = {
47
47
  * @type {string}
48
48
  */
49
49
  clientType: 'public',
50
+ /**
51
+ * @param {Webex} webex
52
+ * @param {Token} token
53
+ * @param {Object} [options={}]
54
+ * @param {string} [options.scope] Scope to request on refresh, if same or narrower than existing scope
55
+ * @param {string} [options.upgradeScope] Scope to request on refresh, if broader than existing scope
56
+ * @returns {Promise<Object>}
57
+ */
50
58
  refreshCallback: function refreshCallback(webex, token) {
59
+ var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
60
+ scope = _ref.scope,
61
+ upgradeScope = _ref.upgradeScope;
51
62
  /* eslint-disable camelcase */
52
63
  var _getClientAuthenticat = getClientAuthenticationOptions(token.config),
53
64
  _getClientAuthenticat2 = _getClientAuthenticat.form,
@@ -56,11 +67,15 @@ var _default = exports.default = {
56
67
  return webex.request(_objectSpread(_objectSpread({
57
68
  method: 'POST',
58
69
  uri: token.config.tokenUrl,
59
- form: _objectSpread({
70
+ form: _objectSpread(_objectSpread(_objectSpread({
60
71
  grant_type: 'refresh_token',
61
72
  redirect_uri: token.config.redirect_uri,
62
73
  refresh_token: token.refresh_token
63
- }, clientForm)
74
+ }, scope && {
75
+ scope: scope
76
+ }), upgradeScope && {
77
+ upgrade_scope: upgradeScope
78
+ }), clientForm)
64
79
  }, clientAuthentication), {}, {
65
80
  shouldRefreshAccessToken: false
66
81
  })).then(function (res) {
@@ -1 +1 @@
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":";;;;;;;;;;;;;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C,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","_ref","arguments","length","undefined","scope","upgradeScope","_getClientAuthenticat","_getClientAuthenticat2","clientForm","clientAuthentication","_objectWithoutProperties2","_excluded","request","_objectSpread","method","uri","tokenUrl","grant_type","redirect_uri","refresh_token","upgrade_scope","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 /**\n * @param {Webex} webex\n * @param {Token} token\n * @param {Object} [options={}]\n * @param {string} [options.scope] Scope to request on refresh, if same or narrower than existing scope\n * @param {string} [options.upgradeScope] Scope to request on refresh, if broader than existing scope\n * @returns {Promise<Object>}\n */\n refreshCallback(webex, token, {scope, upgradeScope} = {}) {\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 ...(scope && {scope}),\n ...(upgradeScope && {upgrade_scope: upgradeScope}),\n ...clientForm,\n },\n ...clientAuthentication,\n shouldR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AAAA,aAAA;QACNC,MAAM,EAAE,MAAM;QACdC,GAAG,EAAEhB,KAAK,CAACf,MAAM,CAACgC,QAAQ;QAC1B7B,IAAI,EAAA0B,aAAA,CAAAA,aAAA,CAAAA,aAAA;UACFI,UAAU,EAAE,eAAe;UAC3BC,YAAY,EAAEnB,KAAK,CAACf,MAAM,CAACkC,YAAY;UACvCC,aAAa,EAAEpB,KAAK,CAACoB;QAAa,GAC9Bf,KAAK,IAAI;UAACA,KAAK,EAALA;QAAK,CAAC,GAChBC,YAAY,IAAI;UAACe,aAAa,EAAEf;QAAY,CAAC,GAC9CG,UAAU;MACd,GACEC,oBAAoB;QACvBY,wBAAwB,EAAE;MAAK,EAChC,CAAC,CACDC,IAAI,CAAC,UAACC,GAAG;QAAA,OAAKA,GAAG,CAACC,IAAI;MAAA,EAAC;MAC1B;IACF;EACF;AACF,CAAC","ignoreList":[]}
package/package.json CHANGED
@@ -36,13 +36,13 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "@webex/common": "3.13.0-next.4",
39
- "@webex/storage-adapter-local-storage": "3.13.0-next.9",
39
+ "@webex/storage-adapter-local-storage": "3.13.0-next.10",
40
40
  "@webex/test-helper-automation": "3.13.0-next.4",
41
41
  "@webex/test-helper-chai": "3.13.0-next.4",
42
42
  "@webex/test-helper-mocha": "3.13.0-next.4",
43
43
  "@webex/test-helper-mock-webex": "3.13.0-next.4",
44
44
  "@webex/test-helper-test-users": "3.13.0-next.4",
45
- "@webex/webex-core": "3.13.0-next.9",
45
+ "@webex/webex-core": "3.13.0-next.10",
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.13.0-next.10"
59
+ "version": "3.13.0-next.11"
60
60
  }
package/src/config.js CHANGED
@@ -32,7 +32,15 @@ export default {
32
32
  */
33
33
  clientType: 'public',
34
34
 
35
- refreshCallback(webex, token) {
35
+ /**
36
+ * @param {Webex} webex
37
+ * @param {Token} token
38
+ * @param {Object} [options={}]
39
+ * @param {string} [options.scope] Scope to request on refresh, if same or narrower than existing scope
40
+ * @param {string} [options.upgradeScope] Scope to request on refresh, if broader than existing scope
41
+ * @returns {Promise<Object>}
42
+ */
43
+ refreshCallback(webex, token, {scope, upgradeScope} = {}) {
36
44
  /* eslint-disable camelcase */
37
45
  const {form: clientForm = {}, ...clientAuthentication} = getClientAuthenticationOptions(
38
46
  token.config
@@ -46,6 +54,8 @@ export default {
46
54
  grant_type: 'refresh_token',
47
55
  redirect_uri: token.config.redirect_uri,
48
56
  refresh_token: token.refresh_token,
57
+ ...(scope && {scope}),
58
+ ...(upgradeScope && {upgrade_scope: upgradeScope}),
49
59
  ...clientForm,
50
60
  },
51
61
  ...clientAuthentication,
@@ -160,7 +160,7 @@ the [package architecture](../../docs/architecture.md#public-and-consumer-surfac
160
160
  | `MOD-010` | `requestAuthorizationCodeGrant` rejects without `code`; otherwise it POSTs an `authorization_code` form with `redirect_uri`, `code`, `self_contained_token: true`, and an optional `code_verifier` to `config.tokenUrl` with `shouldRefreshAccessToken: false`, then sets the response body as the supertoken. | The comments: request the combined access and refresh response; this call is token acquisition itself. | `src/authorization.js` | `test/unit/spec/authorization.js` "uses the client ID in the form for a public client", "uses HTTP Basic authentication for a confidential client" | The missing-code rejection is untested | Present |
161
161
  | `MOD-011` | A 400 response from the code exchange rejects with `grantErrors.select(body.error)` built from the response; every other rejection propagates unchanged. | The JSDoc: map standard OAuth errors to typed error classes. | `src/authorization.js` | None found | No unit case covers either branch | Weak |
162
162
  | `MOD-012` | Client authentication for the code exchange and the refresh callback follows `config.clientType`: `public` sends `client_id` in the form with `addAuthHeader: false`; any other value sends HTTP Basic `client_id`/`client_secret`. The default is `public`. | The `clientType` JSDoc states the public and confidential behaviors. | `src/config.js`, `src/authorization.js` | `test/unit/spec/authorization.js` "uses the client ID in the form for a public client" and "uses HTTP Basic authentication for a confidential client" under both the exchange and `refreshCallback()` | None | Present |
163
- | `MOD-013` | `credentials.refreshCallback(webex, token)` POSTs a `refresh_token` grant with `redirect_uri` and `refresh_token` to `token.config.tokenUrl` and resolves with the response body. | Without a refresh callback a browser token cannot refresh (webex-core credentials spec). | `src/config.js` | `test/unit/spec/authorization.js` "refreshCallback()" cases | None | Present |
163
+ | `MOD-013` | `credentials.refreshCallback(webex, token, {scope, upgradeScope} = {})` POSTs a `refresh_token` grant with `redirect_uri` and `refresh_token` to `token.config.tokenUrl` and resolves with the response body. When supplied, `scope` is sent as `scope` and `upgradeScope` as `upgrade_scope`; absent values are omitted from the form. | Without a refresh callback a browser token cannot refresh (webex-core credentials spec). Explicit scope requests support intentional narrowing; webex-core selects between scope and scope upgrading. | `src/config.js` | `test/unit/spec/authorization.js` "refreshCallback()" cases | None | Present |
164
164
  | `MOD-014` | `initiateThirdPartyLogin` throws synchronously when `state` is defined but not an object; otherwise it clones the options, adds `state.csrf_token`, and calls `initiateThirdPartyLoginRedirect`. | The JSDoc: the caller state is merged with the generated token. | `src/authorization.js` | `test/unit/spec/authorization.js` "throws (before generating a csrf_token) when state is supplied but is not an object", "merges generated csrf_token into caller-supplied state without mutating the caller object" | None | Present |
165
165
  | `MOD-015` | `initiateThirdPartyLoginRedirect` assigns `buildThirdPartyLoginUrl(options)` to `window.location` and resolves; a builder throw becomes a rejected promise. | The JSDoc: consumers may override it for custom navigation, for example postMessage in iframes. | `src/authorization.js` | `test/unit/spec/authorization.js` "builds the third-party login URL and assigns it to getWindow().location", "returns a rejected promise if buildThirdPartyLoginUrl throws" | None | Present |
166
166
  | `MOD-016` | `handleThirdPartyCallback` decodes `state` (default `e30`, the encoding of `{}`), requires a stored CSRF token that matches, scrubs `code`, `id_token`, `email`, and the CSRF token from the URL, and returns `{idToken, email, error, state}` without `csrf_token`. | The JSDoc: `idToken` is single-use and parsed out of the URL exactly once. | `src/authorization.js` | `test/unit/spec/authorization.js` "CSRF round-trip succeeds, scrubs sensitive params, and resolves with payload" and six failure cases | None | Present |
@@ -523,7 +523,7 @@ exchange, so the outcome stays `not_attempted` and `ready` stays `false`.
523
523
  | Authorize URL query: `response_type=code`, `client_id`, `redirect_uri`, `scope`, `state`, `emailHash`, `code_challenge`, `code_challenge_method=S256`, plus any other option such as `separateWindow` | OAuth 2.0 with PKCE | `initiateLogin` and `initiateAuthorizationCodeGrant` through credentials `buildLoginUrl` | Identity broker | `state` is base64url JSON with `csrf_token`, `emailhash`, and caller fields; `client_id`, `redirect_uri`, `scope` come from config |
524
524
  | Redirect query: `code`, `state`, `error`; third-party adds `id_token`, `email` | OAuth 2.0 | Identity broker or provider | `initialize`, `handleThirdPartyCallback` | An authorization code may carry an org id as its third `_` segment |
525
525
  | Code exchange form: `grant_type=authorization_code`, `redirect_uri`, `code`, `self_contained_token=true`, optional `code_verifier`, plus `client_id` for public clients | OAuth 2.0 | `requestAuthorizationCodeGrant` | Token endpoint at `config.tokenUrl` | Response body is the supertoken; 400 body `{error}` maps through `grantErrors` |
526
- | Refresh form: `grant_type=refresh_token`, `redirect_uri`, `refresh_token`, plus `client_id` for public clients | OAuth 2.0 | `credentials.refreshCallback` | Token endpoint at `token.config.tokenUrl` | Resolves the response body |
526
+ | Refresh form: `grant_type=refresh_token`, `redirect_uri`, `refresh_token`, optional `scope` or `upgrade_scope`, plus `client_id` for public clients | OAuth 2.0 | `credentials.refreshCallback` | Token endpoint at `token.config.tokenUrl` | Resolves the response body; webex-core chooses `scope` to retain or narrow configured scopes, or `upgrade_scope` to request missing configured scopes when enabled |
527
527
  | Device authorize form `{client_id, scope}`; response `user_code`, `verification_uri`, `verification_uri_complete`, `device_code`, `interval`, `expires_in` | OAuth device grant | `initQRCodeLogin` | `oauth-helper` `/actions/device/authorize` | HTTP Basic `client_id`/`client_secret` |
528
528
  | Device token form `{grant_type: urn:ietf:params:oauth:grant-type:device_code, device_code, client_id}` | OAuth device grant | `_startQRCodePolling` | `oauth-helper` `/actions/device/token` | 200 is the token body; 428 pending; 400 with `message: 'slow_down'` backs off |
529
529
  | QR verification URL `https://web.webex.com/deviceAuth?usercode=...&oauthhelper=...` | Unversioned | `_generateQRCodeVerificationUrl` | Webex web on the scanning device | Produced only when the URI has a `userCode` parameter |
@@ -537,6 +537,53 @@ describe('plugin-authorization-browser-first-party', () => {
537
537
  });
538
538
  assert.deepEqual(response, tokenResponse);
539
539
  });
540
+
541
+ [
542
+ {
543
+ description: 'uses the upgrade scope when provided',
544
+ options: {upgradeScope: 'scope:one scope:two'},
545
+ form: {upgrade_scope: 'scope:one scope:two'},
546
+ },
547
+ {
548
+ description: 'uses the explicit scope when provided',
549
+ options: {scope: 'scope:one'},
550
+ form: {scope: 'scope:one'},
551
+ },
552
+ ].forEach(({description, options, form}) => {
553
+ it(description, async () => {
554
+ const webex = {request: sinon.stub().resolves({body: tokenResponse})};
555
+ const token = {
556
+ refresh_token: 'current-refresh-token',
557
+ config: {
558
+ clientType: 'public',
559
+ client_id: 'public-client-id',
560
+ redirect_uri: 'http://example.com',
561
+ tokenUrl: 'https://idbroker.example.com/access_token',
562
+ },
563
+ };
564
+
565
+ const response = await authorizationConfig.credentials.refreshCallback(
566
+ webex,
567
+ token,
568
+ options
569
+ );
570
+
571
+ assert.calledOnceWithExactly(webex.request, {
572
+ method: 'POST',
573
+ uri: 'https://idbroker.example.com/access_token',
574
+ form: {
575
+ grant_type: 'refresh_token',
576
+ redirect_uri: 'http://example.com',
577
+ refresh_token: 'current-refresh-token',
578
+ ...form,
579
+ client_id: 'public-client-id',
580
+ },
581
+ addAuthHeader: false,
582
+ shouldRefreshAccessToken: false,
583
+ });
584
+ assert.deepEqual(response, tokenResponse);
585
+ });
586
+ });
540
587
  });
541
588
 
542
589
  describe('#initiateLogin()', () => {