UNPKG

@kitmi/jacaranda

Version:

JavaScript application framework

76 lines (75 loc) 2.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "default", { enumerable: true, get: function() { return _default; } }); const _Feature = /*#__PURE__*/ _interop_require_default(require("../Feature")); function _interop_require_default(obj) { return obj && obj.__esModule ? obj : { default: obj }; } const _default = { stage: _Feature.default.INIT, groupable: true, packages: [ 'jsonwebtoken' ], load_: async function(app, options, name) { let { key, privateKey, publicKey } = app.featureConfig(options, { schema: [ { key: { type: 'text' } }, { privateKey: { type: 'text', post: [ '>trimLines' ] }, publicKey: { type: 'text', post: [ '>trimLines' ] } } ] }, name); let asymmetric = false; if (key) { privateKey = key; publicKey = key; } else { asymmetric = true; } const jwt = await app.tryRequire_('jsonwebtoken', true); const service = { get publicKey () { return publicKey; }, sign: (payload, options)=>{ return jwt.sign(payload, privateKey, asymmetric ? { algorithm: 'RS256', ...options } : options); }, verify: (token, options)=>{ return jwt.verify(token, publicKey, asymmetric ? { algorithm: 'RS256', ...options } : options); } }; app.registerService(name, service); } }; //# sourceMappingURL=jwt.js.map