@webex/plugin-authorization-node 3.0.0-beta.9 → 3.0.0-bnr.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/authorization.js +1 -22
- package/dist/authorization.js.map +1 -1
- package/dist/config.js +0 -3
- package/dist/config.js.map +1 -1
- package/dist/index.js +1 -9
- package/dist/index.js.map +1 -1
- package/dist/plugin-authorization-node.d.ts +13 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/dist/types/authorization.d.ts +7 -0
- package/dist/types/config.d.ts +4 -0
- package/dist/types/index.d.ts +2 -0
- package/package.json +10 -10
- package/src/authorization.js +35 -35
- package/src/config.js +1 -1
- package/src/index.js +2 -5
- package/test/integration/spec/authorization.js +79 -70
- package/test/unit/spec/authorization.js +22 -16
package/dist/authorization.js
CHANGED
|
@@ -1,27 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
|
|
4
|
-
|
|
5
4
|
var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
|
|
6
|
-
|
|
7
5
|
_Object$defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
|
-
|
|
11
8
|
exports.default = void 0;
|
|
12
|
-
|
|
13
9
|
var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
|
|
14
|
-
|
|
15
10
|
var _getOwnPropertyDescriptor = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptor"));
|
|
16
|
-
|
|
17
11
|
var _applyDecoratedDescriptor2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/applyDecoratedDescriptor"));
|
|
18
|
-
|
|
19
12
|
var _common = require("@webex/common");
|
|
20
|
-
|
|
21
13
|
var _webexCore = require("@webex/webex-core");
|
|
22
|
-
|
|
23
14
|
var _dec, _obj;
|
|
24
|
-
|
|
25
15
|
/**
|
|
26
16
|
* NodeJS support for OAuth2
|
|
27
17
|
* @class
|
|
@@ -66,7 +56,6 @@ var Authorization = _webexCore.WebexPlugin.extend((_dec = (0, _common.whileInFli
|
|
|
66
56
|
}
|
|
67
57
|
});
|
|
68
58
|
},
|
|
69
|
-
|
|
70
59
|
/**
|
|
71
60
|
* Exchanges an authorization code for an access token
|
|
72
61
|
* @instance
|
|
@@ -77,14 +66,11 @@ var Authorization = _webexCore.WebexPlugin.extend((_dec = (0, _common.whileInFli
|
|
|
77
66
|
*/
|
|
78
67
|
requestAuthorizationCodeGrant: function requestAuthorizationCodeGrant() {
|
|
79
68
|
var _this = this;
|
|
80
|
-
|
|
81
69
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
82
70
|
this.logger.info('credentials: requesting authorization code grant');
|
|
83
|
-
|
|
84
71
|
if (!options.code) {
|
|
85
72
|
return _promise.default.reject(new Error('`options.code` is required'));
|
|
86
73
|
}
|
|
87
|
-
|
|
88
74
|
return this.webex.request({
|
|
89
75
|
method: 'POST',
|
|
90
76
|
uri: this.config.tokenUrl,
|
|
@@ -108,13 +94,10 @@ var Authorization = _webexCore.WebexPlugin.extend((_dec = (0, _common.whileInFli
|
|
|
108
94
|
if (res.statusCode !== 400) {
|
|
109
95
|
return _promise.default.reject(res);
|
|
110
96
|
}
|
|
111
|
-
|
|
112
97
|
var ErrorConstructor = _webexCore.grantErrors.select(res.body.error);
|
|
113
|
-
|
|
114
98
|
return _promise.default.reject(new ErrorConstructor(res._res || res));
|
|
115
99
|
});
|
|
116
100
|
},
|
|
117
|
-
|
|
118
101
|
/**
|
|
119
102
|
* Requests a Webex access token for a user already authenticated into
|
|
120
103
|
* your product.
|
|
@@ -132,16 +115,13 @@ var Authorization = _webexCore.WebexPlugin.extend((_dec = (0, _common.whileInFli
|
|
|
132
115
|
*/
|
|
133
116
|
requestAccessTokenFromJwt: function requestAccessTokenFromJwt(_ref) {
|
|
134
117
|
var _this2 = this;
|
|
135
|
-
|
|
136
118
|
var jwt = _ref.jwt;
|
|
137
119
|
var hydraUri = this.webex.internal.services.get('hydra', true);
|
|
138
|
-
|
|
139
120
|
if (hydraUri && hydraUri.slice(-1) !== '/') {
|
|
140
121
|
// add a `/` to hydra's uri from the services catalog so that
|
|
141
122
|
// it matches the current env service format.
|
|
142
123
|
hydraUri += '/';
|
|
143
124
|
}
|
|
144
|
-
|
|
145
125
|
hydraUri = hydraUri || process.env.HYDRA_SERVICE_URL || 'https://api.ciscospark.com/v1/';
|
|
146
126
|
return this.webex.request({
|
|
147
127
|
method: 'POST',
|
|
@@ -164,9 +144,8 @@ var Authorization = _webexCore.WebexPlugin.extend((_dec = (0, _common.whileInFli
|
|
|
164
144
|
return _this2.webex.internal.services.initServiceCatalogs();
|
|
165
145
|
});
|
|
166
146
|
},
|
|
167
|
-
version: "3.0.0-
|
|
147
|
+
version: "3.0.0-bnr.2"
|
|
168
148
|
}, ((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)));
|
|
169
|
-
|
|
170
149
|
var _default = Authorization;
|
|
171
150
|
exports.default = _default;
|
|
172
151
|
//# sourceMappingURL=authorization.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Authorization","WebexPlugin","extend","whileInFlight","derived","isAuthenticating","deps","fn","isAuthorizing","session","default","type","namespace","logout","options","webex","request","method","uri","config","logoutUrl","body","token","cisService","service","requestAuthorizationCodeGrant","logger","info","code","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","jwt","hydraUri","internal","services","get","slice","process","env","HYDRA_SERVICE_URL","headers","authorization","access_token","token_type","expires_in","expiresIn","initServiceCatalogs","oneFlight"],"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\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 }
|
|
1
|
+
{"version":3,"names":["Authorization","WebexPlugin","extend","whileInFlight","derived","isAuthenticating","deps","fn","isAuthorizing","session","default","type","namespace","logout","options","webex","request","method","uri","config","logoutUrl","body","token","cisService","service","requestAuthorizationCodeGrant","logger","info","code","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","jwt","hydraUri","internal","services","get","slice","process","env","HYDRA_SERVICE_URL","headers","authorization","access_token","token_type","expires_in","expiresIn","initServiceCatalogs","oneFlight"],"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\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\nexport default Authorization;\n"],"mappings":";;;;;;;;;;;AAMA;AACA;AAA2D;AAE3D;AACA;AACA;AACA;AACA;AACA,IAAMA,aAAa,GAAGC,sBAAW,CAACC,MAAM,SA0CrC,IAAAC,qBAAa,EAAC,eAAe,CAAC,UA1CQ;EACvCC,OAAO,EAAE;IACP;AACJ;AACA;AACA;AACA;AACA;IACIC,gBAAgB,EAAE;MAChBC,IAAI,EAAE,CAAC,eAAe,CAAC;MACvBC,EAAE,gBAAG;QACH,OAAO,IAAI,CAACC,aAAa;MAC3B;IACF;EACF,CAAC;EAEDC,OAAO,EAAE;IACP;AACJ;AACA;AACA;AACA;AACA;IACID,aAAa,EAAE;MACbE,OAAO,EAAE,KAAK;MACdC,IAAI,EAAE;IACR;EACF,CAAC;EAEDC,SAAS,EAAE,aAAa;EAExBC,MAAM,oBAAe;IAAA,IAAdC,OAAO,uEAAG,CAAC,CAAC;IACjB,IAAI,CAACC,KAAK,CAACC,OAAO,CAAC;MACjBC,MAAM,EAAE,MAAM;MACdC,GAAG,EAAE,IAAI,CAACC,MAAM,CAACC,SAAS;MAC1BC,IAAI,EAAE;QACJC,KAAK,EAAER,OAAO,CAACQ,KAAK;QACpBC,UAAU,EAAE,IAAI,CAACJ,MAAM,CAACK;MAC1B;IACF,CAAC,CAAC;EACJ,CAAC;EAID;AACF;AACA;AACA;AACA;AACA;AACA;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/dist/config.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
|
|
4
|
-
|
|
5
4
|
_Object$defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
|
-
|
|
9
7
|
exports.default = void 0;
|
|
10
|
-
|
|
11
8
|
/*!
|
|
12
9
|
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
13
10
|
*/
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["credentials"],"sources":["config.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nexport default {\n credentials: {}
|
|
1
|
+
{"version":3,"names":["credentials"],"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,eAIe;EACbA,WAAW,EAAE,CAAC;AAChB,CAAC;AAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,38 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
|
|
4
|
-
|
|
5
4
|
var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
|
|
6
|
-
|
|
7
5
|
_Object$defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
|
-
|
|
11
8
|
_Object$defineProperty(exports, "config", {
|
|
12
9
|
enumerable: true,
|
|
13
10
|
get: function get() {
|
|
14
11
|
return _config.default;
|
|
15
12
|
}
|
|
16
13
|
});
|
|
17
|
-
|
|
18
14
|
_Object$defineProperty(exports, "default", {
|
|
19
15
|
enumerable: true,
|
|
20
16
|
get: function get() {
|
|
21
17
|
return _authorization.default;
|
|
22
18
|
}
|
|
23
19
|
});
|
|
24
|
-
|
|
25
20
|
require("@webex/internal-plugin-device");
|
|
26
|
-
|
|
27
21
|
var _webexCore = require("@webex/webex-core");
|
|
28
|
-
|
|
29
22
|
var _authorization = _interopRequireDefault(require("./authorization"));
|
|
30
|
-
|
|
31
23
|
var _config = _interopRequireDefault(require("./config"));
|
|
32
|
-
|
|
33
24
|
/*!
|
|
34
25
|
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
35
26
|
*/
|
|
27
|
+
|
|
36
28
|
var proxies = ['isAuthorizing', 'isAuthenticating'];
|
|
37
29
|
(0, _webexCore.registerPlugin)('authorization', _authorization.default, {
|
|
38
30
|
config: _config.default,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["proxies","registerPlugin","Authorization","config"],"sources":["index.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport '@webex/internal-plugin-device';\nimport {registerPlugin} from '@webex/webex-core';\n\nimport Authorization from './authorization';\nimport config from './config';\n\nconst proxies = [
|
|
1
|
+
{"version":3,"names":["proxies","registerPlugin","Authorization","config"],"sources":["index.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport '@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":";;;;;;;;;;;;;;;;;;;AAIA;AACA;AAEA;AACA;AARA;AACA;AACA;;AAQA,IAAMA,OAAO,GAAG,CAAC,eAAe,EAAE,kBAAkB,CAAC;AAErD,IAAAC,yBAAc,EAAC,eAAe,EAAEC,sBAAa,EAAE;EAC7CC,MAAM,EAANA,eAAM;EACNH,OAAO,EAAPA;AACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// This file is read by tools that parse documentation comments conforming to the TSDoc standard.
|
|
2
|
+
// It should be published with your NPM package. It should not be tracked by Git.
|
|
3
|
+
{
|
|
4
|
+
"tsdocVersion": "0.12",
|
|
5
|
+
"toolPackages": [
|
|
6
|
+
{
|
|
7
|
+
"packageName": "@microsoft/api-extractor",
|
|
8
|
+
"packageVersion": "7.34.4"
|
|
9
|
+
}
|
|
10
|
+
]
|
|
11
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webex/plugin-authorization-node",
|
|
3
|
-
"version": "3.0.0-
|
|
3
|
+
"version": "3.0.0-bnr.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -21,18 +21,18 @@
|
|
|
21
21
|
]
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@webex/test-helper-appid": "3.0.0-
|
|
25
|
-
"@webex/test-helper-chai": "3.0.0-
|
|
26
|
-
"@webex/test-helper-mocha": "3.0.0-
|
|
27
|
-
"@webex/test-helper-mock-webex": "3.0.0-
|
|
28
|
-
"@webex/test-helper-test-users": "3.0.0-
|
|
24
|
+
"@webex/test-helper-appid": "3.0.0-bnr.2",
|
|
25
|
+
"@webex/test-helper-chai": "3.0.0-bnr.2",
|
|
26
|
+
"@webex/test-helper-mocha": "3.0.0-bnr.2",
|
|
27
|
+
"@webex/test-helper-mock-webex": "3.0.0-bnr.2",
|
|
28
|
+
"@webex/test-helper-test-users": "3.0.0-bnr.2",
|
|
29
29
|
"sinon": "^9.2.4"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@webex/common": "3.0.0-
|
|
33
|
-
"@webex/internal-plugin-device": "3.0.0-
|
|
34
|
-
"@webex/plugin-authorization-node": "3.0.0-
|
|
35
|
-
"@webex/webex-core": "3.0.0-
|
|
32
|
+
"@webex/common": "3.0.0-bnr.2",
|
|
33
|
+
"@webex/internal-plugin-device": "3.0.0-bnr.2",
|
|
34
|
+
"@webex/plugin-authorization-node": "3.0.0-bnr.2",
|
|
35
|
+
"@webex/webex-core": "3.0.0-bnr.2",
|
|
36
36
|
"uuid": "^3.3.2"
|
|
37
37
|
}
|
|
38
38
|
}
|
package/src/authorization.js
CHANGED
|
@@ -24,8 +24,8 @@ const Authorization = WebexPlugin.extend({
|
|
|
24
24
|
deps: ['isAuthorizing'],
|
|
25
25
|
fn() {
|
|
26
26
|
return this.isAuthorizing;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
29
|
},
|
|
30
30
|
|
|
31
31
|
session: {
|
|
@@ -37,8 +37,8 @@ const Authorization = WebexPlugin.extend({
|
|
|
37
37
|
*/
|
|
38
38
|
isAuthorizing: {
|
|
39
39
|
default: false,
|
|
40
|
-
type: 'boolean'
|
|
41
|
-
}
|
|
40
|
+
type: 'boolean',
|
|
41
|
+
},
|
|
42
42
|
},
|
|
43
43
|
|
|
44
44
|
namespace: 'Credentials',
|
|
@@ -49,8 +49,8 @@ const Authorization = WebexPlugin.extend({
|
|
|
49
49
|
uri: this.config.logoutUrl,
|
|
50
50
|
body: {
|
|
51
51
|
token: options.token,
|
|
52
|
-
cisService: this.config.service
|
|
53
|
-
}
|
|
52
|
+
cisService: this.config.service,
|
|
53
|
+
},
|
|
54
54
|
});
|
|
55
55
|
},
|
|
56
56
|
|
|
@@ -71,22 +71,23 @@ const Authorization = WebexPlugin.extend({
|
|
|
71
71
|
return Promise.reject(new Error('`options.code` is required'));
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
return this.webex
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
74
|
+
return this.webex
|
|
75
|
+
.request({
|
|
76
|
+
method: 'POST',
|
|
77
|
+
uri: this.config.tokenUrl,
|
|
78
|
+
form: {
|
|
79
|
+
grant_type: 'authorization_code',
|
|
80
|
+
redirect_uri: this.config.redirect_uri,
|
|
81
|
+
code: options.code,
|
|
82
|
+
self_contained_token: true,
|
|
83
|
+
},
|
|
84
|
+
auth: {
|
|
85
|
+
user: this.config.client_id,
|
|
86
|
+
pass: this.config.client_secret,
|
|
87
|
+
sendImmediately: true,
|
|
88
|
+
},
|
|
89
|
+
shouldRefreshAccessToken: false,
|
|
90
|
+
})
|
|
90
91
|
.then((res) => {
|
|
91
92
|
this.webex.credentials.set({supertoken: res.body});
|
|
92
93
|
})
|
|
@@ -126,29 +127,28 @@ const Authorization = WebexPlugin.extend({
|
|
|
126
127
|
hydraUri += '/';
|
|
127
128
|
}
|
|
128
129
|
|
|
129
|
-
hydraUri = hydraUri ||
|
|
130
|
-
process.env.HYDRA_SERVICE_URL ||
|
|
131
|
-
'https://api.ciscospark.com/v1/';
|
|
130
|
+
hydraUri = hydraUri || process.env.HYDRA_SERVICE_URL || 'https://api.ciscospark.com/v1/';
|
|
132
131
|
|
|
133
|
-
return this.webex
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
132
|
+
return this.webex
|
|
133
|
+
.request({
|
|
134
|
+
method: 'POST',
|
|
135
|
+
uri: `${hydraUri}jwt/login`,
|
|
136
|
+
headers: {
|
|
137
|
+
authorization: jwt,
|
|
138
|
+
},
|
|
139
|
+
})
|
|
140
140
|
.then(({body}) => ({
|
|
141
141
|
access_token: body.token,
|
|
142
142
|
token_type: 'Bearer',
|
|
143
|
-
expires_in: body.expiresIn
|
|
143
|
+
expires_in: body.expiresIn,
|
|
144
144
|
}))
|
|
145
145
|
.then((token) => {
|
|
146
146
|
this.webex.credentials.set({
|
|
147
|
-
supertoken: token
|
|
147
|
+
supertoken: token,
|
|
148
148
|
});
|
|
149
149
|
})
|
|
150
150
|
.then(() => this.webex.internal.services.initServiceCatalogs());
|
|
151
|
-
}
|
|
151
|
+
},
|
|
152
152
|
});
|
|
153
153
|
|
|
154
154
|
export default Authorization;
|
package/src/config.js
CHANGED
package/src/index.js
CHANGED
|
@@ -8,14 +8,11 @@ import {registerPlugin} from '@webex/webex-core';
|
|
|
8
8
|
import Authorization from './authorization';
|
|
9
9
|
import config from './config';
|
|
10
10
|
|
|
11
|
-
const proxies = [
|
|
12
|
-
'isAuthorizing',
|
|
13
|
-
'isAuthenticating'
|
|
14
|
-
];
|
|
11
|
+
const proxies = ['isAuthorizing', 'isAuthenticating'];
|
|
15
12
|
|
|
16
13
|
registerPlugin('authorization', Authorization, {
|
|
17
14
|
config,
|
|
18
|
-
proxies
|
|
15
|
+
proxies,
|
|
19
16
|
});
|
|
20
17
|
|
|
21
18
|
export {default} from './authorization';
|
|
@@ -18,21 +18,21 @@ nodeOnly(describe)('plugin-authorization-node', () => {
|
|
|
18
18
|
describe('#logout()', () => {
|
|
19
19
|
let webex, spock;
|
|
20
20
|
|
|
21
|
-
beforeEach('create authorized webex user', () =>
|
|
22
|
-
.then(([u]) => {
|
|
21
|
+
beforeEach('create authorized webex user', () =>
|
|
22
|
+
testUsers.create({count: 1}).then(([u]) => {
|
|
23
23
|
spock = u;
|
|
24
24
|
webex = new WebexCore({credentials: spock.token});
|
|
25
|
-
})
|
|
25
|
+
})
|
|
26
|
+
);
|
|
26
27
|
|
|
27
|
-
it(
|
|
28
|
+
it("invalidates all of the use's tokens", () => {
|
|
28
29
|
sinon.spy(webex.authorization, 'logout');
|
|
29
30
|
sinon.spy(webex, 'logout');
|
|
30
31
|
|
|
31
|
-
return webex.logout()
|
|
32
|
-
.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
});
|
|
32
|
+
return webex.logout().then(() => {
|
|
33
|
+
assert.called(webex.logout);
|
|
34
|
+
assert.called(webex.authorization.logout);
|
|
35
|
+
});
|
|
36
36
|
});
|
|
37
37
|
});
|
|
38
38
|
|
|
@@ -41,13 +41,13 @@ nodeOnly(describe)('plugin-authorization-node', () => {
|
|
|
41
41
|
const userId = uuid.v4();
|
|
42
42
|
const displayName = `test-${userId}`;
|
|
43
43
|
|
|
44
|
-
return createUser({displayName, userId})
|
|
45
|
-
|
|
46
|
-
const webex = new WebexCore();
|
|
44
|
+
return createUser({displayName, userId}).then(({jwt}) => {
|
|
45
|
+
const webex = new WebexCore();
|
|
47
46
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
return webex.authorization
|
|
48
|
+
.requestAccessTokenFromJwt({jwt})
|
|
49
|
+
.then(() => assert.isTrue(webex.canAuthorize));
|
|
50
|
+
});
|
|
51
51
|
});
|
|
52
52
|
|
|
53
53
|
it('should call services#initServiceCatalogs()', () => {
|
|
@@ -63,37 +63,36 @@ nodeOnly(describe)('plugin-authorization-node', () => {
|
|
|
63
63
|
});
|
|
64
64
|
});
|
|
65
65
|
|
|
66
|
-
describe.skip('
|
|
66
|
+
describe.skip("'#refresh", () => {
|
|
67
67
|
describe('when used with an appid access token', () => {
|
|
68
68
|
it('refreshes the access token', () => {
|
|
69
69
|
const userId = uuid.v4();
|
|
70
70
|
const displayName = `test-${userId}`;
|
|
71
71
|
|
|
72
|
-
return createUser({displayName, userId})
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
let token;
|
|
85
|
-
|
|
86
|
-
return webex.authorization.requestAccessTokenFromJwt({jwt})
|
|
87
|
-
.then(() => {
|
|
88
|
-
token = webex.credentials.supertoken.access_token;
|
|
89
|
-
assert.isTrue(webex.canAuthorize);
|
|
90
|
-
})
|
|
91
|
-
.then(() => webex.refresh())
|
|
92
|
-
.then(() => {
|
|
93
|
-
assert.isTrue(webex.canAuthorize);
|
|
94
|
-
assert.notEqual(webex.credentials.supertoken.access_token, token);
|
|
95
|
-
});
|
|
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
|
+
},
|
|
96
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
|
+
});
|
|
97
96
|
});
|
|
98
97
|
});
|
|
99
98
|
});
|
|
@@ -102,19 +101,20 @@ nodeOnly(describe)('plugin-authorization-node', () => {
|
|
|
102
101
|
describe('when the user has the webex entitlement', () => {
|
|
103
102
|
let code, webex;
|
|
104
103
|
|
|
105
|
-
beforeEach('create auth code only test user', () =>
|
|
106
|
-
.then(([u]) => {
|
|
104
|
+
beforeEach('create auth code only test user', () =>
|
|
105
|
+
testUsers.create({config: {authCodeOnly: true}}).then(([u]) => {
|
|
107
106
|
webex = new WebexCore();
|
|
108
107
|
code = u.token.auth_code;
|
|
109
|
-
})
|
|
108
|
+
})
|
|
109
|
+
);
|
|
110
110
|
|
|
111
|
-
it('exchanges an authorization code for an access token', () =>
|
|
112
|
-
.then(() => {
|
|
111
|
+
it('exchanges an authorization code for an access token', () =>
|
|
112
|
+
webex.authorization.requestAuthorizationCodeGrant({code}).then(() => {
|
|
113
113
|
assert.isDefined(webex.credentials.supertoken);
|
|
114
114
|
|
|
115
115
|
return Promise.all([
|
|
116
116
|
webex.credentials.getUserToken(apiScope),
|
|
117
|
-
webex.credentials.getUserToken('spark:kms')
|
|
117
|
+
webex.credentials.getUserToken('spark:kms'),
|
|
118
118
|
]);
|
|
119
119
|
}));
|
|
120
120
|
});
|
|
@@ -122,33 +122,42 @@ nodeOnly(describe)('plugin-authorization-node', () => {
|
|
|
122
122
|
describe('when the user does not have the webex entitlement', () => {
|
|
123
123
|
let code, webex;
|
|
124
124
|
|
|
125
|
-
beforeEach('create non-webex-entitled test user', () =>
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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(() => {
|
|
145
148
|
assert.isDefined(webex.credentials.supertoken);
|
|
146
149
|
|
|
147
150
|
return Promise.all([
|
|
148
|
-
webex.credentials
|
|
149
|
-
.
|
|
150
|
-
|
|
151
|
-
|
|
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
|
+
),
|
|
152
161
|
]);
|
|
153
162
|
}));
|
|
154
163
|
});
|
|
@@ -22,32 +22,39 @@ nodeOnly(describe)('plugin-authorization-node', () => {
|
|
|
22
22
|
webex = new MockWebex({
|
|
23
23
|
children: {
|
|
24
24
|
authorization: Authorization,
|
|
25
|
-
credentials: Credentials
|
|
26
|
-
}
|
|
25
|
+
credentials: Credentials,
|
|
26
|
+
},
|
|
27
27
|
});
|
|
28
28
|
|
|
29
|
-
webex.request.returns(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
webex.request.returns(
|
|
30
|
+
Promise.resolve({
|
|
31
|
+
statusCode: 200,
|
|
32
|
+
body: {
|
|
33
|
+
access_token: 'AT3',
|
|
34
|
+
token_type: 'Fake',
|
|
35
|
+
},
|
|
36
|
+
})
|
|
37
|
+
);
|
|
36
38
|
});
|
|
37
39
|
|
|
38
40
|
describe('#requestAuthorizationCodeGrant', () => {
|
|
39
|
-
it('requires a `code`', () =>
|
|
41
|
+
it('requires a `code`', () =>
|
|
42
|
+
assert.isRejected(
|
|
43
|
+
webex.authorization.requestAuthorizationCodeGrant(),
|
|
44
|
+
/`options.code` is required/
|
|
45
|
+
));
|
|
40
46
|
|
|
41
|
-
it('exchanges an authorization code for an access token', () =>
|
|
42
|
-
|
|
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')));
|
|
43
51
|
|
|
44
52
|
it('sets #isAuthenticating', () => {
|
|
45
53
|
const promise = webex.authorization.requestAuthorizationCodeGrant({code: 5});
|
|
46
54
|
|
|
47
55
|
assert.isTrue(webex.authorization.isAuthenticating);
|
|
48
56
|
|
|
49
|
-
return promise
|
|
50
|
-
.then(() => assert.isFalse(webex.authorization.isAuthenticating));
|
|
57
|
+
return promise.then(() => assert.isFalse(webex.authorization.isAuthenticating));
|
|
51
58
|
});
|
|
52
59
|
|
|
53
60
|
it('sets #isAuthorizing', () => {
|
|
@@ -55,8 +62,7 @@ nodeOnly(describe)('plugin-authorization-node', () => {
|
|
|
55
62
|
|
|
56
63
|
assert.isTrue(webex.authorization.isAuthorizing);
|
|
57
64
|
|
|
58
|
-
return promise
|
|
59
|
-
.then(() => assert.isFalse(webex.authorization.isAuthorizing));
|
|
65
|
+
return promise.then(() => assert.isFalse(webex.authorization.isAuthorizing));
|
|
60
66
|
});
|
|
61
67
|
});
|
|
62
68
|
});
|