@better-auth/core 1.5.0-beta.4 → 1.5.0-beta.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. package/.turbo/turbo-build.log +170 -37
  2. package/dist/api/index.d.mts +188 -1
  3. package/dist/api/index.mjs +2 -1
  4. package/dist/context/endpoint-context.d.mts +19 -0
  5. package/dist/context/endpoint-context.mjs +27 -0
  6. package/dist/context/index.d.mts +3 -52
  7. package/dist/context/index.mjs +22 -1
  8. package/dist/context/request-state.d.mts +27 -0
  9. package/dist/context/request-state.mjs +45 -0
  10. package/dist/context/transaction.d.mts +16 -0
  11. package/dist/context/transaction.mjs +48 -0
  12. package/dist/db/adapter/factory.d.mts +27 -0
  13. package/dist/db/adapter/factory.mjs +738 -0
  14. package/dist/db/adapter/get-default-field-name.d.mts +18 -0
  15. package/dist/db/adapter/get-default-field-name.mjs +38 -0
  16. package/dist/db/adapter/get-default-model-name.d.mts +12 -0
  17. package/dist/db/adapter/get-default-model-name.mjs +32 -0
  18. package/dist/db/adapter/get-field-attributes.d.mts +29 -0
  19. package/dist/db/adapter/get-field-attributes.mjs +39 -0
  20. package/dist/db/adapter/get-field-name.d.mts +18 -0
  21. package/dist/db/adapter/get-field-name.mjs +33 -0
  22. package/dist/db/adapter/get-id-field.d.mts +39 -0
  23. package/dist/db/adapter/get-id-field.mjs +67 -0
  24. package/dist/db/adapter/get-model-name.d.mts +12 -0
  25. package/dist/db/adapter/get-model-name.mjs +23 -0
  26. package/dist/db/adapter/index.d.mts +513 -1
  27. package/dist/db/adapter/index.mjs +8 -970
  28. package/dist/db/adapter/types.d.mts +139 -0
  29. package/dist/db/adapter/utils.d.mts +7 -0
  30. package/dist/db/adapter/utils.mjs +38 -0
  31. package/dist/db/get-tables.d.mts +8 -0
  32. package/dist/{get-tables-CMc_Emww.mjs → db/get-tables.mjs} +1 -1
  33. package/dist/db/index.d.mts +10 -2
  34. package/dist/db/index.mjs +7 -60
  35. package/dist/db/plugin.d.mts +12 -0
  36. package/dist/db/schema/account.d.mts +26 -0
  37. package/dist/db/schema/account.mjs +19 -0
  38. package/dist/db/schema/rate-limit.d.mts +14 -0
  39. package/dist/db/schema/rate-limit.mjs +11 -0
  40. package/dist/db/schema/session.d.mts +21 -0
  41. package/dist/db/schema/session.mjs +14 -0
  42. package/dist/db/schema/shared.d.mts +10 -0
  43. package/dist/db/schema/shared.mjs +11 -0
  44. package/dist/db/schema/user.d.mts +20 -0
  45. package/dist/db/schema/user.mjs +13 -0
  46. package/dist/db/schema/verification.d.mts +19 -0
  47. package/dist/db/schema/verification.mjs +12 -0
  48. package/dist/db/type.d.mts +143 -0
  49. package/dist/env/color-depth.d.mts +4 -0
  50. package/dist/env/color-depth.mjs +88 -0
  51. package/dist/env/env-impl.d.mts +32 -0
  52. package/dist/env/env-impl.mjs +82 -0
  53. package/dist/env/index.d.mts +4 -2
  54. package/dist/env/index.mjs +3 -1
  55. package/dist/{index-BRBu0-5h.d.mts → env/logger.d.mts} +1 -35
  56. package/dist/env/logger.mjs +81 -0
  57. package/dist/error/codes.d.mts +186 -0
  58. package/dist/{error-GNtLPYaS.mjs → error/codes.mjs} +2 -29
  59. package/dist/error/index.d.mts +1 -185
  60. package/dist/error/index.mjs +28 -3
  61. package/dist/index.d.mts +7 -1
  62. package/dist/oauth2/client-credentials-token.d.mts +36 -0
  63. package/dist/oauth2/client-credentials-token.mjs +54 -0
  64. package/dist/oauth2/create-authorization-url.d.mts +45 -0
  65. package/dist/oauth2/create-authorization-url.mjs +42 -0
  66. package/dist/oauth2/index.d.mts +8 -2
  67. package/dist/oauth2/index.mjs +6 -2
  68. package/dist/oauth2/oauth-provider.d.mts +194 -0
  69. package/dist/oauth2/refresh-access-token.d.mts +36 -0
  70. package/dist/oauth2/refresh-access-token.mjs +58 -0
  71. package/dist/oauth2/utils.d.mts +7 -0
  72. package/dist/oauth2/utils.mjs +27 -0
  73. package/dist/oauth2/validate-authorization-code.d.mts +55 -0
  74. package/dist/oauth2/validate-authorization-code.mjs +71 -0
  75. package/dist/oauth2/verify.d.mts +49 -0
  76. package/dist/oauth2/verify.mjs +95 -0
  77. package/dist/social-providers/apple.d.mts +119 -0
  78. package/dist/social-providers/apple.mjs +102 -0
  79. package/dist/social-providers/atlassian.d.mts +72 -0
  80. package/dist/social-providers/atlassian.mjs +83 -0
  81. package/dist/social-providers/cognito.d.mts +87 -0
  82. package/dist/social-providers/cognito.mjs +165 -0
  83. package/dist/social-providers/discord.d.mts +126 -0
  84. package/dist/social-providers/discord.mjs +64 -0
  85. package/dist/social-providers/dropbox.d.mts +71 -0
  86. package/dist/social-providers/dropbox.mjs +75 -0
  87. package/dist/social-providers/facebook.d.mts +81 -0
  88. package/dist/social-providers/facebook.mjs +120 -0
  89. package/dist/social-providers/figma.d.mts +63 -0
  90. package/dist/social-providers/figma.mjs +84 -0
  91. package/dist/social-providers/github.d.mts +104 -0
  92. package/dist/social-providers/github.mjs +80 -0
  93. package/dist/social-providers/gitlab.d.mts +125 -0
  94. package/dist/social-providers/gitlab.mjs +82 -0
  95. package/dist/social-providers/google.d.mts +99 -0
  96. package/dist/social-providers/google.mjs +108 -0
  97. package/dist/social-providers/huggingface.d.mts +85 -0
  98. package/dist/social-providers/huggingface.mjs +75 -0
  99. package/dist/social-providers/index.d.mts +1723 -1
  100. package/dist/social-providers/index.mjs +33 -2569
  101. package/dist/social-providers/kakao.d.mts +163 -0
  102. package/dist/social-providers/kakao.mjs +72 -0
  103. package/dist/social-providers/kick.d.mts +75 -0
  104. package/dist/social-providers/kick.mjs +71 -0
  105. package/dist/social-providers/line.d.mts +107 -0
  106. package/dist/social-providers/line.mjs +113 -0
  107. package/dist/social-providers/linear.d.mts +70 -0
  108. package/dist/social-providers/linear.mjs +88 -0
  109. package/dist/social-providers/linkedin.d.mts +69 -0
  110. package/dist/social-providers/linkedin.mjs +76 -0
  111. package/dist/social-providers/microsoft-entra-id.d.mts +174 -0
  112. package/dist/social-providers/microsoft-entra-id.mjs +106 -0
  113. package/dist/social-providers/naver.d.mts +104 -0
  114. package/dist/social-providers/naver.mjs +67 -0
  115. package/dist/social-providers/notion.d.mts +66 -0
  116. package/dist/social-providers/notion.mjs +75 -0
  117. package/dist/social-providers/paybin.d.mts +73 -0
  118. package/dist/social-providers/paybin.mjs +85 -0
  119. package/dist/social-providers/paypal.d.mts +131 -0
  120. package/dist/social-providers/paypal.mjs +144 -0
  121. package/dist/social-providers/polar.d.mts +76 -0
  122. package/dist/social-providers/polar.mjs +73 -0
  123. package/dist/social-providers/reddit.d.mts +64 -0
  124. package/dist/social-providers/reddit.mjs +83 -0
  125. package/dist/social-providers/roblox.d.mts +72 -0
  126. package/dist/social-providers/roblox.mjs +59 -0
  127. package/dist/social-providers/salesforce.d.mts +81 -0
  128. package/dist/social-providers/salesforce.mjs +91 -0
  129. package/dist/social-providers/slack.d.mts +85 -0
  130. package/dist/social-providers/slack.mjs +68 -0
  131. package/dist/social-providers/spotify.d.mts +65 -0
  132. package/dist/social-providers/spotify.mjs +71 -0
  133. package/dist/social-providers/tiktok.d.mts +171 -0
  134. package/dist/social-providers/tiktok.mjs +62 -0
  135. package/dist/social-providers/twitch.d.mts +81 -0
  136. package/dist/social-providers/twitch.mjs +78 -0
  137. package/dist/social-providers/twitter.d.mts +140 -0
  138. package/dist/social-providers/twitter.mjs +87 -0
  139. package/dist/social-providers/vercel.d.mts +64 -0
  140. package/dist/social-providers/vercel.mjs +61 -0
  141. package/dist/social-providers/vk.d.mts +72 -0
  142. package/dist/social-providers/vk.mjs +83 -0
  143. package/dist/social-providers/zoom.d.mts +173 -0
  144. package/dist/social-providers/zoom.mjs +72 -0
  145. package/dist/types/context.d.mts +246 -0
  146. package/dist/types/cookie.d.mts +23 -0
  147. package/dist/types/helper.d.mts +8 -0
  148. package/dist/types/index.d.mts +8 -0
  149. package/dist/types/init-options.d.mts +1266 -0
  150. package/dist/types/plugin-client.d.mts +110 -0
  151. package/dist/types/plugin.d.mts +124 -0
  152. package/dist/utils/deprecate.d.mts +10 -0
  153. package/dist/utils/deprecate.mjs +17 -0
  154. package/dist/utils/{index.d.mts → error-codes.d.mts} +1 -19
  155. package/dist/utils/error-codes.mjs +11 -0
  156. package/dist/utils/id.d.mts +4 -0
  157. package/dist/utils/id.mjs +9 -0
  158. package/dist/utils/json.d.mts +4 -0
  159. package/dist/utils/json.mjs +25 -0
  160. package/dist/utils/string.d.mts +4 -0
  161. package/dist/utils/string.mjs +7 -0
  162. package/package.json +9 -6
  163. package/src/db/adapter/get-id-field.ts +1 -1
  164. package/src/error/codes.ts +1 -1
  165. package/src/oauth2/create-authorization-url.ts +1 -1
  166. package/src/oauth2/oauth-provider.ts +6 -0
  167. package/tsdown.config.ts +3 -1
  168. package/dist/context-BBNwughv.mjs +0 -133
  169. package/dist/env-DbssmzoK.mjs +0 -245
  170. package/dist/index-B5x_W0dM.d.mts +0 -8054
  171. package/dist/oauth2-BjWM15hm.mjs +0 -326
  172. package/dist/utils/index.mjs +0 -4
  173. package/dist/utils-puAL36Bz.mjs +0 -63
  174. package/src/utils/index.ts +0 -5
