/
facebook.ts
46 lines (43 loc) · 1.24 KB
/
facebook.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
import type { OAuthConfig, OAuthUserConfig } from "."
interface FacebookPictureData {
url: string
}
interface FacebookPicture {
data: FacebookPictureData
}
export interface FacebookProfile extends Record<string, any> {
id: string
picture: FacebookPicture
}
export default function Facebook<P extends FacebookProfile>(
options: OAuthUserConfig<P>
): OAuthConfig<P> {
return {
id: "facebook",
name: "Facebook",
type: "oauth",
authorization: "https://www.facebook.com/v11.0/dialog/oauth?scope=email",
token: "https://graph.facebook.com/oauth/access_token",
userinfo: {
url: "https://graph.facebook.com/me",
// https://developers.facebook.com/docs/graph-api/reference/user/#fields
params: { fields: "id,name,email,picture" },
async request({ tokens, client, provider }) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return await client.userinfo(tokens.access_token!, {
// @ts-expect-error
params: provider.userinfo?.params,
})
},
},
profile(profile: P) {
return {
id: profile.id,
name: profile.name,
email: profile.email,
image: profile.picture.data.url,
}
},
options,
}
}