@webex/plugin-authorization-node 3.0.0-beta.42 → 3.0.0-beta.421
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 +34 -1
- package/dist/authorization.js.map +1 -1
- package/package.json +10 -10
- package/src/authorization.js +30 -0
package/dist/authorization.js
CHANGED
|
@@ -11,6 +11,8 @@ var _getOwnPropertyDescriptor = _interopRequireDefault(require("@babel/runtime-c
|
|
|
11
11
|
var _applyDecoratedDescriptor2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/applyDecoratedDescriptor"));
|
|
12
12
|
var _common = require("@webex/common");
|
|
13
13
|
var _webexCore = require("@webex/webex-core");
|
|
14
|
+
var _jsonwebtoken = _interopRequireDefault(require("jsonwebtoken"));
|
|
15
|
+
var _uuid = _interopRequireDefault(require("uuid"));
|
|
14
16
|
var _dec, _obj;
|
|
15
17
|
/**
|
|
16
18
|
* NodeJS support for OAuth2
|
|
@@ -144,7 +146,38 @@ var Authorization = _webexCore.WebexPlugin.extend((_dec = (0, _common.whileInFli
|
|
|
144
146
|
return _this2.webex.internal.services.initServiceCatalogs();
|
|
145
147
|
});
|
|
146
148
|
},
|
|
147
|
-
|
|
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
|
+
*/
|
|
158
|
+
createJwt: function createJwt(_ref3) {
|
|
159
|
+
var issuer = _ref3.issuer,
|
|
160
|
+
secretId = _ref3.secretId,
|
|
161
|
+
displayName = _ref3.displayName,
|
|
162
|
+
expiresIn = _ref3.expiresIn;
|
|
163
|
+
var secret = Buffer.from(secretId, 'base64');
|
|
164
|
+
var payload = {
|
|
165
|
+
"sub": "guest-user-".concat((0, _uuid.default)()),
|
|
166
|
+
"iss": issuer,
|
|
167
|
+
"name": displayName || "Guest User - ".concat((0, _uuid.default)())
|
|
168
|
+
};
|
|
169
|
+
try {
|
|
170
|
+
var jwtToken = _jsonwebtoken.default.sign(payload, secret, {
|
|
171
|
+
expiresIn: expiresIn
|
|
172
|
+
});
|
|
173
|
+
return _promise.default.resolve({
|
|
174
|
+
jwt: jwtToken
|
|
175
|
+
});
|
|
176
|
+
} catch (e) {
|
|
177
|
+
return _promise.default.reject(e);
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
version: "3.0.0-beta.421"
|
|
148
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)));
|
|
149
182
|
var _default = Authorization;
|
|
150
183
|
exports.default = _default;
|
|
@@ -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 },\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;
|
|
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","createJwt","issuer","secretId","displayName","secret","Buffer","from","payload","uuid","jwtToken","sign","resolve","e","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\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;AACA;AAEA;AACA;AAAwB;AAExB;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;I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AC;IAC1B;EACF,CAAC;EAAA;AAEH,CAAC,yFAzHEC,iBAAS,qKA+CTA,iBAAS,6FA0EV;AAAC,eAEYrF,aAAa;AAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webex/plugin-authorization-node",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.421",
|
|
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-beta.
|
|
25
|
-
"@webex/test-helper-chai": "3.0.0-beta.
|
|
26
|
-
"@webex/test-helper-mocha": "3.0.0-beta.
|
|
27
|
-
"@webex/test-helper-mock-webex": "3.0.0-beta.
|
|
28
|
-
"@webex/test-helper-test-users": "3.0.0-beta.
|
|
24
|
+
"@webex/test-helper-appid": "3.0.0-beta.421",
|
|
25
|
+
"@webex/test-helper-chai": "3.0.0-beta.421",
|
|
26
|
+
"@webex/test-helper-mocha": "3.0.0-beta.421",
|
|
27
|
+
"@webex/test-helper-mock-webex": "3.0.0-beta.421",
|
|
28
|
+
"@webex/test-helper-test-users": "3.0.0-beta.421",
|
|
29
29
|
"sinon": "^9.2.4"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@webex/common": "3.0.0-beta.
|
|
33
|
-
"@webex/internal-plugin-device": "3.0.0-beta.
|
|
34
|
-
"@webex/plugin-authorization-node": "3.0.0-beta.
|
|
35
|
-
"@webex/webex-core": "3.0.0-beta.
|
|
32
|
+
"@webex/common": "3.0.0-beta.421",
|
|
33
|
+
"@webex/internal-plugin-device": "3.0.0-beta.421",
|
|
34
|
+
"@webex/plugin-authorization-node": "3.0.0-beta.421",
|
|
35
|
+
"@webex/webex-core": "3.0.0-beta.421",
|
|
36
36
|
"uuid": "^3.3.2"
|
|
37
37
|
}
|
|
38
38
|
}
|
package/src/authorization.js
CHANGED
|
@@ -7,6 +7,9 @@
|
|
|
7
7
|
import {oneFlight, whileInFlight} from '@webex/common';
|
|
8
8
|
import {grantErrors, WebexPlugin} from '@webex/webex-core';
|
|
9
9
|
|
|
10
|
+
import jwt from 'jsonwebtoken';
|
|
11
|
+
import uuid from 'uuid';
|
|
12
|
+
|
|
10
13
|
/**
|
|
11
14
|
* NodeJS support for OAuth2
|
|
12
15
|
* @class
|
|
@@ -149,6 +152,33 @@ const Authorization = WebexPlugin.extend({
|
|
|
149
152
|
})
|
|
150
153
|
.then(() => this.webex.internal.services.initServiceCatalogs());
|
|
151
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
|
+
|
|
152
182
|
});
|
|
153
183
|
|
|
154
184
|
export default Authorization;
|