File size: 909 Bytes
60faa09
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
/**
 * HuggingFace OAuth2 provider for NextAuth v4.
 * Scopes: openid profile email repo:write read
 */
export default function HuggingFaceProvider(options) {
  return {
    id: "huggingface",
    name: "Hugging Face",
    type: "oauth",
    version: "2.0",
    authorization: {
      url: "https://huggingface.co/oauth/authorize",
      params: {
        scope: "openid profile email repo:write read",
        response_type: "code",
      },
    },
    token: "https://huggingface.co/oauth/token",
    userinfo: "https://huggingface.co/oauth/userinfo",
    clientId: options.clientId,
    clientSecret: options.clientSecret,
    profile(profile) {
      return {
        id: profile.sub,
        name: profile.name || profile.preferred_username || "HF User",
        email: profile.email,
        image: profile.picture,
        hfUsername: profile.preferred_username || profile.name,
      };
    },
  };
}