UNPKG

2.55 kBTypeScriptView Raw
1// Type definitions for passport-jwt 3.0
2// Project: https://github.com/themikenicholson/passport-jwt
3// Definitions by: TANAKA Koichi <https://github.com/mugeso/>
4// Alex Young <https://github.com/alsiola/>
5// David Ng <https://github.com/davidNHK/>
6// Carlos Eduardo Scheffer <https://github.com/carlosscheffer/>
7// Byungjin Kim <https://github.com/jindev>
8// Svyatoslav Bychkov <https://github.com/stbychkov>
9// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
10// TypeScript Version: 2.3
11
12import { Strategy as PassportStrategy } from 'passport-strategy';
13import * as express from 'express';
14import { VerifyOptions } from 'jsonwebtoken';
15
16export declare class Strategy extends PassportStrategy {
17 constructor(opt: StrategyOptions, verify: VerifyCallback);
18 constructor(opt: StrategyOptions, verify: VerifyCallbackWithRequest);
19 name: string;
20}
21
22export interface StrategyOptions {
23 secretOrKey?: string | Buffer | undefined;
24 secretOrKeyProvider?: SecretOrKeyProvider | undefined;
25 jwtFromRequest: JwtFromRequestFunction;
26 issuer?: string | undefined;
27 audience?: string | undefined;
28 algorithms?: string[] | undefined;
29 ignoreExpiration?: boolean | undefined;
30 passReqToCallback?: boolean | undefined;
31 jsonWebTokenOptions?: VerifyOptions | undefined;
32}
33
34export interface VerifyCallback {
35 (payload: any, done: VerifiedCallback): void;
36}
37
38export interface VerifyCallbackWithRequest {
39 (req: express.Request, payload: any, done: VerifiedCallback): void;
40}
41
42export interface VerifiedCallback {
43 (error: any, user?: Express.User | false, info?: any): void;
44}
45
46export interface JwtFromRequestFunction {
47 (req: express.Request): string | null;
48}
49
50export interface SecretOrKeyProvider {
51 (request: express.Request, rawJwtToken: any, done: (err: any, secretOrKey?: string | Buffer) => void): void;
52}
53
54export declare namespace ExtractJwt {
55 export function fromHeader(header_name: string): JwtFromRequestFunction;
56 export function fromBodyField(field_name: string): JwtFromRequestFunction;
57 export function fromUrlQueryParameter(param_name: string): JwtFromRequestFunction;
58 export function fromAuthHeaderWithScheme(auth_scheme: string): JwtFromRequestFunction;
59 export function fromAuthHeader(): JwtFromRequestFunction;
60 export function fromExtractors(extractors: JwtFromRequestFunction[]): JwtFromRequestFunction;
61 export function fromAuthHeaderAsBearerToken(): JwtFromRequestFunction;
62}