[jsonwebtoken] Fix verify with encrypted key (#39028)

* [jsonwebtoken] Added breaking test for jwt.verify

* [jsonwebtoken] Fix verify with encrypted key

* [jsonwebtoken] Update formatting (auto)
This commit is contained in:
Fabien O'Carroll
2019-10-15 12:12:24 -07:00
committed by Andrew Branch
parent a5000ae84f
commit 80e25f0d49
2 changed files with 10 additions and 7 deletions
+3 -7
View File
@@ -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;
+7
View File
@@ -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) => {