/
index.d.ts
63 lines (50 loc) · 2.02 KB
/
index.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
import { Context, Request } from 'egg';
import { AuthenticateOptions, Strategy, Authenticator } from 'passport';
interface IMountOptions extends AuthenticateOptions {
loginURL?: string;
callbackURL?: string;
}
interface EggPassport extends Authenticator {
authenticate<AuthenticateRet = any>(strategy: string | string[]): AuthenticateRet;
authenticate<AuthenticateRet = any>(strategy: string | string[], options: AuthenticateOptions): AuthenticateRet;
session<AuthenticateRet = any>(): AuthenticateRet;
mount(strategy: string, options?: IMountOptions): void;
doVerify<TUserPayload = any, TUser = any>(req: Request, user: TUserPayload, done: (err: any, user?: TUser) => void): void;
verify<TUser = any, TID = any>(fn: (ctx: Context, id: TID) => Promise<TUser>): void;
serializeUser<TUser = any, TID = any>(fn: (ctx: Context, user: TUser) => TID): void;
serializeUser<TID = any>(id: TID, req: Request, done: (err: any, id?: TID) => void): void;
deserializeUser<TUser = any, TID = any>(fn: (ctx: Context, id: TID) => void): void;
deserializeUser<TUser = any, TID = any>(fn: (ctx: Context, id: TID) => Promise<TUser>): void;
deserializeUser<TUser = any, TID = any>(ctx: Request, id: TID): void;
deserializeUser<TUser = any, TID = any>(ctx: Request, id: TID): Promise<TUser>;
}
declare module 'egg' {
// extend app
interface Application {
passport: EggPassport;
}
// extend context
interface Context {
user?: any;
login(user: any): Promise<void>;
login(user: any, options: any): Promise<void>;
logout(): void;
isAuthenticated(): boolean;
}
interface EggPassportCommonConfig {
key: string;
secret: string;
}
// extend config
interface EggAppConfig {
passportLocal?: {
usernameField?: string;
passwordField?: string;
},
passportWeibo?: EggPassportCommonConfig,
passportGithub?: EggPassportCommonConfig,
passportTwitter?: EggPassportCommonConfig,
passportTaobao?: EggPassportCommonConfig,
passportBitbucket?: EggPassportCommonConfig
}
}