forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjsonwebtoken.d.ts
130 lines (112 loc) · 5.51 KB
/
jsonwebtoken.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Type definitions for jsonwebtoken 7.1.6
// Project: https://github.com/auth0/node-jsonwebtoken
// Definitions by: Maxime LUCE <https://github.com/SomaticIT>, Daniel Heim <https://github.com/danielheim>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="../node/node.d.ts" />
declare module "jsonwebtoken" {
export class JsonWebTokenError extends Error {
inner: Error;
constructor(message: string, error?: Error);
}
export class TokenExpiredError extends JsonWebTokenError {
expiredAt: number;
constructor(message: string, expiredAt: number);
}
export class NotBeforeError extends JsonWebTokenError {
date: Date;
constructor(message: string, date: Date);
}
export interface SignOptions {
/**
* Signature algorithm. Could be one of these values :
* - HS256: HMAC using SHA-256 hash algorithm
* - HS384: HMAC using SHA-384 hash algorithm
* - HS512: HMAC using SHA-512 hash algorithm
* - RS256: RSASSA using SHA-256 hash algorithm
* - RS384: RSASSA using SHA-384 hash algorithm
* - RS512: RSASSA using SHA-512 hash algorithm
* - ES256: ECDSA using P-256 curve and SHA-256 hash algorithm
* - ES384: ECDSA using P-384 curve and SHA-384 hash algorithm
* - ES512: ECDSA using P-521 curve and SHA-512 hash algorithm
* - none: No digital signature or MAC value included
*/
algorithm?: string;
/** @member {string} - Lifetime for the token expressed in a string describing a time span [rauchg/ms](https://github.com/rauchg/ms.js). Eg: `60`, `"2 days"`, `"10h"`, `"7d"` */
expiresIn?: string | number;
notBefore?: string;
audience?: string;
subject?: string;
issuer?: string;
jwtid?: string;
noTimestamp?: boolean;
header?: Object;
encoding?: string;
}
export interface VerifyOptions {
algorithms?: string[];
audience?: string | string[];
clockTolerance?: number;
issuer?: string | string[];
ignoreExpiration?: boolean;
ignoreNotBefore?: boolean;
jwtId?: string;
subject?: string;
/**
*@deprecated
*@member {string} - Max age of token
*/
maxAge?: string;
}
export interface DecodeOptions {
complete?: boolean;
json?: boolean;
}
export interface VerifyCallback {
(err: JsonWebTokenError | TokenExpiredError | NotBeforeError, decoded: any): void;
}
export interface SignCallback {
(err: Error, encoded: string): void;
}
/**
* Synchronously sign the given payload into a JSON Web Token string
* @param {String|Object|Buffer} payload - Payload to sign, could be an literal, buffer or string
* @param {String|Buffer} secretOrPrivateKey - Either the secret for HMAC algorithms, or the PEM encoded private key for RSA and ECDSA.
* @param {SignOptions} [options] - Options for the signature
* @returns {String} The JSON Web Token string
*/
export function sign(payload: string | Buffer | Object, secretOrPrivateKey: string | Buffer, options?: SignOptions): string;
/**
* Sign the given payload into a JSON Web Token string
* @param {String|Object|Buffer} payload - Payload to sign, could be an literal, buffer or string
* @param {String|Buffer} secretOrPrivateKey - Either the secret for HMAC algorithms, or the PEM encoded private key for RSA and ECDSA.
* @param {SignOptions} [options] - Options for the signature
* @param {Function} callback - Callback to get the encoded token on
*/
export function sign(payload: string | Buffer | Object, secretOrPrivateKey: string | Buffer, callback: SignCallback): void;
export function sign(payload: string | Buffer | Object, secretOrPrivateKey: string | Buffer, options: SignOptions, callback: SignCallback): void;
/**
* Synchronously verify given token using a secret or a public key to get a decoded token
* @param {String} token - JWT string to verify
* @param {String|Buffer} secretOrPublicKey - Either the secret for HMAC algorithms, or the PEM encoded public key for RSA and ECDSA.
* @param {VerifyOptions} [options] - Options for the verification
* @returns The decoded token.
*/
function verify(token: string, secretOrPublicKey: string | Buffer): any;
function verify(token: string, secretOrPublicKey: string | Buffer, options?: VerifyOptions): any;
/**
* Asynchronously verify given token using a secret or a public key to get a decoded token
* @param {String} token - JWT string to verify
* @param {String|Buffer} secretOrPublicKey - Either the secret for HMAC algorithms, or the PEM encoded public key for RSA and ECDSA.
* @param {VerifyOptions} [options] - Options for the verification
* @param {Function} callback - Callback to get the decoded token on
*/
function verify(token: string, secretOrPublicKey: string | Buffer, callback?: VerifyCallback): void;
function verify(token: string, secretOrPublicKey: string | Buffer, options?: VerifyOptions, callback?: VerifyCallback): void;
/**
* Returns the decoded payload without verifying if the signature is valid.
* @param {String} token - JWT string to decode
* @param {DecodeOptions} [options] - Options for decoding
* @returns {Object} The decoded Token
*/
function decode(token: string, options?: DecodeOptions): any;
}