@webex/plugin-authorization-node 3.0.0-bnr.5 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.eslintrc.js ADDED
@@ -0,0 +1,6 @@
1
+ const config = {
2
+ root: true,
3
+ extends: ['@webex/eslint-config-legacy'],
4
+ };
5
+
6
+ module.exports = config;
@@ -0,0 +1,3 @@
1
+ const babelConfigLegacy = require('@webex/babel-config-legacy');
2
+
3
+ module.exports = babelConfigLegacy;
@@ -11,7 +11,13 @@ 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;
17
+ /*!
18
+ * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
19
+ */
20
+ /* eslint camelcase: [0] */
15
21
  /**
16
22
  * NodeJS support for OAuth2
17
23
  * @class
@@ -144,8 +150,38 @@ var Authorization = _webexCore.WebexPlugin.extend((_dec = (0, _common.whileInFli
144
150
  return _this2.webex.internal.services.initServiceCatalogs();
145
151
  });
146
152
  },
147
- version: "3.0.0-bnr.5"
153
+ /**
154
+ * Creates a jwt user token
155
+ * @param {object} options
156
+ * @param {String} options.issuer Guest Issuer ID
157
+ * @param {String} options.secretId Guest Secret ID
158
+ * @param {String} options.displayName Guest Display Name | optional
159
+ * @param {String} options.expiresIn
160
+ * @returns {Promise<object>}
161
+ */
162
+ createJwt: function createJwt(_ref3) {
163
+ var issuer = _ref3.issuer,
164
+ secretId = _ref3.secretId,
165
+ displayName = _ref3.displayName,
166
+ expiresIn = _ref3.expiresIn;
167
+ var secret = Buffer.from(secretId, 'base64');
168
+ var payload = {
169
+ "sub": "guest-user-".concat((0, _uuid.default)()),
170
+ "iss": issuer,
171
+ "name": displayName || "Guest User - ".concat((0, _uuid.default)())
172
+ };
173
+ try {
174
+ var jwtToken = _jsonwebtoken.default.sign(payload, secret, {
175
+ expiresIn: expiresIn
176
+ });
177
+ return _promise.default.resolve({
178
+ jwt: jwtToken
179
+ });
180
+ } catch (e) {
181
+ return _promise.default.reject(e);
182
+ }
183
+ },
184
+ version: "3.0.0"
148
185
  }, ((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
- var _default = Authorization;
150
- exports.default = _default;
186
+ var _default = exports.default = Authorization;
151
187
  //# 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 },\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,U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C;EACnE,CAAC;EAAA;AACH,CAAC,yFA9FEC,iBAAS,qKA+CTA,iBAAS,6FA+CV;AAAC,eAEYxE,aAAa;AAAA"}
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;AAVxB;AACA;AACA;AAEA;AAQA;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;A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C;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,EA0EX,CAAC;AAAC,IAAAoG,QAAA,GAAAC,OAAA,CAAA1F,OAAA,GAEYV,aAAa"}
package/dist/config.js CHANGED
@@ -8,8 +8,7 @@ exports.default = void 0;
8
8
  /*!
9
9
  * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
10
10
  */
11
- var _default = {
11
+ var _default = exports.default = {
12
12
  credentials: {}
13
13
  };
14
- exports.default = _default;
15
14
  //# sourceMappingURL=config.js.map
@@ -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: {},\n};\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AAFA,eAIe;EACbA,WAAW,EAAE,CAAC;AAChB,CAAC;AAAA"}
1
+ {"version":3,"names":["_default","exports","default","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,IAAAA,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAIe;EACbC,WAAW,EAAE,CAAC;AAChB,CAAC"}
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 = ['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"}
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 ADDED
@@ -0,0 +1,3 @@
1
+ const config = require('@webex/jest-config-legacy');
2
+
3
+ module.exports = config;
package/package.json CHANGED
@@ -1,6 +1,5 @@
1
1
  {
2
2
  "name": "@webex/plugin-authorization-node",
3
- "version": "3.0.0-bnr.5",
4
3
  "description": "",
5
4
  "license": "MIT",
6
5
  "main": "dist/index.js",
@@ -21,18 +20,36 @@
21
20
  ]
22
21
  },
23
22
  "devDependencies": {
24
- "@webex/test-helper-appid": "3.0.0-bnr.5",
25
- "@webex/test-helper-chai": "3.0.0-bnr.5",
26
- "@webex/test-helper-mocha": "3.0.0-bnr.5",
27
- "@webex/test-helper-mock-webex": "3.0.0-bnr.5",
28
- "@webex/test-helper-test-users": "3.0.0-bnr.5",
23
+ "@babel/core": "^7.17.10",
24
+ "@webex/babel-config-legacy": "0.0.0",
25
+ "@webex/eslint-config-legacy": "0.0.0",
26
+ "@webex/jest-config-legacy": "0.0.0",
27
+ "@webex/legacy-tools": "0.0.0",
28
+ "@webex/test-helper-appid": "3.0.0",
29
+ "@webex/test-helper-chai": "3.0.0",
30
+ "@webex/test-helper-mocha": "3.0.0",
31
+ "@webex/test-helper-mock-webex": "3.0.0",
32
+ "@webex/test-helper-test-users": "3.0.0",
33
+ "eslint": "^8.24.0",
34
+ "prettier": "^2.7.1",
29
35
  "sinon": "^9.2.4"
30
36
  },
31
37
  "dependencies": {
32
- "@webex/common": "3.0.0-bnr.5",
33
- "@webex/internal-plugin-device": "3.0.0-bnr.5",
34
- "@webex/plugin-authorization-node": "3.0.0-bnr.5",
35
- "@webex/webex-core": "3.0.0-bnr.5",
38
+ "@webex/common": "3.0.0",
39
+ "@webex/internal-plugin-device": "3.0.0",
40
+ "@webex/webex-core": "3.0.0",
41
+ "jsonwebtoken": "^9.0.0",
36
42
  "uuid": "^3.3.2"
37
- }
38
- }
43
+ },
44
+ "scripts": {
45
+ "build": "yarn build:src",
46
+ "build:src": "webex-legacy-tools build -dest \"./dist\" -src \"./src\" -js -ts -maps",
47
+ "deploy:npm": "yarn npm publish",
48
+ "test": "yarn test:style && yarn test:unit && yarn test:integration && yarn test:browser",
49
+ "test:browser": "webex-legacy-tools test --integration --unit --runner karma",
50
+ "test:integration": "webex-legacy-tools test --integration --runner mocha",
51
+ "test:style": "eslint ./src/**/*.*",
52
+ "test:unit": "webex-legacy-tools test --unit --runner jest"
53
+ },
54
+ "version": "3.0.0"
55
+ }
package/process ADDED
@@ -0,0 +1 @@
1
+ module.exports = {browser: true};
@@ -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;
@@ -1,13 +0,0 @@
1
- /**
2
- * NodeJS support for OAuth2
3
- * @class
4
- * @name AuthorizationNode
5
- */
6
- declare const Authorization: any;
7
- export default Authorization;
8
-
9
- export declare namespace config {
10
- const credentials: {};
11
- }
12
-
13
- export { }
@@ -1,11 +0,0 @@
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
- }
@@ -1,7 +0,0 @@
1
- export default Authorization;
2
- /**
3
- * NodeJS support for OAuth2
4
- * @class
5
- * @name AuthorizationNode
6
- */
7
- declare const Authorization: any;
@@ -1,4 +0,0 @@
1
- declare namespace _default {
2
- const credentials: {};
3
- }
4
- export default _default;
@@ -1,2 +0,0 @@
1
- export { default } from "./authorization";
2
- export { default as config } from "./config";