@webex/plugin-authorization-node 2.59.3-next.1 → 2.59.4-next.1
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/.eslintrc.js +6 -6
- package/README.md +53 -53
- package/babel.config.js +3 -3
- package/dist/authorization.js +44 -44
- package/dist/authorization.js.map +1 -1
- package/dist/config.js +2 -2
- package/dist/config.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/jest.config.js +3 -3
- package/package.json +9 -9
- package/process +1 -1
- package/src/authorization.js +184 -184
- package/src/config.js +7 -7
- package/src/index.js +19 -19
- package/test/integration/spec/authorization.js +166 -166
- package/test/unit/spec/authorization.js +69 -69
package/.eslintrc.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const config = {
|
|
2
|
-
root: true,
|
|
3
|
-
extends: ['@webex/eslint-config-legacy'],
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
module.exports = config;
|
|
1
|
+
const config = {
|
|
2
|
+
root: true,
|
|
3
|
+
extends: ['@webex/eslint-config-legacy'],
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
module.exports = config;
|
package/README.md
CHANGED
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
# @webex/plugin-authorization-node
|
|
2
|
-
|
|
3
|
-
[](https://github.com/RichardLitt/standard-readme)
|
|
4
|
-
|
|
5
|
-
> Authorization plugin loaded when the Cisco Webex JS SDK is used in a non-browser environment.
|
|
6
|
-
|
|
7
|
-
- [Install](#install)
|
|
8
|
-
- [Usage](#usage)
|
|
9
|
-
- [Contribute](#contribute)
|
|
10
|
-
- [Maintainers](#maintainers)
|
|
11
|
-
- [License](#license)
|
|
12
|
-
|
|
13
|
-
## Install
|
|
14
|
-
|
|
15
|
-
```bash
|
|
16
|
-
npm install --save @webex/plugin-authorization-node
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
## Usage
|
|
20
|
-
|
|
21
|
-
This is a plugin for the Cisco Webex JS SDK . Please see our [developer portal](https://developer.webex.com/) and the [API docs](https://webex.github.io/webex-js-sdk/api/) for full details.
|
|
22
|
-
|
|
23
|
-
## Install
|
|
24
|
-
|
|
25
|
-
```bash
|
|
26
|
-
npm install --save @webex/plugin-authorization-node
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
## Usage
|
|
30
|
-
|
|
31
|
-
```js
|
|
32
|
-
|
|
33
|
-
const Webex = require('webex');
|
|
34
|
-
|
|
35
|
-
const webex = Webex.init();
|
|
36
|
-
webex.authorization-node.get(id)
|
|
37
|
-
.then((authorization-node) => {
|
|
38
|
-
console.log(authorization-node);
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
## Maintainers
|
|
44
|
-
|
|
45
|
-
This package is maintained by [Cisco Webex for Developers](https://developer.webex.com/).
|
|
46
|
-
|
|
47
|
-
## Contribute
|
|
48
|
-
|
|
49
|
-
Pull requests welcome. Please see [CONTRIBUTING.md](https://github.com/webex/webex-js-sdk/blob/master/CONTRIBUTING.md) for more details.
|
|
50
|
-
|
|
51
|
-
## License
|
|
52
|
-
|
|
53
|
-
© 2016-2020 Cisco and/or its affiliates. All Rights Reserved.
|
|
1
|
+
# @webex/plugin-authorization-node
|
|
2
|
+
|
|
3
|
+
[](https://github.com/RichardLitt/standard-readme)
|
|
4
|
+
|
|
5
|
+
> Authorization plugin loaded when the Cisco Webex JS SDK is used in a non-browser environment.
|
|
6
|
+
|
|
7
|
+
- [Install](#install)
|
|
8
|
+
- [Usage](#usage)
|
|
9
|
+
- [Contribute](#contribute)
|
|
10
|
+
- [Maintainers](#maintainers)
|
|
11
|
+
- [License](#license)
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install --save @webex/plugin-authorization-node
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
This is a plugin for the Cisco Webex JS SDK . Please see our [developer portal](https://developer.webex.com/) and the [API docs](https://webex.github.io/webex-js-sdk/api/) for full details.
|
|
22
|
+
|
|
23
|
+
## Install
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install --save @webex/plugin-authorization-node
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
```js
|
|
32
|
+
|
|
33
|
+
const Webex = require('webex');
|
|
34
|
+
|
|
35
|
+
const webex = Webex.init();
|
|
36
|
+
webex.authorization-node.get(id)
|
|
37
|
+
.then((authorization-node) => {
|
|
38
|
+
console.log(authorization-node);
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Maintainers
|
|
44
|
+
|
|
45
|
+
This package is maintained by [Cisco Webex for Developers](https://developer.webex.com/).
|
|
46
|
+
|
|
47
|
+
## Contribute
|
|
48
|
+
|
|
49
|
+
Pull requests welcome. Please see [CONTRIBUTING.md](https://github.com/webex/webex-js-sdk/blob/master/CONTRIBUTING.md) for more details.
|
|
50
|
+
|
|
51
|
+
## License
|
|
52
|
+
|
|
53
|
+
© 2016-2020 Cisco and/or its affiliates. All Rights Reserved.
|
package/babel.config.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
const babelConfigLegacy = require('@webex/babel-config-legacy');
|
|
2
|
-
|
|
3
|
-
module.exports = babelConfigLegacy;
|
|
1
|
+
const babelConfigLegacy = require('@webex/babel-config-legacy');
|
|
2
|
+
|
|
3
|
+
module.exports = babelConfigLegacy;
|
package/dist/authorization.js
CHANGED
|
@@ -14,18 +14,18 @@ var _webexCore = require("@webex/webex-core");
|
|
|
14
14
|
var _jsonwebtoken = _interopRequireDefault(require("jsonwebtoken"));
|
|
15
15
|
var _uuid = _interopRequireDefault(require("uuid"));
|
|
16
16
|
var _dec, _obj;
|
|
17
|
-
/**
|
|
18
|
-
* NodeJS support for OAuth2
|
|
19
|
-
* @class
|
|
20
|
-
* @name AuthorizationNode
|
|
17
|
+
/**
|
|
18
|
+
* NodeJS support for OAuth2
|
|
19
|
+
* @class
|
|
20
|
+
* @name AuthorizationNode
|
|
21
21
|
*/
|
|
22
22
|
var Authorization = _webexCore.WebexPlugin.extend((_dec = (0, _common.whileInFlight)('isAuthorizing'), (_obj = {
|
|
23
23
|
derived: {
|
|
24
|
-
/**
|
|
25
|
-
* Alias of {@link AuthorizationNode#isAuthorizing}
|
|
26
|
-
* @instance
|
|
27
|
-
* @memberof AuthorizationNode
|
|
28
|
-
* @type {boolean}
|
|
24
|
+
/**
|
|
25
|
+
* Alias of {@link AuthorizationNode#isAuthorizing}
|
|
26
|
+
* @instance
|
|
27
|
+
* @memberof AuthorizationNode
|
|
28
|
+
* @type {boolean}
|
|
29
29
|
*/
|
|
30
30
|
isAuthenticating: {
|
|
31
31
|
deps: ['isAuthorizing'],
|
|
@@ -35,11 +35,11 @@ var Authorization = _webexCore.WebexPlugin.extend((_dec = (0, _common.whileInFli
|
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
37
|
session: {
|
|
38
|
-
/**
|
|
39
|
-
* Indicates if an Authorization Code exchange is inflight
|
|
40
|
-
* @instance
|
|
41
|
-
* @memberof AuthorizationNode
|
|
42
|
-
* @type {boolean}
|
|
38
|
+
/**
|
|
39
|
+
* Indicates if an Authorization Code exchange is inflight
|
|
40
|
+
* @instance
|
|
41
|
+
* @memberof AuthorizationNode
|
|
42
|
+
* @type {boolean}
|
|
43
43
|
*/
|
|
44
44
|
isAuthorizing: {
|
|
45
45
|
default: false,
|
|
@@ -58,13 +58,13 @@ var Authorization = _webexCore.WebexPlugin.extend((_dec = (0, _common.whileInFli
|
|
|
58
58
|
}
|
|
59
59
|
});
|
|
60
60
|
},
|
|
61
|
-
/**
|
|
62
|
-
* Exchanges an authorization code for an access token
|
|
63
|
-
* @instance
|
|
64
|
-
* @memberof AuthorizationNode
|
|
65
|
-
* @param {Object} options
|
|
66
|
-
* @param {Object} options.code
|
|
67
|
-
* @returns {Promise}
|
|
61
|
+
/**
|
|
62
|
+
* Exchanges an authorization code for an access token
|
|
63
|
+
* @instance
|
|
64
|
+
* @memberof AuthorizationNode
|
|
65
|
+
* @param {Object} options
|
|
66
|
+
* @param {Object} options.code
|
|
67
|
+
* @returns {Promise}
|
|
68
68
|
*/
|
|
69
69
|
requestAuthorizationCodeGrant: function requestAuthorizationCodeGrant() {
|
|
70
70
|
var _this = this;
|
|
@@ -100,20 +100,20 @@ var Authorization = _webexCore.WebexPlugin.extend((_dec = (0, _common.whileInFli
|
|
|
100
100
|
return _promise.default.reject(new ErrorConstructor(res._res || res));
|
|
101
101
|
});
|
|
102
102
|
},
|
|
103
|
-
/**
|
|
104
|
-
* Requests a Webex access token for a user already authenticated into
|
|
105
|
-
* your product.
|
|
106
|
-
*
|
|
107
|
-
* Note: You'll need to supply a jwtRefreshCallback of the form
|
|
108
|
-
* `Promise<jwt> = jwtRefreshCallback(webex)` for automatic token refresh to
|
|
109
|
-
* work.
|
|
110
|
-
*
|
|
111
|
-
* @instance
|
|
112
|
-
* @memberof AuthorizationNode
|
|
113
|
-
* @param {Object} options
|
|
114
|
-
* @param {Object} options.jwt This is a jwt generated by your backend that
|
|
115
|
-
* identifies a user in your system
|
|
116
|
-
* @returns {Promise}
|
|
103
|
+
/**
|
|
104
|
+
* Requests a Webex access token for a user already authenticated into
|
|
105
|
+
* your product.
|
|
106
|
+
*
|
|
107
|
+
* Note: You'll need to supply a jwtRefreshCallback of the form
|
|
108
|
+
* `Promise<jwt> = jwtRefreshCallback(webex)` for automatic token refresh to
|
|
109
|
+
* work.
|
|
110
|
+
*
|
|
111
|
+
* @instance
|
|
112
|
+
* @memberof AuthorizationNode
|
|
113
|
+
* @param {Object} options
|
|
114
|
+
* @param {Object} options.jwt This is a jwt generated by your backend that
|
|
115
|
+
* identifies a user in your system
|
|
116
|
+
* @returns {Promise}
|
|
117
117
|
*/
|
|
118
118
|
requestAccessTokenFromJwt: function requestAccessTokenFromJwt(_ref) {
|
|
119
119
|
var _this2 = this;
|
|
@@ -146,14 +146,14 @@ var Authorization = _webexCore.WebexPlugin.extend((_dec = (0, _common.whileInFli
|
|
|
146
146
|
return _this2.webex.internal.services.initServiceCatalogs();
|
|
147
147
|
});
|
|
148
148
|
},
|
|
149
|
-
/**
|
|
150
|
-
* Creates a jwt user token
|
|
151
|
-
* @param {object} options
|
|
152
|
-
* @param {String} options.issuer Guest Issuer ID
|
|
153
|
-
* @param {String} options.secretId Guest Secret ID
|
|
154
|
-
* @param {String} options.displayName Guest Display Name | optional
|
|
155
|
-
* @param {String} options.expiresIn
|
|
156
|
-
* @returns {Promise<object>}
|
|
149
|
+
/**
|
|
150
|
+
* Creates a jwt user token
|
|
151
|
+
* @param {object} options
|
|
152
|
+
* @param {String} options.issuer Guest Issuer ID
|
|
153
|
+
* @param {String} options.secretId Guest Secret ID
|
|
154
|
+
* @param {String} options.displayName Guest Display Name | optional
|
|
155
|
+
* @param {String} options.expiresIn
|
|
156
|
+
* @returns {Promise<object>}
|
|
157
157
|
*/
|
|
158
158
|
createJwt: function createJwt(_ref3) {
|
|
159
159
|
var issuer = _ref3.issuer,
|
|
@@ -177,7 +177,7 @@ var Authorization = _webexCore.WebexPlugin.extend((_dec = (0, _common.whileInFli
|
|
|
177
177
|
return _promise.default.reject(e);
|
|
178
178
|
}
|
|
179
179
|
},
|
|
180
|
-
version: "2.59.
|
|
180
|
+
version: "2.59.4-next.1"
|
|
181
181
|
}, ((0, _applyDecoratedDescriptor2.default)(_obj, "requestAuthorizationCodeGrant", [_dec, _common.oneFlight], (0, _getOwnPropertyDescriptor.default)(_obj, "requestAuthorizationCodeGrant"), _obj), (0, _applyDecoratedDescriptor2.default)(_obj, "requestAccessTokenFromJwt", [_common.oneFlight], (0, _getOwnPropertyDescriptor.default)(_obj, "requestAccessTokenFromJwt"), _obj)), _obj)));
|
|
182
182
|
var _default = Authorization;
|
|
183
183
|
exports.default = _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_common","require","_webexCore","_jsonwebtoken","_interopRequireDefault","_uuid","_dec","_obj","Authorization","WebexPlugin","extend","whileInFlight","derived","isAuthenticating","deps","fn","isAuthorizing","session","default","type","namespace","logout","options","arguments","length","undefined","webex","request","method","uri","config","logoutUrl","body","token","cisService","service","requestAuthorizationCodeGrant","_this","logger","info","code","_promise","reject","Error","tokenUrl","form","grant_type","redirect_uri","self_contained_token","auth","user","client_id","pass","client_secret","sendImmediately","shouldRefreshAccessToken","then","res","credentials","set","supertoken","catch","statusCode","ErrorConstructor","grantErrors","select","error","_res","requestAccessTokenFromJwt","_ref","_this2","jwt","hydraUri","internal","services","get","slice","process","env","HYDRA_SERVICE_URL","concat","headers","authorization","_ref2","access_token","token_type","expires_in","expiresIn","initServiceCatalogs","createJwt","_ref3","issuer","secretId","displayName","secret","Buffer","from","payload","uuid","jwtToken","sign","resolve","e","version","_applyDecoratedDescriptor2","oneFlight","_getOwnPropertyDescriptor","_default","exports"],"sources":["authorization.js"],"sourcesContent":["/*!\r\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\r\n */\r\n\r\n/* eslint camelcase: [0] */\r\n\r\nimport {oneFlight, whileInFlight} from '@webex/common';\r\nimport {grantErrors, WebexPlugin} from '@webex/webex-core';\r\n\r\nimport jwt from 'jsonwebtoken';\r\nimport uuid from 'uuid';\r\n\r\n/**\r\n * NodeJS support for OAuth2\r\n * @class\r\n * @name AuthorizationNode\r\n */\r\nconst Authorization = WebexPlugin.extend({\r\n derived: {\r\n /**\r\n * Alias of {@link AuthorizationNode#isAuthorizing}\r\n * @instance\r\n * @memberof AuthorizationNode\r\n * @type {boolean}\r\n */\r\n isAuthenticating: {\r\n deps: ['isAuthorizing'],\r\n fn() {\r\n return this.isAuthorizing;\r\n },\r\n },\r\n },\r\n\r\n session: {\r\n /**\r\n * Indicates if an Authorization Code exchange is inflight\r\n * @instance\r\n * @memberof AuthorizationNode\r\n * @type {boolean}\r\n */\r\n isAuthorizing: {\r\n default: false,\r\n type: 'boolean',\r\n },\r\n },\r\n\r\n namespace: 'Credentials',\r\n\r\n logout(options = {}) {\r\n this.webex.request({\r\n method: 'POST',\r\n uri: this.config.logoutUrl,\r\n body: {\r\n token: options.token,\r\n cisService: this.config.service,\r\n },\r\n });\r\n },\r\n\r\n @whileInFlight('isAuthorizing')\r\n @oneFlight\r\n /**\r\n * Exchanges an authorization code for an access token\r\n * @instance\r\n * @memberof AuthorizationNode\r\n * @param {Object} options\r\n * @param {Object} options.code\r\n * @returns {Promise}\r\n */\r\n requestAuthorizationCodeGrant(options = {}) {\r\n this.logger.info('credentials: requesting authorization code grant');\r\n\r\n if (!options.code) {\r\n return Promise.reject(new Error('`options.code` is required'));\r\n }\r\n\r\n return this.webex\r\n .request({\r\n method: 'POST',\r\n uri: this.config.tokenUrl,\r\n form: {\r\n grant_type: 'authorization_code',\r\n redirect_uri: this.config.redirect_uri,\r\n code: options.code,\r\n self_contained_token: true,\r\n },\r\n auth: {\r\n user: this.config.client_id,\r\n pass: this.config.client_secret,\r\n sendImmediately: true,\r\n },\r\n shouldRefreshAccessToken: false,\r\n })\r\n .then((res) => {\r\n this.webex.credentials.set({supertoken: res.body});\r\n })\r\n .catch((res) => {\r\n if (res.statusCode !== 400) {\r\n return Promise.reject(res);\r\n }\r\n\r\n const ErrorConstructor = grantErrors.select(res.body.error);\r\n\r\n return Promise.reject(new ErrorConstructor(res._res || res));\r\n });\r\n },\r\n\r\n @oneFlight\r\n /**\r\n * Requests a Webex access token for a user already authenticated into\r\n * your product.\r\n *\r\n * Note: You'll need to supply a jwtRefreshCallback of the form\r\n * `Promise<jwt> = jwtRefreshCallback(webex)` for automatic token refresh to\r\n * work.\r\n *\r\n * @instance\r\n * @memberof AuthorizationNode\r\n * @param {Object} options\r\n * @param {Object} options.jwt This is a jwt generated by your backend that\r\n * identifies a user in your system\r\n * @returns {Promise}\r\n */\r\n requestAccessTokenFromJwt({jwt}) {\r\n let hydraUri = this.webex.internal.services.get('hydra', true);\r\n\r\n if (hydraUri && hydraUri.slice(-1) !== '/') {\r\n // add a `/` to hydra's uri from the services catalog so that\r\n // it matches the current env service format.\r\n hydraUri += '/';\r\n }\r\n\r\n hydraUri = hydraUri || process.env.HYDRA_SERVICE_URL || 'https://api.ciscospark.com/v1/';\r\n\r\n return this.webex\r\n .request({\r\n method: 'POST',\r\n uri: `${hydraUri}jwt/login`,\r\n headers: {\r\n authorization: jwt,\r\n },\r\n })\r\n .then(({body}) => ({\r\n access_token: body.token,\r\n token_type: 'Bearer',\r\n expires_in: body.expiresIn,\r\n }))\r\n .then((token) => {\r\n this.webex.credentials.set({\r\n supertoken: token,\r\n });\r\n })\r\n .then(() => this.webex.internal.services.initServiceCatalogs());\r\n },\r\n\r\n /**\r\n * Creates a jwt user token\r\n * @param {object} options\r\n * @param {String} options.issuer Guest Issuer ID\r\n * @param {String} options.secretId Guest Secret ID\r\n * @param {String} options.displayName Guest Display Name | optional\r\n * @param {String} options.expiresIn\r\n * @returns {Promise<object>}\r\n */\r\n createJwt({issuer, secretId, displayName, expiresIn}) {\r\n const secret = Buffer.from(secretId, 'base64');\r\n const payload = {\r\n \"sub\": `guest-user-${uuid()}`,\r\n \"iss\": issuer,\r\n \"name\": displayName || `Guest User - ${uuid()}`\r\n };\r\n\r\n try {\r\n const jwtToken = jwt.sign(payload, secret,{ expiresIn });\r\n\r\n return Promise.resolve({jwt: jwtToken});\r\n } catch (e) {\r\n return Promise.reject(e);\r\n }\r\n },\r\n\r\n});\r\n\r\nexport default Authorization;\r\n"],"mappings":";;;;;;;;;;;AAMA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AAEA,IAAAE,aAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,KAAA,GAAAD,sBAAA,CAAAH,OAAA;AAAwB,IAAAK,IAAA,EAAAC,IAAA;AAExB;AACA;AACA;AACA;AACA;AACA,IAAMC,aAAa,GAAGC,sBAAW,CAACC,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AAS,GAAAG,KAAA,CAATH,SAAS;IACjD,IAAMO,MAAM,GAAGC,MAAM,CAACC,IAAI,CAACJ,QAAQ,EAAE,QAAQ,CAAC;IAC9C,IAAMK,OAAO,GAAG;MACd,KAAK,gBAAAjB,MAAA,CAAgB,IAAAkB,aAAI,GAAE,CAAE;MAC7B,KAAK,EAAEP,MAAM;MACb,MAAM,EAAEE,WAAW,oBAAAb,MAAA,CAAoB,IAAAkB,aAAI,GAAE;IAC/C,CAAC;IAED,IAAI;MACF,IAAMC,QAAQ,GAAG5B,qBAAG,CAAC6B,IAAI,CAACH,OAAO,EAAEH,MAAM,EAAC;QAAEP,SAAS,EAATA;MAAU,CAAC,CAAC;MAExD,OAAO9C,QAAA,CAAAvB,OAAA,CAAQmF,OAAO,CAAC;QAAC9B,GAAG,EAAE4B;MAAQ,CAAC,CAAC;IACzC,CAAC,CAAC,OAAOG,CAAC,EAAE;MACV,OAAO7D,QAAA,CAAAvB,OAAA,CAAQwB,MAAM,CAAC4D,CAAC,CAAC;IAC1B;EACF,CAAC;EAAAC,OAAA;AAEH,CAAC,OAAAC,0BAAA,CAAAtF,OAAA,EAAAX,IAAA,oCAAAD,IAAA,EAzHEmG,iBAAS,OAAAC,yBAAA,CAAAxF,OAAA,EAAAX,IAAA,oCAAAA,IAAA,OAAAiG,0BAAA,CAAAtF,OAAA,EAAAX,IAAA,gCA+CTkG,iBAAS,OAAAC,yBAAA,CAAAxF,OAAA,EAAAX,IAAA,gCAAAA,IAAA,IAAAA,IAAA,GA0EV;AAAC,IAAAoG,QAAA,GAEYnG,aAAa;AAAAoG,OAAA,CAAA1F,OAAA,GAAAyF,QAAA"}
|
|
1
|
+
{"version":3,"names":["_common","require","_webexCore","_jsonwebtoken","_interopRequireDefault","_uuid","_dec","_obj","Authorization","WebexPlugin","extend","whileInFlight","derived","isAuthenticating","deps","fn","isAuthorizing","session","default","type","namespace","logout","options","arguments","length","undefined","webex","request","method","uri","config","logoutUrl","body","token","cisService","service","requestAuthorizationCodeGrant","_this","logger","info","code","_promise","reject","Error","tokenUrl","form","grant_type","redirect_uri","self_contained_token","auth","user","client_id","pass","client_secret","sendImmediately","shouldRefreshAccessToken","then","res","credentials","set","supertoken","catch","statusCode","ErrorConstructor","grantErrors","select","error","_res","requestAccessTokenFromJwt","_ref","_this2","jwt","hydraUri","internal","services","get","slice","process","env","HYDRA_SERVICE_URL","concat","headers","authorization","_ref2","access_token","token_type","expires_in","expiresIn","initServiceCatalogs","createJwt","_ref3","issuer","secretId","displayName","secret","Buffer","from","payload","uuid","jwtToken","sign","resolve","e","version","_applyDecoratedDescriptor2","oneFlight","_getOwnPropertyDescriptor","_default","exports"],"sources":["authorization.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\n/* eslint camelcase: [0] */\n\nimport {oneFlight, whileInFlight} from '@webex/common';\nimport {grantErrors, WebexPlugin} from '@webex/webex-core';\n\nimport jwt from 'jsonwebtoken';\nimport uuid from 'uuid';\n\n/**\n * NodeJS support for OAuth2\n * @class\n * @name AuthorizationNode\n */\nconst Authorization = WebexPlugin.extend({\n derived: {\n /**\n * Alias of {@link AuthorizationNode#isAuthorizing}\n * @instance\n * @memberof AuthorizationNode\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 AuthorizationNode\n * @type {boolean}\n */\n isAuthorizing: {\n default: false,\n type: 'boolean',\n },\n },\n\n namespace: 'Credentials',\n\n logout(options = {}) {\n this.webex.request({\n method: 'POST',\n uri: this.config.logoutUrl,\n body: {\n token: options.token,\n cisService: this.config.service,\n },\n });\n },\n\n @whileInFlight('isAuthorizing')\n @oneFlight\n /**\n * Exchanges an authorization code for an access token\n * @instance\n * @memberof AuthorizationNode\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 return this.webex\n .request({\n method: 'POST',\n uri: this.config.tokenUrl,\n form: {\n grant_type: 'authorization_code',\n redirect_uri: this.config.redirect_uri,\n code: options.code,\n self_contained_token: true,\n },\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 @oneFlight\n /**\n * Requests a Webex access token for a user already authenticated into\n * your product.\n *\n * Note: You'll need to supply a jwtRefreshCallback of the form\n * `Promise<jwt> = jwtRefreshCallback(webex)` for automatic token refresh to\n * work.\n *\n * @instance\n * @memberof AuthorizationNode\n * @param {Object} options\n * @param {Object} options.jwt This is a jwt generated by your backend that\n * identifies a user in your system\n * @returns {Promise}\n */\n requestAccessTokenFromJwt({jwt}) {\n let hydraUri = this.webex.internal.services.get('hydra', true);\n\n if (hydraUri && hydraUri.slice(-1) !== '/') {\n // add a `/` to hydra's uri from the services catalog so that\n // it matches the current env service format.\n hydraUri += '/';\n }\n\n hydraUri = hydraUri || process.env.HYDRA_SERVICE_URL || 'https://api.ciscospark.com/v1/';\n\n return this.webex\n .request({\n method: 'POST',\n uri: `${hydraUri}jwt/login`,\n headers: {\n authorization: jwt,\n },\n })\n .then(({body}) => ({\n access_token: body.token,\n token_type: 'Bearer',\n expires_in: body.expiresIn,\n }))\n .then((token) => {\n this.webex.credentials.set({\n supertoken: token,\n });\n })\n .then(() => this.webex.internal.services.initServiceCatalogs());\n },\n\n /**\n * Creates a jwt user token\n * @param {object} options\n * @param {String} options.issuer Guest Issuer ID\n * @param {String} options.secretId Guest Secret ID\n * @param {String} options.displayName Guest Display Name | optional\n * @param {String} options.expiresIn\n * @returns {Promise<object>}\n */\n createJwt({issuer, secretId, displayName, expiresIn}) {\n const secret = Buffer.from(secretId, 'base64');\n const payload = {\n \"sub\": `guest-user-${uuid()}`,\n \"iss\": issuer,\n \"name\": displayName || `Guest User - ${uuid()}`\n };\n\n try {\n const jwtToken = jwt.sign(payload, secret,{ expiresIn });\n\n return Promise.resolve({jwt: jwtToken});\n } catch (e) {\n return Promise.reject(e);\n }\n },\n\n});\n\nexport default Authorization;\n"],"mappings":";;;;;;;;;;;AAMA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AAEA,IAAAE,aAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,KAAA,GAAAD,sBAAA,CAAAH,OAAA;AAAwB,IAAAK,IAAA,EAAAC,IAAA;AAExB;AACA;AACA;AACA;AACA;AACA,IAAMC,aAAa,GAAGC,sBAAW,CAACC,MAAM,EAAAJ,IAAA,GA0CrC,IAAAK,qBAAa,EAAC,eAAe,CAAC,GAAAJ,IAAA,GA1CQ;EACvCK,OAAO,EAAE;IACP;AACJ;AACA;AACA;AACA;AACA;IACIC,gBAAgB,EAAE;MAChBC,IAAI,EAAE,CAAC,eAAe,CAAC;MACvBC,EAAE,WAAAA,GAAA,EAAG;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;EACF,CAAC;EAEDC,SAAS,EAAE,aAAa;EAExBC,MAAM,WAAAA,OAAA,EAAe;IAAA,IAAdC,OAAO,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;IACjB,IAAI,CAACG,KAAK,CAACC,OAAO,CAAC;MACjBC,MAAM,EAAE,MAAM;MACdC,GAAG,E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ACF,CAAC;EAAAC,OAAA;AAEH,CAAC,OAAAC,0BAAA,CAAAtF,OAAA,EAAAX,IAAA,oCAAAD,IAAA,EAzHEmG,iBAAS,OAAAC,yBAAA,CAAAxF,OAAA,EAAAX,IAAA,oCAAAA,IAAA,OAAAiG,0BAAA,CAAAtF,OAAA,EAAAX,IAAA,gCA+CTkG,iBAAS,OAAAC,yBAAA,CAAAxF,OAAA,EAAAX,IAAA,gCAAAA,IAAA,IAAAA,IAAA,GA0EV;AAAC,IAAAoG,QAAA,GAEYnG,aAAa;AAAAoG,OAAA,CAAA1F,OAAA,GAAAyF,QAAA"}
|
package/dist/config.js
CHANGED
|
@@ -5,8 +5,8 @@ _Object$defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
|
-
/*!
|
|
9
|
-
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
8
|
+
/*!
|
|
9
|
+
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
10
10
|
*/
|
|
11
11
|
var _default = {
|
|
12
12
|
credentials: {}
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_default","credentials","exports","default"],"sources":["config.js"],"sourcesContent":["/*!\
|
|
1
|
+
{"version":3,"names":["_default","credentials","exports","default"],"sources":["config.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nexport default {\n credentials: {},\n};\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AAFA,IAAAA,QAAA,GAIe;EACbC,WAAW,EAAE,CAAC;AAChB,CAAC;AAAAC,OAAA,CAAAC,OAAA,GAAAH,QAAA"}
|
package/dist/index.js
CHANGED
|
@@ -21,8 +21,8 @@ require("@webex/internal-plugin-device");
|
|
|
21
21
|
var _webexCore = require("@webex/webex-core");
|
|
22
22
|
var _authorization = _interopRequireDefault(require("./authorization"));
|
|
23
23
|
var _config = _interopRequireDefault(require("./config"));
|
|
24
|
-
/*!
|
|
25
|
-
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
24
|
+
/*!
|
|
25
|
+
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
28
|
var proxies = ['isAuthorizing', 'isAuthenticating'];
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["require","_webexCore","_authorization","_interopRequireDefault","_config","proxies","registerPlugin","Authorization","config"],"sources":["index.js"],"sourcesContent":["/*!\
|
|
1
|
+
{"version":3,"names":["require","_webexCore","_authorization","_interopRequireDefault","_config","proxies","registerPlugin","Authorization","config"],"sources":["index.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport '@webex/internal-plugin-device';\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":";;;;;;;;;;;;;;;;;;;AAIAA,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AAEA,IAAAE,cAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,OAAA,GAAAD,sBAAA,CAAAH,OAAA;AARA;AACA;AACA;;AAQA,IAAMK,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/jest.config.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
const config = require('@webex/jest-config-legacy');
|
|
2
|
-
|
|
3
|
-
module.exports = config;
|
|
1
|
+
const config = require('@webex/jest-config-legacy');
|
|
2
|
+
|
|
3
|
+
module.exports = config;
|
package/package.json
CHANGED
|
@@ -25,19 +25,19 @@
|
|
|
25
25
|
"@webex/eslint-config-legacy": "^0.0.0",
|
|
26
26
|
"@webex/jest-config-legacy": "^0.0.0",
|
|
27
27
|
"@webex/legacy-tools": "^0.0.0",
|
|
28
|
-
"@webex/test-helper-appid": "^2.59.
|
|
29
|
-
"@webex/test-helper-chai": "^2.59.
|
|
30
|
-
"@webex/test-helper-mocha": "^2.59.
|
|
31
|
-
"@webex/test-helper-mock-webex": "^2.59.
|
|
32
|
-
"@webex/test-helper-test-users": "^2.59.
|
|
28
|
+
"@webex/test-helper-appid": "^2.59.4-next.1",
|
|
29
|
+
"@webex/test-helper-chai": "^2.59.4-next.1",
|
|
30
|
+
"@webex/test-helper-mocha": "^2.59.4-next.1",
|
|
31
|
+
"@webex/test-helper-mock-webex": "^2.59.4-next.1",
|
|
32
|
+
"@webex/test-helper-test-users": "^2.59.4-next.1",
|
|
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": "^2.59.
|
|
39
|
-
"@webex/internal-plugin-device": "^2.59.
|
|
40
|
-
"@webex/webex-core": "^2.59.
|
|
38
|
+
"@webex/common": "^2.59.4-next.1",
|
|
39
|
+
"@webex/internal-plugin-device": "^2.59.4-next.1",
|
|
40
|
+
"@webex/webex-core": "^2.59.4-next.1",
|
|
41
41
|
"jsonwebtoken": "^9.0.0",
|
|
42
42
|
"uuid": "^3.3.2"
|
|
43
43
|
},
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"test:style": "eslint ./src/**/*.*",
|
|
52
52
|
"test:unit": "webex-legacy-tools test --unit --runner jest"
|
|
53
53
|
},
|
|
54
|
-
"version": "2.59.
|
|
54
|
+
"version": "2.59.4-next.1"
|
|
55
55
|
}
|
package/process
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
module.exports = {browser: true};
|
|
1
|
+
module.exports = {browser: true};
|
package/src/authorization.js
CHANGED
|
@@ -1,184 +1,184 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
/* eslint camelcase: [0] */
|
|
6
|
-
|
|
7
|
-
import {oneFlight, whileInFlight} from '@webex/common';
|
|
8
|
-
import {grantErrors, WebexPlugin} from '@webex/webex-core';
|
|
9
|
-
|
|
10
|
-
import jwt from 'jsonwebtoken';
|
|
11
|
-
import uuid from 'uuid';
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* NodeJS support for OAuth2
|
|
15
|
-
* @class
|
|
16
|
-
* @name AuthorizationNode
|
|
17
|
-
*/
|
|
18
|
-
const Authorization = WebexPlugin.extend({
|
|
19
|
-
derived: {
|
|
20
|
-
/**
|
|
21
|
-
* Alias of {@link AuthorizationNode#isAuthorizing}
|
|
22
|
-
* @instance
|
|
23
|
-
* @memberof AuthorizationNode
|
|
24
|
-
* @type {boolean}
|
|
25
|
-
*/
|
|
26
|
-
isAuthenticating: {
|
|
27
|
-
deps: ['isAuthorizing'],
|
|
28
|
-
fn() {
|
|
29
|
-
return this.isAuthorizing;
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
|
|
34
|
-
session: {
|
|
35
|
-
/**
|
|
36
|
-
* Indicates if an Authorization Code exchange is inflight
|
|
37
|
-
* @instance
|
|
38
|
-
* @memberof AuthorizationNode
|
|
39
|
-
* @type {boolean}
|
|
40
|
-
*/
|
|
41
|
-
isAuthorizing: {
|
|
42
|
-
default: false,
|
|
43
|
-
type: 'boolean',
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
|
|
47
|
-
namespace: 'Credentials',
|
|
48
|
-
|
|
49
|
-
logout(options = {}) {
|
|
50
|
-
this.webex.request({
|
|
51
|
-
method: 'POST',
|
|
52
|
-
uri: this.config.logoutUrl,
|
|
53
|
-
body: {
|
|
54
|
-
token: options.token,
|
|
55
|
-
cisService: this.config.service,
|
|
56
|
-
},
|
|
57
|
-
});
|
|
58
|
-
},
|
|
59
|
-
|
|
60
|
-
@whileInFlight('isAuthorizing')
|
|
61
|
-
@oneFlight
|
|
62
|
-
/**
|
|
63
|
-
* Exchanges an authorization code for an access token
|
|
64
|
-
* @instance
|
|
65
|
-
* @memberof AuthorizationNode
|
|
66
|
-
* @param {Object} options
|
|
67
|
-
* @param {Object} options.code
|
|
68
|
-
* @returns {Promise}
|
|
69
|
-
*/
|
|
70
|
-
requestAuthorizationCodeGrant(options = {}) {
|
|
71
|
-
this.logger.info('credentials: requesting authorization code grant');
|
|
72
|
-
|
|
73
|
-
if (!options.code) {
|
|
74
|
-
return Promise.reject(new Error('`options.code` is required'));
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return this.webex
|
|
78
|
-
.request({
|
|
79
|
-
method: 'POST',
|
|
80
|
-
uri: this.config.tokenUrl,
|
|
81
|
-
form: {
|
|
82
|
-
grant_type: 'authorization_code',
|
|
83
|
-
redirect_uri: this.config.redirect_uri,
|
|
84
|
-
code: options.code,
|
|
85
|
-
self_contained_token: true,
|
|
86
|
-
},
|
|
87
|
-
auth: {
|
|
88
|
-
user: this.config.client_id,
|
|
89
|
-
pass: this.config.client_secret,
|
|
90
|
-
sendImmediately: true,
|
|
91
|
-
},
|
|
92
|
-
shouldRefreshAccessToken: false,
|
|
93
|
-
})
|
|
94
|
-
.then((res) => {
|
|
95
|
-
this.webex.credentials.set({supertoken: res.body});
|
|
96
|
-
})
|
|
97
|
-
.catch((res) => {
|
|
98
|
-
if (res.statusCode !== 400) {
|
|
99
|
-
return Promise.reject(res);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const ErrorConstructor = grantErrors.select(res.body.error);
|
|
103
|
-
|
|
104
|
-
return Promise.reject(new ErrorConstructor(res._res || res));
|
|
105
|
-
});
|
|
106
|
-
},
|
|
107
|
-
|
|
108
|
-
@oneFlight
|
|
109
|
-
/**
|
|
110
|
-
* Requests a Webex access token for a user already authenticated into
|
|
111
|
-
* your product.
|
|
112
|
-
*
|
|
113
|
-
* Note: You'll need to supply a jwtRefreshCallback of the form
|
|
114
|
-
* `Promise<jwt> = jwtRefreshCallback(webex)` for automatic token refresh to
|
|
115
|
-
* work.
|
|
116
|
-
*
|
|
117
|
-
* @instance
|
|
118
|
-
* @memberof AuthorizationNode
|
|
119
|
-
* @param {Object} options
|
|
120
|
-
* @param {Object} options.jwt This is a jwt generated by your backend that
|
|
121
|
-
* identifies a user in your system
|
|
122
|
-
* @returns {Promise}
|
|
123
|
-
*/
|
|
124
|
-
requestAccessTokenFromJwt({jwt}) {
|
|
125
|
-
let hydraUri = this.webex.internal.services.get('hydra', true);
|
|
126
|
-
|
|
127
|
-
if (hydraUri && hydraUri.slice(-1) !== '/') {
|
|
128
|
-
// add a `/` to hydra's uri from the services catalog so that
|
|
129
|
-
// it matches the current env service format.
|
|
130
|
-
hydraUri += '/';
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
hydraUri = hydraUri || process.env.HYDRA_SERVICE_URL || 'https://api.ciscospark.com/v1/';
|
|
134
|
-
|
|
135
|
-
return this.webex
|
|
136
|
-
.request({
|
|
137
|
-
method: 'POST',
|
|
138
|
-
uri: `${hydraUri}jwt/login`,
|
|
139
|
-
headers: {
|
|
140
|
-
authorization: jwt,
|
|
141
|
-
},
|
|
142
|
-
})
|
|
143
|
-
.then(({body}) => ({
|
|
144
|
-
access_token: body.token,
|
|
145
|
-
token_type: 'Bearer',
|
|
146
|
-
expires_in: body.expiresIn,
|
|
147
|
-
}))
|
|
148
|
-
.then((token) => {
|
|
149
|
-
this.webex.credentials.set({
|
|
150
|
-
supertoken: token,
|
|
151
|
-
});
|
|
152
|
-
})
|
|
153
|
-
.then(() => this.webex.internal.services.initServiceCatalogs());
|
|
154
|
-
},
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Creates a jwt user token
|
|
158
|
-
* @param {object} options
|
|
159
|
-
* @param {String} options.issuer Guest Issuer ID
|
|
160
|
-
* @param {String} options.secretId Guest Secret ID
|
|
161
|
-
* @param {String} options.displayName Guest Display Name | optional
|
|
162
|
-
* @param {String} options.expiresIn
|
|
163
|
-
* @returns {Promise<object>}
|
|
164
|
-
*/
|
|
165
|
-
createJwt({issuer, secretId, displayName, expiresIn}) {
|
|
166
|
-
const secret = Buffer.from(secretId, 'base64');
|
|
167
|
-
const payload = {
|
|
168
|
-
"sub": `guest-user-${uuid()}`,
|
|
169
|
-
"iss": issuer,
|
|
170
|
-
"name": displayName || `Guest User - ${uuid()}`
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
try {
|
|
174
|
-
const jwtToken = jwt.sign(payload, secret,{ expiresIn });
|
|
175
|
-
|
|
176
|
-
return Promise.resolve({jwt: jwtToken});
|
|
177
|
-
} catch (e) {
|
|
178
|
-
return Promise.reject(e);
|
|
179
|
-
}
|
|
180
|
-
},
|
|
181
|
-
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
export default Authorization;
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/* eslint camelcase: [0] */
|
|
6
|
+
|
|
7
|
+
import {oneFlight, whileInFlight} from '@webex/common';
|
|
8
|
+
import {grantErrors, WebexPlugin} from '@webex/webex-core';
|
|
9
|
+
|
|
10
|
+
import jwt from 'jsonwebtoken';
|
|
11
|
+
import uuid from 'uuid';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* NodeJS support for OAuth2
|
|
15
|
+
* @class
|
|
16
|
+
* @name AuthorizationNode
|
|
17
|
+
*/
|
|
18
|
+
const Authorization = WebexPlugin.extend({
|
|
19
|
+
derived: {
|
|
20
|
+
/**
|
|
21
|
+
* Alias of {@link AuthorizationNode#isAuthorizing}
|
|
22
|
+
* @instance
|
|
23
|
+
* @memberof AuthorizationNode
|
|
24
|
+
* @type {boolean}
|
|
25
|
+
*/
|
|
26
|
+
isAuthenticating: {
|
|
27
|
+
deps: ['isAuthorizing'],
|
|
28
|
+
fn() {
|
|
29
|
+
return this.isAuthorizing;
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
session: {
|
|
35
|
+
/**
|
|
36
|
+
* Indicates if an Authorization Code exchange is inflight
|
|
37
|
+
* @instance
|
|
38
|
+
* @memberof AuthorizationNode
|
|
39
|
+
* @type {boolean}
|
|
40
|
+
*/
|
|
41
|
+
isAuthorizing: {
|
|
42
|
+
default: false,
|
|
43
|
+
type: 'boolean',
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
namespace: 'Credentials',
|
|
48
|
+
|
|
49
|
+
logout(options = {}) {
|
|
50
|
+
this.webex.request({
|
|
51
|
+
method: 'POST',
|
|
52
|
+
uri: this.config.logoutUrl,
|
|
53
|
+
body: {
|
|
54
|
+
token: options.token,
|
|
55
|
+
cisService: this.config.service,
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
@whileInFlight('isAuthorizing')
|
|
61
|
+
@oneFlight
|
|
62
|
+
/**
|
|
63
|
+
* Exchanges an authorization code for an access token
|
|
64
|
+
* @instance
|
|
65
|
+
* @memberof AuthorizationNode
|
|
66
|
+
* @param {Object} options
|
|
67
|
+
* @param {Object} options.code
|
|
68
|
+
* @returns {Promise}
|
|
69
|
+
*/
|
|
70
|
+
requestAuthorizationCodeGrant(options = {}) {
|
|
71
|
+
this.logger.info('credentials: requesting authorization code grant');
|
|
72
|
+
|
|
73
|
+
if (!options.code) {
|
|
74
|
+
return Promise.reject(new Error('`options.code` is required'));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return this.webex
|
|
78
|
+
.request({
|
|
79
|
+
method: 'POST',
|
|
80
|
+
uri: this.config.tokenUrl,
|
|
81
|
+
form: {
|
|
82
|
+
grant_type: 'authorization_code',
|
|
83
|
+
redirect_uri: this.config.redirect_uri,
|
|
84
|
+
code: options.code,
|
|
85
|
+
self_contained_token: true,
|
|
86
|
+
},
|
|
87
|
+
auth: {
|
|
88
|
+
user: this.config.client_id,
|
|
89
|
+
pass: this.config.client_secret,
|
|
90
|
+
sendImmediately: true,
|
|
91
|
+
},
|
|
92
|
+
shouldRefreshAccessToken: false,
|
|
93
|
+
})
|
|
94
|
+
.then((res) => {
|
|
95
|
+
this.webex.credentials.set({supertoken: res.body});
|
|
96
|
+
})
|
|
97
|
+
.catch((res) => {
|
|
98
|
+
if (res.statusCode !== 400) {
|
|
99
|
+
return Promise.reject(res);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const ErrorConstructor = grantErrors.select(res.body.error);
|
|
103
|
+
|
|
104
|
+
return Promise.reject(new ErrorConstructor(res._res || res));
|
|
105
|
+
});
|
|
106
|
+
},
|
|
107
|
+
|
|
108
|
+
@oneFlight
|
|
109
|
+
/**
|
|
110
|
+
* Requests a Webex access token for a user already authenticated into
|
|
111
|
+
* your product.
|
|
112
|
+
*
|
|
113
|
+
* Note: You'll need to supply a jwtRefreshCallback of the form
|
|
114
|
+
* `Promise<jwt> = jwtRefreshCallback(webex)` for automatic token refresh to
|
|
115
|
+
* work.
|
|
116
|
+
*
|
|
117
|
+
* @instance
|
|
118
|
+
* @memberof AuthorizationNode
|
|
119
|
+
* @param {Object} options
|
|
120
|
+
* @param {Object} options.jwt This is a jwt generated by your backend that
|
|
121
|
+
* identifies a user in your system
|
|
122
|
+
* @returns {Promise}
|
|
123
|
+
*/
|
|
124
|
+
requestAccessTokenFromJwt({jwt}) {
|
|
125
|
+
let hydraUri = this.webex.internal.services.get('hydra', true);
|
|
126
|
+
|
|
127
|
+
if (hydraUri && hydraUri.slice(-1) !== '/') {
|
|
128
|
+
// add a `/` to hydra's uri from the services catalog so that
|
|
129
|
+
// it matches the current env service format.
|
|
130
|
+
hydraUri += '/';
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
hydraUri = hydraUri || process.env.HYDRA_SERVICE_URL || 'https://api.ciscospark.com/v1/';
|
|
134
|
+
|
|
135
|
+
return this.webex
|
|
136
|
+
.request({
|
|
137
|
+
method: 'POST',
|
|
138
|
+
uri: `${hydraUri}jwt/login`,
|
|
139
|
+
headers: {
|
|
140
|
+
authorization: jwt,
|
|
141
|
+
},
|
|
142
|
+
})
|
|
143
|
+
.then(({body}) => ({
|
|
144
|
+
access_token: body.token,
|
|
145
|
+
token_type: 'Bearer',
|
|
146
|
+
expires_in: body.expiresIn,
|
|
147
|
+
}))
|
|
148
|
+
.then((token) => {
|
|
149
|
+
this.webex.credentials.set({
|
|
150
|
+
supertoken: token,
|
|
151
|
+
});
|
|
152
|
+
})
|
|
153
|
+
.then(() => this.webex.internal.services.initServiceCatalogs());
|
|
154
|
+
},
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Creates a jwt user token
|
|
158
|
+
* @param {object} options
|
|
159
|
+
* @param {String} options.issuer Guest Issuer ID
|
|
160
|
+
* @param {String} options.secretId Guest Secret ID
|
|
161
|
+
* @param {String} options.displayName Guest Display Name | optional
|
|
162
|
+
* @param {String} options.expiresIn
|
|
163
|
+
* @returns {Promise<object>}
|
|
164
|
+
*/
|
|
165
|
+
createJwt({issuer, secretId, displayName, expiresIn}) {
|
|
166
|
+
const secret = Buffer.from(secretId, 'base64');
|
|
167
|
+
const payload = {
|
|
168
|
+
"sub": `guest-user-${uuid()}`,
|
|
169
|
+
"iss": issuer,
|
|
170
|
+
"name": displayName || `Guest User - ${uuid()}`
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
try {
|
|
174
|
+
const jwtToken = jwt.sign(payload, secret,{ expiresIn });
|
|
175
|
+
|
|
176
|
+
return Promise.resolve({jwt: jwtToken});
|
|
177
|
+
} catch (e) {
|
|
178
|
+
return Promise.reject(e);
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
export default Authorization;
|
package/src/config.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export default {
|
|
6
|
-
credentials: {},
|
|
7
|
-
};
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
credentials: {},
|
|
7
|
+
};
|
package/src/index.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import '@webex/internal-plugin-device';
|
|
6
|
-
import {registerPlugin} from '@webex/webex-core';
|
|
7
|
-
|
|
8
|
-
import Authorization from './authorization';
|
|
9
|
-
import config from './config';
|
|
10
|
-
|
|
11
|
-
const proxies = ['isAuthorizing', 'isAuthenticating'];
|
|
12
|
-
|
|
13
|
-
registerPlugin('authorization', Authorization, {
|
|
14
|
-
config,
|
|
15
|
-
proxies,
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
export {default} from './authorization';
|
|
19
|
-
export {default as config} from './config';
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import '@webex/internal-plugin-device';
|
|
6
|
+
import {registerPlugin} from '@webex/webex-core';
|
|
7
|
+
|
|
8
|
+
import Authorization from './authorization';
|
|
9
|
+
import config from './config';
|
|
10
|
+
|
|
11
|
+
const proxies = ['isAuthorizing', 'isAuthenticating'];
|
|
12
|
+
|
|
13
|
+
registerPlugin('authorization', Authorization, {
|
|
14
|
+
config,
|
|
15
|
+
proxies,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
export {default} from './authorization';
|
|
19
|
+
export {default as config} from './config';
|
|
@@ -1,166 +1,166 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import '@webex/plugin-authorization-node';
|
|
6
|
-
import {nodeOnly} from '@webex/test-helper-mocha';
|
|
7
|
-
import {assert} from '@webex/test-helper-chai';
|
|
8
|
-
import testUsers from '@webex/test-helper-test-users';
|
|
9
|
-
import {createUser} from '@webex/test-helper-appid';
|
|
10
|
-
import WebexCore, {filterScope} from '@webex/webex-core';
|
|
11
|
-
import uuid from 'uuid';
|
|
12
|
-
import sinon from 'sinon';
|
|
13
|
-
|
|
14
|
-
const apiScope = filterScope('spark:kms', process.env.WEBEX_SCOPE);
|
|
15
|
-
|
|
16
|
-
nodeOnly(describe)('plugin-authorization-node', () => {
|
|
17
|
-
describe('Authorization', () => {
|
|
18
|
-
describe('#logout()', () => {
|
|
19
|
-
let webex, spock;
|
|
20
|
-
|
|
21
|
-
beforeEach('create authorized webex user', () =>
|
|
22
|
-
testUsers.create({count: 1}).then(([u]) => {
|
|
23
|
-
spock = u;
|
|
24
|
-
webex = new WebexCore({credentials: spock.token});
|
|
25
|
-
})
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
it("invalidates all of the use's tokens", () => {
|
|
29
|
-
sinon.spy(webex.authorization, 'logout');
|
|
30
|
-
sinon.spy(webex, 'logout');
|
|
31
|
-
|
|
32
|
-
return webex.logout().then(() => {
|
|
33
|
-
assert.called(webex.logout);
|
|
34
|
-
assert.called(webex.authorization.logout);
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
describe('#requestAccessTokenFromJwt', () => {
|
|
40
|
-
it('exchanges a JWT for an appid access token', () => {
|
|
41
|
-
const userId = uuid.v4();
|
|
42
|
-
const displayName = `test-${userId}`;
|
|
43
|
-
|
|
44
|
-
return createUser({displayName, userId}).then(({jwt}) => {
|
|
45
|
-
const webex = new WebexCore();
|
|
46
|
-
|
|
47
|
-
return webex.authorization
|
|
48
|
-
.requestAccessTokenFromJwt({jwt})
|
|
49
|
-
.then(() => assert.isTrue(webex.canAuthorize));
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('should call services#initServiceCatalogs()', () => {
|
|
54
|
-
const webex = new WebexCore();
|
|
55
|
-
const userId = uuid.v4();
|
|
56
|
-
const displayName = `test-${userId}`;
|
|
57
|
-
|
|
58
|
-
webex.internal.services.initServiceCatalogs = sinon.spy();
|
|
59
|
-
|
|
60
|
-
return createUser({displayName, userId})
|
|
61
|
-
.then(({jwt}) => webex.authorization.requestAccessTokenFromJwt({jwt}))
|
|
62
|
-
.then(() => assert.called(webex.internal.services.initServiceCatalogs));
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
describe.skip("'#refresh", () => {
|
|
67
|
-
describe('when used with an appid access token', () => {
|
|
68
|
-
it('refreshes the access token', () => {
|
|
69
|
-
const userId = uuid.v4();
|
|
70
|
-
const displayName = `test-${userId}`;
|
|
71
|
-
|
|
72
|
-
return createUser({displayName, userId}).then(({jwt}) => {
|
|
73
|
-
const webex = new WebexCore({
|
|
74
|
-
config: {
|
|
75
|
-
credentials: {
|
|
76
|
-
jwtRefreshCallback() {
|
|
77
|
-
return createUser({displayName, userId}).then(({jwt}) => jwt);
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
});
|
|
82
|
-
let token;
|
|
83
|
-
|
|
84
|
-
return webex.authorization
|
|
85
|
-
.requestAccessTokenFromJwt({jwt})
|
|
86
|
-
.then(() => {
|
|
87
|
-
token = webex.credentials.supertoken.access_token;
|
|
88
|
-
assert.isTrue(webex.canAuthorize);
|
|
89
|
-
})
|
|
90
|
-
.then(() => webex.refresh())
|
|
91
|
-
.then(() => {
|
|
92
|
-
assert.isTrue(webex.canAuthorize);
|
|
93
|
-
assert.notEqual(webex.credentials.supertoken.access_token, token);
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
describe('#requestAuthorizationCodeGrant()', () => {
|
|
101
|
-
describe('when the user has the webex entitlement', () => {
|
|
102
|
-
let code, webex;
|
|
103
|
-
|
|
104
|
-
beforeEach('create auth code only test user', () =>
|
|
105
|
-
testUsers.create({config: {authCodeOnly: true}}).then(([u]) => {
|
|
106
|
-
webex = new WebexCore();
|
|
107
|
-
code = u.token.auth_code;
|
|
108
|
-
})
|
|
109
|
-
);
|
|
110
|
-
|
|
111
|
-
it('exchanges an authorization code for an access token', () =>
|
|
112
|
-
webex.authorization.requestAuthorizationCodeGrant({code}).then(() => {
|
|
113
|
-
assert.isDefined(webex.credentials.supertoken);
|
|
114
|
-
|
|
115
|
-
return Promise.all([
|
|
116
|
-
webex.credentials.getUserToken(apiScope),
|
|
117
|
-
webex.credentials.getUserToken('spark:kms'),
|
|
118
|
-
]);
|
|
119
|
-
}));
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
describe('when the user does not have the webex entitlement', () => {
|
|
123
|
-
let code, webex;
|
|
124
|
-
|
|
125
|
-
beforeEach('create non-webex-entitled test user', () =>
|
|
126
|
-
testUsers
|
|
127
|
-
.create({
|
|
128
|
-
config: {
|
|
129
|
-
// We omit the webex entitlment so that CI gives us a token lacking
|
|
130
|
-
// spark:* scopes
|
|
131
|
-
entitlements: [
|
|
132
|
-
'squaredCallInitiation',
|
|
133
|
-
'squaredRoomModeration',
|
|
134
|
-
'squaredInviter',
|
|
135
|
-
'webExSquared',
|
|
136
|
-
],
|
|
137
|
-
authCodeOnly: true,
|
|
138
|
-
},
|
|
139
|
-
})
|
|
140
|
-
.then(([u]) => {
|
|
141
|
-
webex = new WebexCore();
|
|
142
|
-
code = u.token.auth_code;
|
|
143
|
-
})
|
|
144
|
-
);
|
|
145
|
-
|
|
146
|
-
it('exchanges an authorization code for an access token', () =>
|
|
147
|
-
webex.authorization.requestAuthorizationCodeGrant({code}).then(() => {
|
|
148
|
-
assert.isDefined(webex.credentials.supertoken);
|
|
149
|
-
|
|
150
|
-
return Promise.all([
|
|
151
|
-
webex.credentials
|
|
152
|
-
.getUserToken(apiScope)
|
|
153
|
-
.then((token) =>
|
|
154
|
-
assert.equal(token.access_token, webex.credentials.supertoken.access_token)
|
|
155
|
-
),
|
|
156
|
-
webex.credentials
|
|
157
|
-
.getUserToken('spark:kms')
|
|
158
|
-
.then((token) =>
|
|
159
|
-
assert.equal(token.access_token, webex.credentials.supertoken.access_token)
|
|
160
|
-
),
|
|
161
|
-
]);
|
|
162
|
-
}));
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
});
|
|
166
|
-
});
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import '@webex/plugin-authorization-node';
|
|
6
|
+
import {nodeOnly} from '@webex/test-helper-mocha';
|
|
7
|
+
import {assert} from '@webex/test-helper-chai';
|
|
8
|
+
import testUsers from '@webex/test-helper-test-users';
|
|
9
|
+
import {createUser} from '@webex/test-helper-appid';
|
|
10
|
+
import WebexCore, {filterScope} from '@webex/webex-core';
|
|
11
|
+
import uuid from 'uuid';
|
|
12
|
+
import sinon from 'sinon';
|
|
13
|
+
|
|
14
|
+
const apiScope = filterScope('spark:kms', process.env.WEBEX_SCOPE);
|
|
15
|
+
|
|
16
|
+
nodeOnly(describe)('plugin-authorization-node', () => {
|
|
17
|
+
describe('Authorization', () => {
|
|
18
|
+
describe('#logout()', () => {
|
|
19
|
+
let webex, spock;
|
|
20
|
+
|
|
21
|
+
beforeEach('create authorized webex user', () =>
|
|
22
|
+
testUsers.create({count: 1}).then(([u]) => {
|
|
23
|
+
spock = u;
|
|
24
|
+
webex = new WebexCore({credentials: spock.token});
|
|
25
|
+
})
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
it("invalidates all of the use's tokens", () => {
|
|
29
|
+
sinon.spy(webex.authorization, 'logout');
|
|
30
|
+
sinon.spy(webex, 'logout');
|
|
31
|
+
|
|
32
|
+
return webex.logout().then(() => {
|
|
33
|
+
assert.called(webex.logout);
|
|
34
|
+
assert.called(webex.authorization.logout);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe('#requestAccessTokenFromJwt', () => {
|
|
40
|
+
it('exchanges a JWT for an appid access token', () => {
|
|
41
|
+
const userId = uuid.v4();
|
|
42
|
+
const displayName = `test-${userId}`;
|
|
43
|
+
|
|
44
|
+
return createUser({displayName, userId}).then(({jwt}) => {
|
|
45
|
+
const webex = new WebexCore();
|
|
46
|
+
|
|
47
|
+
return webex.authorization
|
|
48
|
+
.requestAccessTokenFromJwt({jwt})
|
|
49
|
+
.then(() => assert.isTrue(webex.canAuthorize));
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('should call services#initServiceCatalogs()', () => {
|
|
54
|
+
const webex = new WebexCore();
|
|
55
|
+
const userId = uuid.v4();
|
|
56
|
+
const displayName = `test-${userId}`;
|
|
57
|
+
|
|
58
|
+
webex.internal.services.initServiceCatalogs = sinon.spy();
|
|
59
|
+
|
|
60
|
+
return createUser({displayName, userId})
|
|
61
|
+
.then(({jwt}) => webex.authorization.requestAccessTokenFromJwt({jwt}))
|
|
62
|
+
.then(() => assert.called(webex.internal.services.initServiceCatalogs));
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
describe.skip("'#refresh", () => {
|
|
67
|
+
describe('when used with an appid access token', () => {
|
|
68
|
+
it('refreshes the access token', () => {
|
|
69
|
+
const userId = uuid.v4();
|
|
70
|
+
const displayName = `test-${userId}`;
|
|
71
|
+
|
|
72
|
+
return createUser({displayName, userId}).then(({jwt}) => {
|
|
73
|
+
const webex = new WebexCore({
|
|
74
|
+
config: {
|
|
75
|
+
credentials: {
|
|
76
|
+
jwtRefreshCallback() {
|
|
77
|
+
return createUser({displayName, userId}).then(({jwt}) => jwt);
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
let token;
|
|
83
|
+
|
|
84
|
+
return webex.authorization
|
|
85
|
+
.requestAccessTokenFromJwt({jwt})
|
|
86
|
+
.then(() => {
|
|
87
|
+
token = webex.credentials.supertoken.access_token;
|
|
88
|
+
assert.isTrue(webex.canAuthorize);
|
|
89
|
+
})
|
|
90
|
+
.then(() => webex.refresh())
|
|
91
|
+
.then(() => {
|
|
92
|
+
assert.isTrue(webex.canAuthorize);
|
|
93
|
+
assert.notEqual(webex.credentials.supertoken.access_token, token);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
describe('#requestAuthorizationCodeGrant()', () => {
|
|
101
|
+
describe('when the user has the webex entitlement', () => {
|
|
102
|
+
let code, webex;
|
|
103
|
+
|
|
104
|
+
beforeEach('create auth code only test user', () =>
|
|
105
|
+
testUsers.create({config: {authCodeOnly: true}}).then(([u]) => {
|
|
106
|
+
webex = new WebexCore();
|
|
107
|
+
code = u.token.auth_code;
|
|
108
|
+
})
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
it('exchanges an authorization code for an access token', () =>
|
|
112
|
+
webex.authorization.requestAuthorizationCodeGrant({code}).then(() => {
|
|
113
|
+
assert.isDefined(webex.credentials.supertoken);
|
|
114
|
+
|
|
115
|
+
return Promise.all([
|
|
116
|
+
webex.credentials.getUserToken(apiScope),
|
|
117
|
+
webex.credentials.getUserToken('spark:kms'),
|
|
118
|
+
]);
|
|
119
|
+
}));
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
describe('when the user does not have the webex entitlement', () => {
|
|
123
|
+
let code, webex;
|
|
124
|
+
|
|
125
|
+
beforeEach('create non-webex-entitled test user', () =>
|
|
126
|
+
testUsers
|
|
127
|
+
.create({
|
|
128
|
+
config: {
|
|
129
|
+
// We omit the webex entitlment so that CI gives us a token lacking
|
|
130
|
+
// spark:* scopes
|
|
131
|
+
entitlements: [
|
|
132
|
+
'squaredCallInitiation',
|
|
133
|
+
'squaredRoomModeration',
|
|
134
|
+
'squaredInviter',
|
|
135
|
+
'webExSquared',
|
|
136
|
+
],
|
|
137
|
+
authCodeOnly: true,
|
|
138
|
+
},
|
|
139
|
+
})
|
|
140
|
+
.then(([u]) => {
|
|
141
|
+
webex = new WebexCore();
|
|
142
|
+
code = u.token.auth_code;
|
|
143
|
+
})
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
it('exchanges an authorization code for an access token', () =>
|
|
147
|
+
webex.authorization.requestAuthorizationCodeGrant({code}).then(() => {
|
|
148
|
+
assert.isDefined(webex.credentials.supertoken);
|
|
149
|
+
|
|
150
|
+
return Promise.all([
|
|
151
|
+
webex.credentials
|
|
152
|
+
.getUserToken(apiScope)
|
|
153
|
+
.then((token) =>
|
|
154
|
+
assert.equal(token.access_token, webex.credentials.supertoken.access_token)
|
|
155
|
+
),
|
|
156
|
+
webex.credentials
|
|
157
|
+
.getUserToken('spark:kms')
|
|
158
|
+
.then((token) =>
|
|
159
|
+
assert.equal(token.access_token, webex.credentials.supertoken.access_token)
|
|
160
|
+
),
|
|
161
|
+
]);
|
|
162
|
+
}));
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
});
|
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
/* eslint camelcase: [0] */
|
|
6
|
-
|
|
7
|
-
import {assert} from '@webex/test-helper-chai';
|
|
8
|
-
import {browserOnly, nodeOnly} from '@webex/test-helper-mocha';
|
|
9
|
-
import MockWebex from '@webex/test-helper-mock-webex';
|
|
10
|
-
import Authorization from '@webex/plugin-authorization-node';
|
|
11
|
-
import {Credentials} from '@webex/webex-core';
|
|
12
|
-
|
|
13
|
-
browserOnly(describe)('hack', () => {
|
|
14
|
-
it('prevents the suite from crashing', () => assert(true));
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
nodeOnly(describe)('plugin-authorization-node', () => {
|
|
18
|
-
describe('Authorization', () => {
|
|
19
|
-
let webex;
|
|
20
|
-
|
|
21
|
-
beforeEach(() => {
|
|
22
|
-
webex = new MockWebex({
|
|
23
|
-
children: {
|
|
24
|
-
authorization: Authorization,
|
|
25
|
-
credentials: Credentials,
|
|
26
|
-
},
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
webex.request.returns(
|
|
30
|
-
Promise.resolve({
|
|
31
|
-
statusCode: 200,
|
|
32
|
-
body: {
|
|
33
|
-
access_token: 'AT3',
|
|
34
|
-
token_type: 'Fake',
|
|
35
|
-
},
|
|
36
|
-
})
|
|
37
|
-
);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
describe('#requestAuthorizationCodeGrant', () => {
|
|
41
|
-
it('requires a `code`', () =>
|
|
42
|
-
assert.isRejected(
|
|
43
|
-
webex.authorization.requestAuthorizationCodeGrant(),
|
|
44
|
-
/`options.code` is required/
|
|
45
|
-
));
|
|
46
|
-
|
|
47
|
-
it('exchanges an authorization code for an access token', () =>
|
|
48
|
-
webex.authorization
|
|
49
|
-
.requestAuthorizationCodeGrant({code: 1})
|
|
50
|
-
.then(() => assert.equal(webex.credentials.supertoken.access_token, 'AT3')));
|
|
51
|
-
|
|
52
|
-
it('sets #isAuthenticating', () => {
|
|
53
|
-
const promise = webex.authorization.requestAuthorizationCodeGrant({code: 5});
|
|
54
|
-
|
|
55
|
-
assert.isTrue(webex.authorization.isAuthenticating);
|
|
56
|
-
|
|
57
|
-
return promise.then(() => assert.isFalse(webex.authorization.isAuthenticating));
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('sets #isAuthorizing', () => {
|
|
61
|
-
const promise = webex.authorization.requestAuthorizationCodeGrant({code: 5});
|
|
62
|
-
|
|
63
|
-
assert.isTrue(webex.authorization.isAuthorizing);
|
|
64
|
-
|
|
65
|
-
return promise.then(() => assert.isFalse(webex.authorization.isAuthorizing));
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
});
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/* eslint camelcase: [0] */
|
|
6
|
+
|
|
7
|
+
import {assert} from '@webex/test-helper-chai';
|
|
8
|
+
import {browserOnly, nodeOnly} from '@webex/test-helper-mocha';
|
|
9
|
+
import MockWebex from '@webex/test-helper-mock-webex';
|
|
10
|
+
import Authorization from '@webex/plugin-authorization-node';
|
|
11
|
+
import {Credentials} from '@webex/webex-core';
|
|
12
|
+
|
|
13
|
+
browserOnly(describe)('hack', () => {
|
|
14
|
+
it('prevents the suite from crashing', () => assert(true));
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
nodeOnly(describe)('plugin-authorization-node', () => {
|
|
18
|
+
describe('Authorization', () => {
|
|
19
|
+
let webex;
|
|
20
|
+
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
webex = new MockWebex({
|
|
23
|
+
children: {
|
|
24
|
+
authorization: Authorization,
|
|
25
|
+
credentials: Credentials,
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
webex.request.returns(
|
|
30
|
+
Promise.resolve({
|
|
31
|
+
statusCode: 200,
|
|
32
|
+
body: {
|
|
33
|
+
access_token: 'AT3',
|
|
34
|
+
token_type: 'Fake',
|
|
35
|
+
},
|
|
36
|
+
})
|
|
37
|
+
);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe('#requestAuthorizationCodeGrant', () => {
|
|
41
|
+
it('requires a `code`', () =>
|
|
42
|
+
assert.isRejected(
|
|
43
|
+
webex.authorization.requestAuthorizationCodeGrant(),
|
|
44
|
+
/`options.code` is required/
|
|
45
|
+
));
|
|
46
|
+
|
|
47
|
+
it('exchanges an authorization code for an access token', () =>
|
|
48
|
+
webex.authorization
|
|
49
|
+
.requestAuthorizationCodeGrant({code: 1})
|
|
50
|
+
.then(() => assert.equal(webex.credentials.supertoken.access_token, 'AT3')));
|
|
51
|
+
|
|
52
|
+
it('sets #isAuthenticating', () => {
|
|
53
|
+
const promise = webex.authorization.requestAuthorizationCodeGrant({code: 5});
|
|
54
|
+
|
|
55
|
+
assert.isTrue(webex.authorization.isAuthenticating);
|
|
56
|
+
|
|
57
|
+
return promise.then(() => assert.isFalse(webex.authorization.isAuthenticating));
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('sets #isAuthorizing', () => {
|
|
61
|
+
const promise = webex.authorization.requestAuthorizationCodeGrant({code: 5});
|
|
62
|
+
|
|
63
|
+
assert.isTrue(webex.authorization.isAuthorizing);
|
|
64
|
+
|
|
65
|
+
return promise.then(() => assert.isFalse(webex.authorization.isAuthorizing));
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
});
|