mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Add Buffer type to property 'key' in Secret (#38360)
This commit is contained in:
parent
9ea7f6359d
commit
4878bcc79f
13
types/jsonwebtoken/index.d.ts
vendored
13
types/jsonwebtoken/index.d.ts
vendored
@ -5,7 +5,8 @@
|
||||
// Brice BERNARD <https://github.com/brikou>,
|
||||
// Veli-Pekka Kestilä <https://github.com/vpk>,
|
||||
// Daniel Parker <https://github.com/rlgod>,
|
||||
// Kjell Dießel <https://github.com/kettil>
|
||||
// Kjell Dießel <https://github.com/kettil>,
|
||||
// Robert Gajda <https://github.com/RunAge>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
@ -82,7 +83,10 @@ export interface DecodeOptions {
|
||||
complete?: boolean;
|
||||
json?: boolean;
|
||||
}
|
||||
export type VerifyErrors= JsonWebTokenError | NotBeforeError | TokenExpiredError;
|
||||
export type VerifyErrors =
|
||||
| JsonWebTokenError
|
||||
| NotBeforeError
|
||||
| TokenExpiredError;
|
||||
export type VerifyCallback = (
|
||||
err: VerifyErrors,
|
||||
decoded: object | string,
|
||||
@ -111,7 +115,10 @@ export type GetPublicKeyOrSecret = (
|
||||
callback: SigningKeyCallback
|
||||
) => void;
|
||||
|
||||
export type Secret = string | Buffer | { key: string; passphrase: string };
|
||||
export type Secret =
|
||||
| string
|
||||
| Buffer
|
||||
| { key: string | Buffer; passphrase: string };
|
||||
|
||||
/**
|
||||
* Synchronously sign the given payload into a JSON Web Token string
|
||||
|
||||
@ -42,6 +42,7 @@ token = jwt.sign(testObject, cert, { algorithm: "RS256" });
|
||||
const privKey: Buffer = fs.readFileSync("encrypted_private.key"); // get private key
|
||||
const secret = { key: privKey.toString(), passphrase: "keypwd" };
|
||||
token = jwt.sign(testObject, secret, { algorithm: "RS256" }); // the algorithm option is mandatory in this case
|
||||
token = jwt.sign(testObject, { key: privKey, passphrase: 'keypwd' }, { algorithm: "RS256" });
|
||||
|
||||
// sign asynchronously
|
||||
jwt.sign(testObject, cert, { algorithm: "RS256" }, (
|
||||
@ -64,9 +65,9 @@ jwt.verify(token, "shhhhh", (err, decoded) => {
|
||||
|
||||
// use external time for verifying
|
||||
jwt.verify(token, 'shhhhh', { clockTimestamp: 1 }, (err, decoded) => {
|
||||
const result = decoded as TestObject;
|
||||
const result = decoded as TestObject;
|
||||
|
||||
console.log(result.foo); // bar
|
||||
console.log(result.foo); // bar
|
||||
});
|
||||
|
||||
// invalid token
|
||||
|
||||
Loading…
Reference in New Issue
Block a user