-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
62 lines (56 loc) · 1.29 KB
/
index.ts
File metadata and controls
62 lines (56 loc) · 1.29 KB
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
import {
type AccessTokenFailure,
type AccessTokenResponse,
type AccessTokenSuccess,
type ClientCredentials,
getAccessToken,
} from "./get-access-token";
import {
getUser,
type UserFailure,
type UserResponse,
type UserSuccess,
} from "./get-user";
import { type CookieSettings, redirectToOAuth } from "./redirect-to-oauth";
export type {
ClientCredentials,
CookieSettings,
AccessTokenResponse,
AccessTokenSuccess,
AccessTokenFailure,
UserResponse,
UserSuccess,
UserFailure,
};
export interface LoginWithGitHubConfig {
client: ClientCredentials;
cookie: CookieSettings;
newSecret(): string;
userAgent: string;
}
export class LoginWithGitHub {
constructor(public readonly config: LoginWithGitHubConfig) {}
redirectToOAuth(): Promise<{
status: number;
headers: Array<[string, string]>;
}> {
return redirectToOAuth({
clientId: this.config.client.id,
cookieSettings: this.config.cookie,
newSecret: this.config.newSecret,
});
}
getAccessToken(x: { code: string }): Promise<AccessTokenResponse> {
return getAccessToken({
client: this.config.client,
code: x.code,
userAgent: this.config.userAgent,
});
}
getUser(x: { accessToken: string }): Promise<UserResponse> {
return getUser({
accessToken: x.accessToken,
userAgent: this.config.userAgent,
});
}
}