@vonage/jwt
Advanced tools
Comparing version 1.0.9 to 1.0.10
/// <reference types="node" /> | ||
import { JWTInterface, GeneratorOptions } from './common'; | ||
export declare class JWT implements JWTInterface { | ||
tokenGenerate<T>(applicationId: string, privateKey: string | Buffer, opts?: GeneratorOptions): string; | ||
tokenGenerate(applicationId: string, privateKey: string | Buffer, opts?: GeneratorOptions): string; | ||
private validateOptions; | ||
} |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -6,6 +9,11 @@ exports.JWT = void 0; | ||
const uuid_1 = require("uuid"); | ||
const debug_1 = __importDefault(require("debug")); | ||
const log = (0, debug_1.default)('vonage:jwt'); | ||
class JWT { | ||
tokenGenerate(applicationId, privateKey, opts) { | ||
if (!applicationId || !privateKey) | ||
log(`Application id: ${applicationId}`); | ||
log(`Provate key: ${privateKey}`); | ||
if (!applicationId || !privateKey) { | ||
throw new Error('Missing applicationId or privateKey'); | ||
} | ||
if (typeof applicationId !== 'string') { | ||
@@ -18,2 +26,3 @@ throw new Error('applicationId must be string'); | ||
const claims = this.validateOptions(opts); | ||
log('Claims', claims); | ||
claims.application_id = applicationId; | ||
@@ -28,22 +37,12 @@ return (0, jsonwebtoken_1.sign)(claims, privateKey, { | ||
const claims = { | ||
jti: (opts === null || opts === void 0 ? void 0 : opts.jti) || (0, uuid_1.v4)(), | ||
iat: (opts === null || opts === void 0 ? void 0 : opts.issued_at) || now, | ||
exp: now + ((opts === null || opts === void 0 ? void 0 : opts.ttl) || 900), | ||
...opts, | ||
jti: opts?.jti || (0, uuid_1.v4)(), | ||
iat: opts?.issued_at || now, | ||
exp: now + (opts?.ttl || 900), | ||
}; | ||
if (opts === null || opts === void 0 ? void 0 : opts.jti) { | ||
delete opts.jti; | ||
} | ||
if (opts === null || opts === void 0 ? void 0 : opts.issued_at) { | ||
delete opts.issued_at; | ||
} | ||
if (opts === null || opts === void 0 ? void 0 : opts.ttl) { | ||
delete opts.ttl; | ||
} | ||
if (opts === null || opts === void 0 ? void 0 : opts.subject) { | ||
if (opts?.subject) { | ||
claims.sub = opts.subject; | ||
delete opts.subject; | ||
} | ||
if (opts === null || opts === void 0 ? void 0 : opts.acl) { | ||
if (opts?.acl) { | ||
claims.acl = opts.acl; | ||
delete opts.acl; | ||
} | ||
@@ -50,0 +49,0 @@ for (const property in opts) { |
{ | ||
"name": "@vonage/jwt", | ||
"version": "1.0.9", | ||
"version": "1.0.10", | ||
"description": "Vonage JWT package. Creates JWT tokens for Vonage API's", | ||
@@ -26,2 +26,3 @@ "homepage": "https://github.com/vonage/vonage-node-sdk/tree/master/packages/jwt#readme", | ||
"dependencies": { | ||
"debug": "^4.3.4", | ||
"jsonwebtoken": "^9.0.0", | ||
@@ -28,0 +29,0 @@ "uuid": "^9.0.0" |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9087
3
106
+ Addeddebug@^4.3.4
+ Addeddebug@4.3.7(transitive)