This repository has been archived by the owner on Jan 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 145
/
index.d.ts
103 lines (88 loc) · 2.73 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
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
declare class ClientOAuth2 {
code: ClientOAuth2.CodeFlow;
token: ClientOAuth2.TokenFlow;
owner: ClientOAuth2.OwnerFlow;
credentials: ClientOAuth2.CredentialsFlow;
jwt: ClientOAuth2.JwtBearerFlow;
constructor(options: ClientOAuth2.Options, request?: ClientOAuth2.Request);
createToken(data: ClientOAuth2.Data): ClientOAuth2.Token;
createToken(accessToken: string, data: ClientOAuth2.Data): ClientOAuth2.Token;
createToken(accessToken: string, refreshToken: string, data: ClientOAuth2.Data): ClientOAuth2.Token;
createToken(accessToken: string, refreshToken: string, type: string, data: ClientOAuth2.Data): ClientOAuth2.Token;
}
declare namespace ClientOAuth2 {
export interface Data {
[key: string]: string
}
export interface Options {
clientId?: string
clientSecret?: string
accessTokenUri?: string
authorizationUri?: string
redirectUri?: string
scopes?: string[]
state?: string
body?: {
[key: string]: string | string[];
};
query?: {
[key: string]: string | string[];
};
headers?: {
[key: string]: string | string[];
};
}
export interface Request {
(method: string, url: string, body: string, headers: { [key: string]: string | string[] }): Promise<{ status: number, body: string }>;
}
export interface RequestObject {
url: string;
headers?: {
[key: string]: string | string[];
};
}
export interface UrlObject {
hash?: string | {
[key: string]: string | string[];
};
query?: string | {
[key: string]: string | string[];
}
pathname?: string;
}
export class Token {
client: ClientOAuth2;
data: Data;
tokenType: string;
accessToken: string;
refreshToken: string;
constructor(client: ClientOAuth2, data: Data);
expiresIn(duration: number | Date): Date;
sign<T extends RequestObject>(requestObj: T): T;
refresh(options?: Options): Promise<Token>;
expired(): boolean;
}
export class CodeFlow {
constructor(client: ClientOAuth2);
getUri(options?: Options): string;
getToken(uri: string | UrlObject, options?: Options): Promise<Token>;
}
export class TokenFlow {
constructor(client: ClientOAuth2);
getUri(options?: Options): string;
getToken(uri: string | UrlObject, options?: Options): Promise<Token>;
}
export class OwnerFlow {
constructor(client: ClientOAuth2);
getToken(username: string, password: string, options?: Options): Promise<Token>;
}
export class CredentialsFlow {
constructor(client: ClientOAuth2);
getToken(options?: Options): Promise<Token>;
}
export class JwtBearerFlow {
constructor(client: ClientOAuth2);
getToken(token: string, options?: Options): Promise<Token>;
}
}
export = ClientOAuth2;