nestjs-jwt2
Advanced tools
Comparing version 8.0.1 to 8.0.2
@@ -0,1 +1,6 @@ | ||
/// <reference types="node" /> | ||
export declare class ValidateTokenOptions { | ||
issuers?: string[]; | ||
cert?: Buffer; | ||
} | ||
export declare class JwtService { | ||
@@ -7,5 +12,6 @@ private readonly client; | ||
constructor(); | ||
validateToken(token: string): Promise<boolean>; | ||
validateToken(token: string, options?: ValidateTokenOptions): Promise<boolean>; | ||
decodeToken(token: string): Promise<object>; | ||
private getKey; | ||
private getCertOrKey; | ||
} |
@@ -12,3 +12,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.JwtService = void 0; | ||
exports.JwtService = exports.ValidateTokenOptions = void 0; | ||
const jwt = require("jsonwebtoken"); | ||
@@ -18,2 +18,5 @@ const jwksClient = require("jwks-rsa"); | ||
const common_1 = require("@nestjs/common"); | ||
class ValidateTokenOptions { | ||
} | ||
exports.ValidateTokenOptions = ValidateTokenOptions; | ||
let JwtService = class JwtService { | ||
@@ -38,3 +41,3 @@ constructor() { | ||
rateLimit: true, | ||
jwksRequestsPerMinute: 10, | ||
jwksRequestsPerMinute: 10 | ||
}); | ||
@@ -50,8 +53,9 @@ } | ||
} | ||
validateToken(token) { | ||
const certOrGetKey = this.cert ? this.cert : this.getKey.bind(this); | ||
validateToken(token, options) { | ||
const certOrGetKey = this.getCertOrKey(options); | ||
return new Promise((resolve, reject) => { | ||
var _a; | ||
jwt.verify(token, certOrGetKey, { | ||
audience: this.audiences, | ||
issuer: this.issuers, | ||
issuer: (_a = options === null || options === void 0 ? void 0 : options.issuers) !== null && _a !== void 0 ? _a : this.issuers | ||
}, err => { | ||
@@ -67,3 +71,3 @@ if (err) { | ||
return jwt.decode(token, { | ||
json: true, | ||
json: true | ||
}); | ||
@@ -81,2 +85,9 @@ } | ||
} | ||
getCertOrKey(options) { | ||
var _a; | ||
if (this.cert || (options === null || options === void 0 ? void 0 : options.cert)) { | ||
return (_a = options === null || options === void 0 ? void 0 : options.cert) !== null && _a !== void 0 ? _a : this.cert; | ||
} | ||
return this.getKey.bind(this); | ||
} | ||
}; | ||
@@ -83,0 +94,0 @@ JwtService = __decorate([ |
{ | ||
"name": "nestjs-jwt2", | ||
"version": "8.0.1", | ||
"version": "8.0.2", | ||
"description": "Jwt utils for nestjs", | ||
@@ -5,0 +5,0 @@ "author": "Julien Dufresne", |
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
14799
346