UNPKG

revbits-cip-integration

Version:
53 lines (52 loc) 2.06 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.JWTClient = void 0; const JWT = __importStar(require("jsonwebtoken")); const config_1 = require("../utils/config"); class JWTClient { constructor(platform, privKey, actor = null) { this.platform = platform; this.privKey = privKey; this.actor = actor; } getJWT(user = null) { var _a; const { PLATFORM_JWT_EXPIRY } = config_1.JWT_CONFIG; const expiresIn = parseInt(PLATFORM_JWT_EXPIRY, 10); const body = { platform: this.platform }; if (user && (user === null || user === void 0 ? void 0 : user.username)) { body.username = user.username; } else if (this.actor && ((_a = this.actor) === null || _a === void 0 ? void 0 : _a.username)) { body.username = this.actor.username; } return JWT.sign(body, this.privKey, { expiresIn, algorithm: 'RS256', }); } } exports.JWTClient = JWTClient;