jsonwebtoken: Allow audience to be verified with regular expressions

See https://github.com/auth0/node-jsonwebtoken/pull/398
This commit is contained in:
Andrew Haines 2019-02-26 10:59:04 +00:00
parent abe95f396c
commit 9f6f861222
No known key found for this signature in database
GPG Key ID: B16A6F178227A23E
2 changed files with 7 additions and 1 deletions

View File

@ -59,7 +59,7 @@ export interface SignOptions {
export interface VerifyOptions {
algorithms?: string[];
audience?: string | string[];
audience?: string | RegExp | Array<string | RegExp>;
clockTimestamp?: number;
clockTolerance?: number;
issuer?: string | string[];

View File

@ -101,6 +101,12 @@ cert = fs.readFileSync("public.pem"); // get public key
jwt.verify(token, cert, { audience: "urn:foo" }, (err, decoded) => {
// if audience mismatch, err == invalid audience
});
jwt.verify(token, cert, { audience: /urn:f[o]{2}/ }, (err, decoded) => {
// if audience mismatch, err == invalid audience
});
jwt.verify(token, cert, { audience: [/urn:f[o]{2}/, "urn:bar"] }, (err, decoded) => {
// if audience mismatch, err == invalid audience
});
// verify issuer
cert = fs.readFileSync("public.pem"); // get public key