From 80e25f0d492eaa02fa9f84a49665475fd7bac467 Mon Sep 17 00:00:00 2001 From: Fabien O'Carroll Date: Wed, 16 Oct 2019 02:12:24 +0700 Subject: [PATCH] [jsonwebtoken] Fix verify with encrypted key (#39028) * [jsonwebtoken] Added breaking test for jwt.verify * [jsonwebtoken] Fix verify with encrypted key * [jsonwebtoken] Update formatting (auto) --- types/jsonwebtoken/index.d.ts | 10 +++------- types/jsonwebtoken/jsonwebtoken-tests.ts | 7 +++++++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/types/jsonwebtoken/index.d.ts b/types/jsonwebtoken/index.d.ts index 81dbbeae80..ef6dc7b0b1 100644 --- a/types/jsonwebtoken/index.d.ts +++ b/types/jsonwebtoken/index.d.ts @@ -159,11 +159,7 @@ export function sign( * [options] - Options for the verification * returns - The decoded token. */ -export function verify( - token: string, - secretOrPublicKey: string | Buffer, - options?: VerifyOptions, -): object | string; +export function verify(token: string, secretOrPublicKey: Secret, options?: VerifyOptions): object | string; /** * Asynchronously verify given token using a secret or a public key to get a decoded token @@ -176,12 +172,12 @@ export function verify( */ export function verify( token: string, - secretOrPublicKey: string | Buffer | GetPublicKeyOrSecret, + secretOrPublicKey: Secret | GetPublicKeyOrSecret, callback?: VerifyCallback, ): void; export function verify( token: string, - secretOrPublicKey: string | Buffer | GetPublicKeyOrSecret, + secretOrPublicKey: Secret | GetPublicKeyOrSecret, options?: VerifyOptions, callback?: VerifyCallback, ): void; diff --git a/types/jsonwebtoken/jsonwebtoken-tests.ts b/types/jsonwebtoken/jsonwebtoken-tests.ts index 2f66502cb4..68587b9e2b 100644 --- a/types/jsonwebtoken/jsonwebtoken-tests.ts +++ b/types/jsonwebtoken/jsonwebtoken-tests.ts @@ -76,6 +76,13 @@ jwt.verify(token, "wrong-secret", (err, decoded) => { // decoded undefined }); +// verify with encrypted RSA SHA256 private key +jwt.verify(token, secret, (err, decoded) => { + const result = decoded as TestObject; + + console.log(result.foo); // bar +}); + // verify a token asymmetric cert = fs.readFileSync("public.pem"); // get public key jwt.verify(token, cert, (err, decoded) => {