@@ -0,0 +1,81 @@
1
+ import { OAuth2Tokens, ProviderOptions } from "../oauth2/oauth-provider.mjs";
2
+ import "../oauth2/index.mjs";
3
+
4
+ //#region src/social-providers/facebook.d.ts
5
+ interface FacebookProfile {
6
+ id: string;
7
+ name: string;
8
+ email: string;
9
+ email_verified: boolean;
10
+ picture: {
11
+ data: {
12
+ height: number;
13
+ is_silhouette: boolean;
14
+ url: string;
15
+ width: number;
16
+ };
17
+ };
18
+ }
19
+ interface FacebookOptions extends ProviderOptions<FacebookProfile> {
20
+ clientId: string;
21
+ /**
22
+ * Extend list of fields to retrieve from the Facebook user profile.
23
+ *
24
+ * @default ["id", "name", "email", "picture"]
25
+ */
26
+ fields?: string[] | undefined;
27
+ /**
28
+ * The config id to use when undergoing oauth
29
+ */
30
+ configId?: string | undefined;
31
+ }
32
+ declare const facebook: (options: FacebookOptions) => {
33
+ id: "facebook";
34
+ name: string;
35
+ createAuthorizationURL({
36
+ state,
37
+ scopes,
38
+ redirectURI,
39
+ loginHint
40
+ }: {
41
+ state: string;
42
+ codeVerifier: string;
43
+ scopes?: string[] | undefined;
44
+ redirectURI: string;
45
+ display?: string | undefined;
46
+ loginHint?: string | undefined;
47
+ }): Promise<URL>;
48
+ validateAuthorizationCode: ({
49
+ code,
50
+ redirectURI
51
+ }: {
52
+ code: string;
53
+ redirectURI: string;
54
+ codeVerifier?: string | undefined;
55
+ deviceId?: string | undefined;
56
+ }) => Promise<OAuth2Tokens>;
57
+ verifyIdToken(token: string, nonce: string | undefined): Promise<boolean>;
58
+ refreshAccessToken: (refreshToken: string) => Promise<OAuth2Tokens>;
59
+ getUserInfo(token: OAuth2Tokens & {
60
+ user?: {
61
+ name?: {
62
+ firstName?: string;
63
+ lastName?: string;
64
+ };
65
+ email?: string;
66
+ } | undefined;
67
+ }): Promise<{
68
+ user: {
69
+ id: string;
70
+ name?: string;
71
+ email?: string | null;
72
+ image?: string;
73
+ emailVerified: boolean;
74
+ [key: string]: any;
75
+ };
76
+ data: any;
77
+ } | null>;
78
+ options: FacebookOptions;
79
+ };
80
+ //#endregion
81
+ export { FacebookOptions, FacebookProfile, facebook };
@@ -0,0 +1,120 @@
1
+ import { createAuthorizationURL } from "../oauth2/create-authorization-url.mjs";
2
+ import { refreshAccessToken } from "../oauth2/refresh-access-token.mjs";
3
+ import { validateAuthorizationCode } from "../oauth2/validate-authorization-code.mjs";
4
+ import "../oauth2/index.mjs";
5
+ import { betterFetch } from "@better-fetch/fetch";
6
+ import { createRemoteJWKSet, decodeJwt, jwtVerify } from "jose";
7
+
8
+ //#region src/social-providers/facebook.ts
9
+ const facebook = (options) => {
10
+ return {
11
+ id: "facebook",
12
+ name: "Facebook",
13
+ async createAuthorizationURL({ state, scopes, redirectURI, loginHint }) {
14
+ const _scopes = options.disableDefaultScope ? [] : ["email", "public_profile"];
15
+ if (options.scope) _scopes.push(...options.scope);
16
+ if (scopes) _scopes.push(...scopes);
17
+ return await createAuthorizationURL({
18
+ id: "facebook",
19
+ options,
20
+ authorizationEndpoint: "https://www.facebook.com/v21.0/dialog/oauth",
21
+ scopes: _scopes,
22
+ state,
23
+ redirectURI,
24
+ loginHint,
25
+ additionalParams: options.configId ? { config_id: options.configId } : {}
26
+ });
27
+ },
28
+ validateAuthorizationCode: async ({ code, redirectURI }) => {
29
+ return validateAuthorizationCode({
30
+ code,
31
+ redirectURI,
32
+ options,
33
+ tokenEndpoint: "https://graph.facebook.com/oauth/access_token"
34
+ });
35
+ },
36
+ async verifyIdToken(token, nonce) {
37
+ if (options.disableIdTokenSignIn) return false;
38
+ if (options.verifyIdToken) return options.verifyIdToken(token, nonce);
39
+ if (token.split(".").length === 3) try {
40
+ const { payload: jwtClaims } = await jwtVerify(token, createRemoteJWKSet(new URL("https://limited.facebook.com/.well-known/oauth/openid/jwks/")), {
41
+ algorithms: ["RS256"],
42
+ audience: options.clientId,
43
+ issuer: "https://www.facebook.com"
44
+ });
45
+ if (nonce && jwtClaims.nonce !== nonce) return false;
46
+ return !!jwtClaims;
47
+ } catch {
48
+ return false;
49
+ }
50
+ return true;
51
+ },
52
+ refreshAccessToken: options.refreshAccessToken ? options.refreshAccessToken : async (refreshToken) => {
53
+ return refreshAccessToken({
54
+ refreshToken,
55
+ options: {
56
+ clientId: options.clientId,
57
+ clientKey: options.clientKey,
58
+ clientSecret: options.clientSecret
59
+ },
60
+ tokenEndpoint: "https://graph.facebook.com/v18.0/oauth/access_token"
61
+ });
62
+ },
63
+ async getUserInfo(token) {
64
+ if (options.getUserInfo) return options.getUserInfo(token);
65
+ if (token.idToken && token.idToken.split(".").length === 3) {
66
+ const profile$1 = decodeJwt(token.idToken);
67
+ const user = {
68
+ id: profile$1.sub,
69
+ name: profile$1.name,
70
+ email: profile$1.email,
71
+ picture: { data: {
72
+ url: profile$1.picture,
73
+ height: 100,
74
+ width: 100,
75
+ is_silhouette: false
76
+ } }
77
+ };
78
+ const userMap$1 = await options.mapProfileToUser?.({
79
+ ...user,
80
+ email_verified: false
81
+ });
82
+ return {
83
+ user: {
84
+ ...user,
85
+ emailVerified: false,
86
+ ...userMap$1
87
+ },
88
+ data: profile$1
89
+ };
90
+ }
91
+ const { data: profile, error } = await betterFetch("https://graph.facebook.com/me?fields=" + [
92
+ "id",
93
+ "name",
94
+ "email",
95
+ "picture",
96
+ ...options?.fields || []
97
+ ].join(","), { auth: {
98
+ type: "Bearer",
99
+ token: token.accessToken
100
+ } });
101
+ if (error) return null;
102
+ const userMap = await options.mapProfileToUser?.(profile);
103
+ return {
104
+ user: {
105
+ id: profile.id,
106
+ name: profile.name,
107
+ email: profile.email,
108
+ image: profile.picture.data.url,
109
+ emailVerified: profile.email_verified,
110
+ ...userMap
111
+ },
112
+ data: profile
113
+ };
114
+ },
115
+ options
116
+ };
117
+ };
118
+
119
+ //#endregion
120
+ export { facebook };
@@ -0,0 +1,63 @@
1
+ import { OAuth2Tokens, ProviderOptions } from "../oauth2/oauth-provider.mjs";
2
+ import "../oauth2/index.mjs";
3
+
4
+ //#region src/social-providers/figma.d.ts
5
+ interface FigmaProfile {
6
+ id: string;
7
+ email: string;
8
+ handle: string;
9
+ img_url: string;
10
+ }
11
+ interface FigmaOptions extends ProviderOptions<FigmaProfile> {
12
+ clientId: string;
13
+ }
14
+ declare const figma: (options: FigmaOptions) => {
15
+ id: "figma";
16
+ name: string;
17
+ createAuthorizationURL({
18
+ state,
19
+ scopes,
20
+ codeVerifier,
21
+ redirectURI
22
+ }: {
23
+ state: string;
24
+ codeVerifier: string;
25
+ scopes?: string[] | undefined;
26
+ redirectURI: string;
27
+ display?: string | undefined;
28
+ loginHint?: string | undefined;
29
+ }): Promise<URL>;
30
+ validateAuthorizationCode: ({
31
+ code,
32
+ codeVerifier,
33
+ redirectURI
34
+ }: {
35
+ code: string;
36
+ redirectURI: string;
37
+ codeVerifier?: string | undefined;
38
+ deviceId?: string | undefined;
39
+ }) => Promise<OAuth2Tokens>;
40
+ refreshAccessToken: (refreshToken: string) => Promise<OAuth2Tokens>;
41
+ getUserInfo(token: OAuth2Tokens & {
42
+ user?: {
43
+ name?: {
44
+ firstName?: string;
45
+ lastName?: string;
46
+ };
47
+ email?: string;
48
+ } | undefined;
49
+ }): Promise<{
50
+ user: {
51
+ id: string;
52
+ name?: string;
53
+ email?: string | null;
54
+ image?: string;
55
+ emailVerified: boolean;
56
+ [key: string]: any;
57
+ };
58
+ data: any;
59
+ } | null>;
60
+ options: FigmaOptions;
61
+ };
62
+ //#endregion
63
+ export { FigmaOptions, FigmaProfile, figma };
@@ -0,0 +1,84 @@
1
+ import { logger } from "../env/logger.mjs";
2
+ import "../env/index.mjs";
3
+ import { BetterAuthError } from "../error/index.mjs";
4
+ import { createAuthorizationURL } from "../oauth2/create-authorization-url.mjs";
5
+ import { refreshAccessToken } from "../oauth2/refresh-access-token.mjs";
6
+ import { validateAuthorizationCode } from "../oauth2/validate-authorization-code.mjs";
7
+ import "../oauth2/index.mjs";
8
+ import { betterFetch } from "@better-fetch/fetch";
9
+
10
+ //#region src/social-providers/figma.ts
11
+ const figma = (options) => {
12
+ return {
13
+ id: "figma",
14
+ name: "Figma",
15
+ async createAuthorizationURL({ state, scopes, codeVerifier, redirectURI }) {
16
+ if (!options.clientId || !options.clientSecret) {
17
+ logger.error("Client Id and Client Secret are required for Figma. Make sure to provide them in the options.");
18
+ throw new BetterAuthError("CLIENT_ID_AND_SECRET_REQUIRED");
19
+ }
20
+ if (!codeVerifier) throw new BetterAuthError("codeVerifier is required for Figma");
21
+ const _scopes = options.disableDefaultScope ? [] : ["file_read"];
22
+ if (options.scope) _scopes.push(...options.scope);
23
+ if (scopes) _scopes.push(...scopes);
24
+ return await createAuthorizationURL({
25
+ id: "figma",
26
+ options,
27
+ authorizationEndpoint: "https://www.figma.com/oauth",
28
+ scopes: _scopes,
29
+ state,
30
+ codeVerifier,
31
+ redirectURI
32
+ });
33
+ },
34
+ validateAuthorizationCode: async ({ code, codeVerifier, redirectURI }) => {
35
+ return validateAuthorizationCode({
36
+ code,
37
+ codeVerifier,
38
+ redirectURI,
39
+ options,
40
+ tokenEndpoint: "https://www.figma.com/api/oauth/token"
41
+ });
42
+ },
43
+ refreshAccessToken: options.refreshAccessToken ? options.refreshAccessToken : async (refreshToken) => {
44
+ return refreshAccessToken({
45
+ refreshToken,
46
+ options: {
47
+ clientId: options.clientId,
48
+ clientKey: options.clientKey,
49
+ clientSecret: options.clientSecret
50
+ },
51
+ tokenEndpoint: "https://www.figma.com/api/oauth/token"
52
+ });
53
+ },
54
+ async getUserInfo(token) {
55
+ if (options.getUserInfo) return options.getUserInfo(token);
56
+ try {
57
+ const { data: profile } = await betterFetch("https://api.figma.com/v1/me", { headers: { Authorization: `Bearer ${token.accessToken}` } });
58
+ if (!profile) {
59
+ logger.error("Failed to fetch user from Figma");
60
+ return null;
61
+ }
62
+ const userMap = await options.mapProfileToUser?.(profile);
63
+ return {
64
+ user: {
65
+ id: profile.id,
66
+ name: profile.handle,
67
+ email: profile.email,
68
+ image: profile.img_url,
69
+ emailVerified: false,
70
+ ...userMap
71
+ },
72
+ data: profile
73
+ };
74
+ } catch (error) {
75
+ logger.error("Failed to fetch user info from Figma:", error);
76
+ return null;
77
+ }
78
+ },
79
+ options
80
+ };
81
+ };
82
+
83
+ //#endregion
84
+ export { figma };
@@ -0,0 +1,104 @@
1
+ import { OAuth2Tokens, ProviderOptions } from "../oauth2/oauth-provider.mjs";
2
+ import "../oauth2/index.mjs";
3
+
4
+ //#region src/social-providers/github.d.ts
5
+ interface GithubProfile {
6
+ login: string;
7
+ id: string;
8
+ node_id: string;
9
+ avatar_url: string;
10
+ gravatar_id: string;
11
+ url: string;
12
+ html_url: string;
13
+ followers_url: string;
14
+ following_url: string;
15
+ gists_url: string;
16
+ starred_url: string;
17
+ subscriptions_url: string;
18
+ organizations_url: string;
19
+ repos_url: string;
20
+ events_url: string;
21
+ received_events_url: string;
22
+ type: string;
23
+ site_admin: boolean;
24
+ name: string;
25
+ company: string;
26
+ blog: string;
27
+ location: string;
28
+ email: string;
29
+ hireable: boolean;
30
+ bio: string;
31
+ twitter_username: string;
32
+ public_repos: string;
33
+ public_gists: string;
34
+ followers: string;
35
+ following: string;
36
+ created_at: string;
37
+ updated_at: string;
38
+ private_gists: string;
39
+ total_private_repos: string;
40
+ owned_private_repos: string;
41
+ disk_usage: string;
42
+ collaborators: string;
43
+ two_factor_authentication: boolean;
44
+ plan: {
45
+ name: string;
46
+ space: string;
47
+ private_repos: string;
48
+ collaborators: string;
49
+ };
50
+ }
51
+ interface GithubOptions extends ProviderOptions<GithubProfile> {
52
+ clientId: string;
53
+ }
54
+ declare const github: (options: GithubOptions) => {
55
+ id: "github";
56
+ name: string;
57
+ createAuthorizationURL({
58
+ state,
59
+ scopes,
60
+ loginHint,
61
+ codeVerifier,
62
+ redirectURI
63
+ }: {
64
+ state: string;
65
+ codeVerifier: string;
66
+ scopes?: string[] | undefined;
67
+ redirectURI: string;
68
+ display?: string | undefined;
69
+ loginHint?: string | undefined;
70
+ }): Promise<URL>;
71
+ validateAuthorizationCode: ({
72
+ code,
73
+ codeVerifier,
74
+ redirectURI
75
+ }: {
76
+ code: string;
77
+ redirectURI: string;
78
+ codeVerifier?: string | undefined;
79
+ deviceId?: string | undefined;
80
+ }) => Promise<OAuth2Tokens>;
81
+ refreshAccessToken: (refreshToken: string) => Promise<OAuth2Tokens>;
82
+ getUserInfo(token: OAuth2Tokens & {
83
+ user?: {
84
+ name?: {
85
+ firstName?: string;
86
+ lastName?: string;
87
+ };
88
+ email?: string;
89
+ } | undefined;
90
+ }): Promise<{
91
+ user: {
92
+ id: string;
93
+ name?: string;
94
+ email?: string | null;
95
+ image?: string;
96
+ emailVerified: boolean;
97
+ [key: string]: any;
98
+ };
99
+ data: any;
100
+ } | null>;
101
+ options: GithubOptions;
102
+ };
103
+ //#endregion
104
+ export { GithubOptions, GithubProfile, github };
@@ -0,0 +1,80 @@
1
+ import { createAuthorizationURL } from "../oauth2/create-authorization-url.mjs";
2
+ import { refreshAccessToken } from "../oauth2/refresh-access-token.mjs";
3
+ import { validateAuthorizationCode } from "../oauth2/validate-authorization-code.mjs";
4
+ import "../oauth2/index.mjs";
5
+ import { betterFetch } from "@better-fetch/fetch";
6
+
7
+ //#region src/social-providers/github.ts
8
+ const github = (options) => {
9
+ const tokenEndpoint = "https://github.com/login/oauth/access_token";
10
+ return {
11
+ id: "github",
12
+ name: "GitHub",
13
+ createAuthorizationURL({ state, scopes, loginHint, codeVerifier, redirectURI }) {
14
+ const _scopes = options.disableDefaultScope ? [] : ["read:user", "user:email"];
15
+ if (options.scope) _scopes.push(...options.scope);
16
+ if (scopes) _scopes.push(...scopes);
17
+ return createAuthorizationURL({
18
+ id: "github",
19
+ options,
20
+ authorizationEndpoint: "https://github.com/login/oauth/authorize",
21
+ scopes: _scopes,
22
+ state,
23
+ codeVerifier,
24
+ redirectURI,
25
+ loginHint,
26
+ prompt: options.prompt
27
+ });
28
+ },
29
+ validateAuthorizationCode: async ({ code, codeVerifier, redirectURI }) => {
30
+ return validateAuthorizationCode({
31
+ code,
32
+ codeVerifier,
33
+ redirectURI,
34
+ options,
35
+ tokenEndpoint
36
+ });
37
+ },
38
+ refreshAccessToken: options.refreshAccessToken ? options.refreshAccessToken : async (refreshToken) => {
39
+ return refreshAccessToken({
40
+ refreshToken,
41
+ options: {
42
+ clientId: options.clientId,
43
+ clientKey: options.clientKey,
44
+ clientSecret: options.clientSecret
45
+ },
46
+ tokenEndpoint: "https://github.com/login/oauth/access_token"
47
+ });
48
+ },
49
+ async getUserInfo(token) {
50
+ if (options.getUserInfo) return options.getUserInfo(token);
51
+ const { data: profile, error } = await betterFetch("https://api.github.com/user", { headers: {
52
+ "User-Agent": "better-auth",
53
+ authorization: `Bearer ${token.accessToken}`
54
+ } });
55
+ if (error) return null;
56
+ const { data: emails } = await betterFetch("https://api.github.com/user/emails", { headers: {
57
+ Authorization: `Bearer ${token.accessToken}`,
58
+ "User-Agent": "better-auth"
59
+ } });
60
+ if (!profile.email && emails) profile.email = (emails.find((e) => e.primary) ?? emails[0])?.email;
61
+ const emailVerified = emails?.find((e) => e.email === profile.email)?.verified ?? false;
62
+ const userMap = await options.mapProfileToUser?.(profile);
63
+ return {
64
+ user: {
65
+ id: profile.id,
66
+ name: profile.name || profile.login,
67
+ email: profile.email,
68
+ image: profile.avatar_url,
69
+ emailVerified,
70
+ ...userMap
71
+ },
72
+ data: profile
73
+ };
74
+ },
75
+ options
76
+ };
77
+ };
78
+
79
+ //#endregion
80
+ export { github };
@@ -0,0 +1,125 @@
1
+ import { OAuth2Tokens, ProviderOptions } from "../oauth2/oauth-provider.mjs";
2
+ import "../oauth2/index.mjs";
3
+
4
+ //#region src/social-providers/gitlab.d.ts
5
+ interface GitlabProfile extends Record<string, any> {
6
+ id: number;
7
+ username: string;
8
+ email: string;
9
+ name: string;
10
+ state: string;
11
+ avatar_url: string;
12
+ web_url: string;
13
+ created_at: string;
14
+ bio: string;
15
+ location?: string | undefined;
16
+ public_email: string;
17
+ skype: string;
18
+ linkedin: string;
19
+ twitter: string;
20
+ website_url: string;
21
+ organization: string;
22
+ job_title: string;
23
+ pronouns: string;
24
+ bot: boolean;
25
+ work_information?: string | undefined;
26
+ followers: number;
27
+ following: number;
28
+ local_time: string;
29
+ last_sign_in_at: string;
30
+ confirmed_at: string;
31
+ theme_id: number;
32
+ last_activity_on: string;
33
+ color_scheme_id: number;
34
+ projects_limit: number;
35
+ current_sign_in_at: string;
36
+ identities: Array<{
37
+ provider: string;
38
+ extern_uid: string;
39
+ }>;
40
+ can_create_group: boolean;
41
+ can_create_project: boolean;
42
+ two_factor_enabled: boolean;
43
+ external: boolean;
44
+ private_profile: boolean;
45
+ commit_email: string;
46
+ shared_runners_minutes_limit: number;
47
+ extra_shared_runners_minutes_limit: number;
48
+ email_verified?: boolean | undefined;
49
+ }
50
+ interface GitlabOptions extends ProviderOptions<GitlabProfile> {
51
+ clientId: string;
52
+ issuer?: string | undefined;
53
+ }
54
+ declare const gitlab: (options: GitlabOptions) => {
55
+ id: "gitlab";
56
+ name: string;
57
+ createAuthorizationURL: ({
58
+ state,
59
+ scopes,
60
+ codeVerifier,
61
+ loginHint,
62
+ redirectURI
63
+ }: {
64
+ state: string;
65
+ codeVerifier: string;
66
+ scopes?: string[] | undefined;
67
+ redirectURI: string;
68
+ display?: string | undefined;
69
+ loginHint?: string | undefined;
70
+ }) => Promise<URL>;
71
+ validateAuthorizationCode: ({
72
+ code,
73
+ redirectURI,
74
+ codeVerifier
75
+ }: {
76
+ code: string;
77
+ redirectURI: string;
78
+ codeVerifier?: string | undefined;
79
+ deviceId?: string | undefined;
80
+ }) => Promise<OAuth2Tokens>;
81
+ refreshAccessToken: (refreshToken: string) => Promise<OAuth2Tokens>;
82
+ getUserInfo(token: OAuth2Tokens & {
83
+ user?: {
84
+ name?: {
85
+ firstName?: string;
86
+ lastName?: string;
87
+ };
88
+ email?: string;
89
+ } | undefined;
90
+ }): Promise<{
91
+ user: {
92
+ id: string;
93
+ name?: string;
94
+ email?: string | null;
95
+ image?: string;
96
+ emailVerified: boolean;
97
+ [key: string]: any;
98
+ };
99
+ data: any;
100
+ } | {
101
+ user: {
102
+ id: number;
103
+ name: string;
104
+ email: string;
105
+ image: string;
106
+ emailVerified: boolean;
107
+ } | {
108
+ id: string | number;
109
+ name: string;
110
+ email: string | null;
111
+ image: string;
112
+ emailVerified: boolean;
113
+ } | {
114
+ id: string | number;
115
+ name: string;
116
+ email: string | null;
117
+ image: string;
118
+ emailVerified: boolean;
119
+ };
120
+ data: GitlabProfile;
121
+ } | null>;
122
+ options: GitlabOptions;
123
+ };
124
+ //#endregion
125
+ export { GitlabOptions, GitlabProfile, gitlab };