mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-07 08:17:05 +00:00
[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:
committed by
Andrew Branch
parent
a5000ae84f
commit
80e25f0d49
Vendored
+3
-7
@@ -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;
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user