@better-auth/core 1.4.12-beta.2 → 1.4.13

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 (185) hide show
  1. package/.turbo/turbo-build.log +172 -35
  2. package/dist/api/index.d.mts +178 -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 +31 -0
  6. package/dist/context/global.d.mts +7 -0
  7. package/dist/context/global.mjs +37 -0
  8. package/dist/context/index.d.mts +5 -53
  9. package/dist/context/index.mjs +5 -2
  10. package/dist/context/request-state.d.mts +27 -0
  11. package/dist/context/request-state.mjs +49 -0
  12. package/dist/context/transaction.d.mts +16 -0
  13. package/dist/context/transaction.mjs +52 -0
  14. package/dist/db/adapter/factory.d.mts +27 -0
  15. package/dist/db/adapter/factory.mjs +738 -0
  16. package/dist/db/adapter/get-default-field-name.d.mts +18 -0
  17. package/dist/db/adapter/get-default-field-name.mjs +38 -0
  18. package/dist/db/adapter/get-default-model-name.d.mts +12 -0
  19. package/dist/db/adapter/get-default-model-name.mjs +32 -0
  20. package/dist/db/adapter/get-field-attributes.d.mts +29 -0
  21. package/dist/db/adapter/get-field-attributes.mjs +39 -0
  22. package/dist/db/adapter/get-field-name.d.mts +18 -0
  23. package/dist/db/adapter/get-field-name.mjs +33 -0
  24. package/dist/db/adapter/get-id-field.d.mts +39 -0
  25. package/dist/db/adapter/get-id-field.mjs +68 -0
  26. package/dist/db/adapter/get-model-name.d.mts +12 -0
  27. package/dist/db/adapter/get-model-name.mjs +23 -0
  28. package/dist/db/adapter/index.d.mts +513 -1
  29. package/dist/db/adapter/index.mjs +8 -970
  30. package/dist/db/adapter/types.d.mts +139 -0
  31. package/dist/db/adapter/utils.d.mts +7 -0
  32. package/dist/db/adapter/utils.mjs +38 -0
  33. package/dist/db/get-tables.d.mts +8 -0
  34. package/dist/{get-tables-CMc_Emww.mjs → db/get-tables.mjs} +1 -1
  35. package/dist/db/index.d.mts +10 -2
  36. package/dist/db/index.mjs +7 -60
  37. package/dist/db/plugin.d.mts +12 -0
  38. package/dist/db/schema/account.d.mts +26 -0
  39. package/dist/db/schema/account.mjs +19 -0
  40. package/dist/db/schema/rate-limit.d.mts +14 -0
  41. package/dist/db/schema/rate-limit.mjs +11 -0
  42. package/dist/db/schema/session.d.mts +21 -0
  43. package/dist/db/schema/session.mjs +14 -0
  44. package/dist/db/schema/shared.d.mts +10 -0
  45. package/dist/db/schema/shared.mjs +11 -0
  46. package/dist/db/schema/user.d.mts +20 -0
  47. package/dist/db/schema/user.mjs +13 -0
  48. package/dist/db/schema/verification.d.mts +19 -0
  49. package/dist/db/schema/verification.mjs +12 -0
  50. package/dist/db/type.d.mts +143 -0
  51. package/dist/env/color-depth.d.mts +4 -0
  52. package/dist/env/color-depth.mjs +88 -0
  53. package/dist/env/env-impl.d.mts +32 -0
  54. package/dist/env/env-impl.mjs +82 -0
  55. package/dist/env/index.d.mts +4 -2
  56. package/dist/env/index.mjs +3 -1
  57. package/dist/{index-BRBu0-5h.d.mts → env/logger.d.mts} +1 -35
  58. package/dist/env/logger.mjs +81 -0
  59. package/dist/error/codes.d.mts +48 -0
  60. package/dist/{error-DP1xOn7P.mjs → error/codes.mjs} +3 -14
  61. package/dist/error/index.d.mts +5 -48
  62. package/dist/error/index.mjs +12 -3
  63. package/dist/index.d.mts +8 -2
  64. package/dist/oauth2/client-credentials-token.d.mts +36 -0
  65. package/dist/oauth2/client-credentials-token.mjs +54 -0
  66. package/dist/oauth2/create-authorization-url.d.mts +45 -0
  67. package/dist/oauth2/create-authorization-url.mjs +42 -0
  68. package/dist/oauth2/index.d.mts +8 -2
  69. package/dist/oauth2/index.mjs +6 -2
  70. package/dist/oauth2/oauth-provider.d.mts +194 -0
  71. package/dist/oauth2/refresh-access-token.d.mts +36 -0
  72. package/dist/oauth2/refresh-access-token.mjs +58 -0
  73. package/dist/oauth2/utils.d.mts +7 -0
  74. package/dist/oauth2/utils.mjs +27 -0
  75. package/dist/oauth2/validate-authorization-code.d.mts +55 -0
  76. package/dist/oauth2/validate-authorization-code.mjs +71 -0
  77. package/dist/oauth2/verify.d.mts +49 -0
  78. package/dist/oauth2/verify.mjs +95 -0
  79. package/dist/social-providers/apple.d.mts +119 -0
  80. package/dist/social-providers/apple.mjs +102 -0
  81. package/dist/social-providers/atlassian.d.mts +72 -0
  82. package/dist/social-providers/atlassian.mjs +83 -0
  83. package/dist/social-providers/cognito.d.mts +87 -0
  84. package/dist/social-providers/cognito.mjs +166 -0
  85. package/dist/social-providers/discord.d.mts +126 -0
  86. package/dist/social-providers/discord.mjs +64 -0
  87. package/dist/social-providers/dropbox.d.mts +71 -0
  88. package/dist/social-providers/dropbox.mjs +75 -0
  89. package/dist/social-providers/facebook.d.mts +81 -0
  90. package/dist/social-providers/facebook.mjs +120 -0
  91. package/dist/social-providers/figma.d.mts +63 -0
  92. package/dist/social-providers/figma.mjs +84 -0
  93. package/dist/social-providers/github.d.mts +104 -0
  94. package/dist/social-providers/github.mjs +80 -0
  95. package/dist/social-providers/gitlab.d.mts +125 -0
  96. package/dist/social-providers/gitlab.mjs +82 -0
  97. package/dist/social-providers/google.d.mts +99 -0
  98. package/dist/social-providers/google.mjs +109 -0
  99. package/dist/social-providers/huggingface.d.mts +85 -0
  100. package/dist/social-providers/huggingface.mjs +75 -0
  101. package/dist/social-providers/index.d.mts +1723 -1
  102. package/dist/social-providers/index.mjs +33 -2570
  103. package/dist/social-providers/kakao.d.mts +163 -0
  104. package/dist/social-providers/kakao.mjs +72 -0
  105. package/dist/social-providers/kick.d.mts +75 -0
  106. package/dist/social-providers/kick.mjs +71 -0
  107. package/dist/social-providers/line.d.mts +107 -0
  108. package/dist/social-providers/line.mjs +113 -0
  109. package/dist/social-providers/linear.d.mts +70 -0
  110. package/dist/social-providers/linear.mjs +88 -0
  111. package/dist/social-providers/linkedin.d.mts +69 -0
  112. package/dist/social-providers/linkedin.mjs +76 -0
  113. package/dist/social-providers/microsoft-entra-id.d.mts +174 -0
  114. package/dist/social-providers/microsoft-entra-id.mjs +106 -0
  115. package/dist/social-providers/naver.d.mts +104 -0
  116. package/dist/social-providers/naver.mjs +67 -0
  117. package/dist/social-providers/notion.d.mts +66 -0
  118. package/dist/social-providers/notion.mjs +75 -0
  119. package/dist/social-providers/paybin.d.mts +73 -0
  120. package/dist/social-providers/paybin.mjs +85 -0
  121. package/dist/social-providers/paypal.d.mts +131 -0
  122. package/dist/social-providers/paypal.mjs +144 -0
  123. package/dist/social-providers/polar.d.mts +76 -0
  124. package/dist/social-providers/polar.mjs +73 -0
  125. package/dist/social-providers/reddit.d.mts +64 -0
  126. package/dist/social-providers/reddit.mjs +83 -0
  127. package/dist/social-providers/roblox.d.mts +72 -0
  128. package/dist/social-providers/roblox.mjs +59 -0
  129. package/dist/social-providers/salesforce.d.mts +81 -0
  130. package/dist/social-providers/salesforce.mjs +91 -0
  131. package/dist/social-providers/slack.d.mts +85 -0
  132. package/dist/social-providers/slack.mjs +68 -0
  133. package/dist/social-providers/spotify.d.mts +65 -0
  134. package/dist/social-providers/spotify.mjs +71 -0
  135. package/dist/social-providers/tiktok.d.mts +171 -0
  136. package/dist/social-providers/tiktok.mjs +62 -0
  137. package/dist/social-providers/twitch.d.mts +81 -0
  138. package/dist/social-providers/twitch.mjs +78 -0
  139. package/dist/social-providers/twitter.d.mts +140 -0
  140. package/dist/social-providers/twitter.mjs +87 -0
  141. package/dist/social-providers/vercel.d.mts +64 -0
  142. package/dist/social-providers/vercel.mjs +61 -0
  143. package/dist/social-providers/vk.d.mts +72 -0
  144. package/dist/social-providers/vk.mjs +83 -0
  145. package/dist/social-providers/zoom.d.mts +173 -0
  146. package/dist/social-providers/zoom.mjs +72 -0
  147. package/dist/types/context.d.mts +215 -0
  148. package/dist/types/cookie.d.mts +15 -0
  149. package/dist/types/helper.d.mts +8 -0
  150. package/dist/types/index.d.mts +8 -0
  151. package/dist/types/init-options.d.mts +1266 -0
  152. package/dist/types/plugin-client.d.mts +103 -0
  153. package/dist/types/plugin.d.mts +121 -0
  154. package/dist/utils/deprecate.d.mts +10 -0
  155. package/dist/utils/deprecate.mjs +17 -0
  156. package/dist/utils/error-codes.d.mts +9 -0
  157. package/dist/utils/error-codes.mjs +7 -0
  158. package/dist/utils/id.d.mts +4 -0
  159. package/dist/utils/id.mjs +9 -0
  160. package/dist/utils/index.d.mts +5 -26
  161. package/dist/utils/index.mjs +5 -2
  162. package/dist/utils/json.d.mts +4 -0
  163. package/dist/utils/json.mjs +25 -0
  164. package/dist/utils/string.d.mts +4 -0
  165. package/dist/utils/string.mjs +7 -0
  166. package/package.json +1 -1
  167. package/src/context/endpoint-context.ts +7 -15
  168. package/src/context/global.ts +57 -0
  169. package/src/context/index.ts +1 -0
  170. package/src/context/request-state.ts +7 -12
  171. package/src/context/transaction.ts +7 -16
  172. package/src/db/adapter/factory.ts +13 -13
  173. package/src/db/adapter/get-default-model-name.ts +1 -1
  174. package/src/db/adapter/get-id-field.ts +2 -2
  175. package/src/error/index.ts +2 -3
  176. package/src/social-providers/gitlab.ts +1 -1
  177. package/src/types/context.ts +137 -131
  178. package/src/types/cookie.ts +6 -4
  179. package/src/types/index.ts +2 -1
  180. package/tsdown.config.ts +9 -0
  181. package/dist/context-BGZ8V6DD.mjs +0 -126
  182. package/dist/env-DbssmzoK.mjs +0 -245
  183. package/dist/index-zgYuzZ7O.d.mts +0 -8020
  184. package/dist/oauth2-COJkghlT.mjs +0 -326
  185. package/dist/utils-U2L7n92V.mjs +0 -59
@@ -0,0 +1,88 @@
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/linear.ts
8
+ const linear = (options) => {
9
+ const tokenEndpoint = "https://api.linear.app/oauth/token";
10
+ return {
11
+ id: "linear",
12
+ name: "Linear",
13
+ createAuthorizationURL({ state, scopes, loginHint, redirectURI }) {
14
+ const _scopes = options.disableDefaultScope ? [] : ["read"];
15
+ if (options.scope) _scopes.push(...options.scope);
16
+ if (scopes) _scopes.push(...scopes);
17
+ return createAuthorizationURL({
18
+ id: "linear",
19
+ options,
20
+ authorizationEndpoint: "https://linear.app/oauth/authorize",
21
+ scopes: _scopes,
22
+ state,
23
+ redirectURI,
24
+ loginHint
25
+ });
26
+ },
27
+ validateAuthorizationCode: async ({ code, redirectURI }) => {
28
+ return validateAuthorizationCode({
29
+ code,
30
+ redirectURI,
31
+ options,
32
+ tokenEndpoint
33
+ });
34
+ },
35
+ refreshAccessToken: options.refreshAccessToken ? options.refreshAccessToken : async (refreshToken) => {
36
+ return refreshAccessToken({
37
+ refreshToken,
38
+ options: {
39
+ clientId: options.clientId,
40
+ clientKey: options.clientKey,
41
+ clientSecret: options.clientSecret
42
+ },
43
+ tokenEndpoint
44
+ });
45
+ },
46
+ async getUserInfo(token) {
47
+ if (options.getUserInfo) return options.getUserInfo(token);
48
+ const { data: profile, error } = await betterFetch("https://api.linear.app/graphql", {
49
+ method: "POST",
50
+ headers: {
51
+ "Content-Type": "application/json",
52
+ Authorization: `Bearer ${token.accessToken}`
53
+ },
54
+ body: JSON.stringify({ query: `
55
+ query {
56
+ viewer {
57
+ id
58
+ name
59
+ email
60
+ avatarUrl
61
+ active
62
+ createdAt
63
+ updatedAt
64
+ }
65
+ }
66
+ ` })
67
+ });
68
+ if (error || !profile?.data?.viewer) return null;
69
+ const userData = profile.data.viewer;
70
+ const userMap = await options.mapProfileToUser?.(userData);
71
+ return {
72
+ user: {
73
+ id: profile.data.viewer.id,
74
+ name: profile.data.viewer.name,
75
+ email: profile.data.viewer.email,
76
+ image: profile.data.viewer.avatarUrl,
77
+ emailVerified: false,
78
+ ...userMap
79
+ },
80
+ data: userData
81
+ };
82
+ },
83
+ options
84
+ };
85
+ };
86
+
87
+ //#endregion
88
+ export { linear };
@@ -0,0 +1,69 @@
1
+ import { OAuth2Tokens, ProviderOptions } from "../oauth2/oauth-provider.mjs";
2
+ import "../oauth2/index.mjs";
3
+
4
+ //#region src/social-providers/linkedin.d.ts
5
+ interface LinkedInProfile {
6
+ sub: string;
7
+ name: string;
8
+ given_name: string;
9
+ family_name: string;
10
+ picture: string;
11
+ locale: {
12
+ country: string;
13
+ language: string;
14
+ };
15
+ email: string;
16
+ email_verified: boolean;
17
+ }
18
+ interface LinkedInOptions extends ProviderOptions<LinkedInProfile> {
19
+ clientId: string;
20
+ }
21
+ declare const linkedin: (options: LinkedInOptions) => {
22
+ id: "linkedin";
23
+ name: string;
24
+ createAuthorizationURL: ({
25
+ state,
26
+ scopes,
27
+ redirectURI,
28
+ loginHint
29
+ }: {
30
+ state: string;
31
+ codeVerifier: string;
32
+ scopes?: string[] | undefined;
33
+ redirectURI: string;
34
+ display?: string | undefined;
35
+ loginHint?: string | undefined;
36
+ }) => Promise<URL>;
37
+ validateAuthorizationCode: ({
38
+ code,
39
+ redirectURI
40
+ }: {
41
+ code: string;
42
+ redirectURI: string;
43
+ codeVerifier?: string | undefined;
44
+ deviceId?: string | undefined;
45
+ }) => Promise<OAuth2Tokens>;
46
+ refreshAccessToken: (refreshToken: string) => Promise<OAuth2Tokens>;
47
+ getUserInfo(token: OAuth2Tokens & {
48
+ user?: {
49
+ name?: {
50
+ firstName?: string;
51
+ lastName?: string;
52
+ };
53
+ email?: string;
54
+ } | undefined;
55
+ }): Promise<{
56
+ user: {
57
+ id: string;
58
+ name?: string;
59
+ email?: string | null;
60
+ image?: string;
61
+ emailVerified: boolean;
62
+ [key: string]: any;
63
+ };
64
+ data: any;
65
+ } | null>;
66
+ options: LinkedInOptions;
67
+ };
68
+ //#endregion
69
+ export { LinkedInOptions, LinkedInProfile, linkedin };
@@ -0,0 +1,76 @@
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/linkedin.ts
8
+ const linkedin = (options) => {
9
+ const authorizationEndpoint = "https://www.linkedin.com/oauth/v2/authorization";
10
+ const tokenEndpoint = "https://www.linkedin.com/oauth/v2/accessToken";
11
+ return {
12
+ id: "linkedin",
13
+ name: "Linkedin",
14
+ createAuthorizationURL: async ({ state, scopes, redirectURI, loginHint }) => {
15
+ const _scopes = options.disableDefaultScope ? [] : [
16
+ "profile",
17
+ "email",
18
+ "openid"
19
+ ];
20
+ if (options.scope) _scopes.push(...options.scope);
21
+ if (scopes) _scopes.push(...scopes);
22
+ return await createAuthorizationURL({
23
+ id: "linkedin",
24
+ options,
25
+ authorizationEndpoint,
26
+ scopes: _scopes,
27
+ state,
28
+ loginHint,
29
+ redirectURI
30
+ });
31
+ },
32
+ validateAuthorizationCode: async ({ code, redirectURI }) => {
33
+ return await validateAuthorizationCode({
34
+ code,
35
+ redirectURI,
36
+ options,
37
+ tokenEndpoint
38
+ });
39
+ },
40
+ refreshAccessToken: options.refreshAccessToken ? options.refreshAccessToken : async (refreshToken) => {
41
+ return refreshAccessToken({
42
+ refreshToken,
43
+ options: {
44
+ clientId: options.clientId,
45
+ clientKey: options.clientKey,
46
+ clientSecret: options.clientSecret
47
+ },
48
+ tokenEndpoint
49
+ });
50
+ },
51
+ async getUserInfo(token) {
52
+ if (options.getUserInfo) return options.getUserInfo(token);
53
+ const { data: profile, error } = await betterFetch("https://api.linkedin.com/v2/userinfo", {
54
+ method: "GET",
55
+ headers: { Authorization: `Bearer ${token.accessToken}` }
56
+ });
57
+ if (error) return null;
58
+ const userMap = await options.mapProfileToUser?.(profile);
59
+ return {
60
+ user: {
61
+ id: profile.sub,
62
+ name: profile.name,
63
+ email: profile.email,
64
+ emailVerified: profile.email_verified || false,
65
+ image: profile.picture,
66
+ ...userMap
67
+ },
68
+ data: profile
69
+ };
70
+ },
71
+ options
72
+ };
73
+ };
74
+
75
+ //#endregion
76
+ export { linkedin };
@@ -0,0 +1,174 @@
1
+ import { OAuth2Tokens, ProviderOptions } from "../oauth2/oauth-provider.mjs";
2
+ import "../oauth2/index.mjs";
3
+
4
+ //#region src/social-providers/microsoft-entra-id.d.ts
5
+ /**
6
+ * @see [Microsoft Identity Platform - Optional claims reference](https://learn.microsoft.com/en-us/entra/identity-platform/optional-claims-reference)
7
+ */
8
+ interface MicrosoftEntraIDProfile extends Record<string, any> {
9
+ /** Identifies the intended recipient of the token */
10
+ aud: string;
11
+ /** Identifies the issuer, or "authorization server" that constructs and returns the token */
12
+ iss: string;
13
+ /** Indicates when the authentication for the token occurred */
14
+ iat: Date;
15
+ /** Records the identity provider that authenticated the subject of the token */
16
+ idp: string;
17
+ /** Identifies the time before which the JWT can't be accepted for processing */
18
+ nbf: Date;
19
+ /** Identifies the expiration time on or after which the JWT can't be accepted for processing */
20
+ exp: Date;
21
+ /** Code hash included in ID tokens when issued with an OAuth 2.0 authorization code */
22
+ c_hash: string;
23
+ /** Access token hash included in ID tokens when issued with an OAuth 2.0 access token */
24
+ at_hash: string;
25
+ /** Internal claim used to record data for token reuse */
26
+ aio: string;
27
+ /** The primary username that represents the user */
28
+ preferred_username: string;
29
+ /** User's email address */
30
+ email: string;
31
+ /** Human-readable value that identifies the subject of the token */
32
+ name: string;
33
+ /** Matches the parameter included in the original authorize request */
34
+ nonce: string;
35
+ /** User's profile picture */
36
+ picture: string;
37
+ /** Immutable identifier for the user account */
38
+ oid: string;
39
+ /** Set of roles assigned to the user */
40
+ roles: string[];
41
+ /** Internal claim used to revalidate tokens */
42
+ rh: string;
43
+ /** Subject identifier - unique to application ID */
44
+ sub: string;
45
+ /** Tenant ID the user is signing in to */
46
+ tid: string;
47
+ /** Unique identifier for a session */
48
+ sid: string;
49
+ /** Token identifier claim */
50
+ uti: string;
51
+ /** Indicates if user is in at least one group */
52
+ hasgroups: boolean;
53
+ /** User account status in tenant (0 = member, 1 = guest) */
54
+ acct: 0 | 1;
55
+ /** Auth Context IDs */
56
+ acrs: string;
57
+ /** Time when the user last authenticated */
58
+ auth_time: Date;
59
+ /** User's country/region */
60
+ ctry: string;
61
+ /** IP address of requesting client when inside VNET */
62
+ fwd: string;
63
+ /** Group claims */
64
+ groups: string;
65
+ /** Login hint for SSO */
66
+ login_hint: string;
67
+ /** Resource tenant's country/region */
68
+ tenant_ctry: string;
69
+ /** Region of the resource tenant */
70
+ tenant_region_scope: string;
71
+ /** UserPrincipalName */
72
+ upn: string;
73
+ /** User's verified primary email addresses */
74
+ verified_primary_email: string[];
75
+ /** User's verified secondary email addresses */
76
+ verified_secondary_email: string[];
77
+ /** Whether the user's email is verified (optional claim, must be configured in app registration) */
78
+ email_verified?: boolean | undefined;
79
+ /** VNET specifier information */
80
+ vnet: string;
81
+ /** Client Capabilities */
82
+ xms_cc: string;
83
+ /** Whether user's email domain is verified */
84
+ xms_edov: boolean;
85
+ /** Preferred data location for Multi-Geo tenants */
86
+ xms_pdl: string;
87
+ /** User preferred language */
88
+ xms_pl: string;
89
+ /** Tenant preferred language */
90
+ xms_tpl: string;
91
+ /** Zero-touch Deployment ID */
92
+ ztdid: string;
93
+ /** IP Address */
94
+ ipaddr: string;
95
+ /** On-premises Security Identifier */
96
+ onprem_sid: string;
97
+ /** Password Expiration Time */
98
+ pwd_exp: number;
99
+ /** Change Password URL */
100
+ pwd_url: string;
101
+ /** Inside Corporate Network flag */
102
+ in_corp: string;
103
+ /** User's family name/surname */
104
+ family_name: string;
105
+ /** User's given/first name */
106
+ given_name: string;
107
+ }
108
+ interface MicrosoftOptions extends ProviderOptions<MicrosoftEntraIDProfile> {
109
+ clientId: string;
110
+ /**
111
+ * The tenant ID of the Microsoft account
112
+ * @default "common"
113
+ */
114
+ tenantId?: string | undefined;
115
+ /**
116
+ * The authentication authority URL. Use the default "https://login.microsoftonline.com" for standard Entra ID or "https://<tenant-id>.ciamlogin.com" for CIAM scenarios.
117
+ * @default "https://login.microsoftonline.com"
118
+ */
119
+ authority?: string | undefined;
120
+ /**
121
+ * The size of the profile photo
122
+ * @default 48
123
+ */
124
+ profilePhotoSize?: (48 | 64 | 96 | 120 | 240 | 360 | 432 | 504 | 648) | undefined;
125
+ /**
126
+ * Disable profile photo
127
+ */
128
+ disableProfilePhoto?: boolean | undefined;
129
+ }
130
+ declare const microsoft: (options: MicrosoftOptions) => {
131
+ id: "microsoft";
132
+ name: string;
133
+ createAuthorizationURL(data: {
134
+ state: string;
135
+ codeVerifier: string;
136
+ scopes?: string[] | undefined;
137
+ redirectURI: string;
138
+ display?: string | undefined;
139
+ loginHint?: string | undefined;
140
+ }): Promise<URL>;
141
+ validateAuthorizationCode({
142
+ code,
143
+ codeVerifier,
144
+ redirectURI
145
+ }: {
146
+ code: string;
147
+ redirectURI: string;
148
+ codeVerifier?: string | undefined;
149
+ deviceId?: string | undefined;
150
+ }): Promise<OAuth2Tokens>;
151
+ getUserInfo(token: OAuth2Tokens & {
152
+ user?: {
153
+ name?: {
154
+ firstName?: string;
155
+ lastName?: string;
156
+ };
157
+ email?: string;
158
+ } | undefined;
159
+ }): Promise<{
160
+ user: {
161
+ id: string;
162
+ name?: string;
163
+ email?: string | null;
164
+ image?: string;
165
+ emailVerified: boolean;
166
+ [key: string]: any;
167
+ };
168
+ data: any;
169
+ } | null>;
170
+ refreshAccessToken: (refreshToken: string) => Promise<OAuth2Tokens>;
171
+ options: MicrosoftOptions;
172
+ };
173
+ //#endregion
174
+ export { MicrosoftEntraIDProfile, MicrosoftOptions, microsoft };
@@ -0,0 +1,106 @@
1
+ import { logger } from "../env/logger.mjs";
2
+ import "../env/index.mjs";
3
+ import { createAuthorizationURL } from "../oauth2/create-authorization-url.mjs";
4
+ import { refreshAccessToken } from "../oauth2/refresh-access-token.mjs";
5
+ import { validateAuthorizationCode } from "../oauth2/validate-authorization-code.mjs";
6
+ import "../oauth2/index.mjs";
7
+ import { base64 } from "@better-auth/utils/base64";
8
+ import { betterFetch } from "@better-fetch/fetch";
9
+ import { decodeJwt } from "jose";
10
+
11
+ //#region src/social-providers/microsoft-entra-id.ts
12
+ const microsoft = (options) => {
13
+ const tenant = options.tenantId || "common";
14
+ const authority = options.authority || "https://login.microsoftonline.com";
15
+ const authorizationEndpoint = `${authority}/${tenant}/oauth2/v2.0/authorize`;
16
+ const tokenEndpoint = `${authority}/${tenant}/oauth2/v2.0/token`;
17
+ return {
18
+ id: "microsoft",
19
+ name: "Microsoft EntraID",
20
+ createAuthorizationURL(data) {
21
+ const scopes = options.disableDefaultScope ? [] : [
22
+ "openid",
23
+ "profile",
24
+ "email",
25
+ "User.Read",
26
+ "offline_access"
27
+ ];
28
+ if (options.scope) scopes.push(...options.scope);
29
+ if (data.scopes) scopes.push(...data.scopes);
30
+ return createAuthorizationURL({
31
+ id: "microsoft",
32
+ options,
33
+ authorizationEndpoint,
34
+ state: data.state,
35
+ codeVerifier: data.codeVerifier,
36
+ scopes,
37
+ redirectURI: data.redirectURI,
38
+ prompt: options.prompt,
39
+ loginHint: data.loginHint
40
+ });
41
+ },
42
+ validateAuthorizationCode({ code, codeVerifier, redirectURI }) {
43
+ return validateAuthorizationCode({
44
+ code,
45
+ codeVerifier,
46
+ redirectURI,
47
+ options,
48
+ tokenEndpoint
49
+ });
50
+ },
51
+ async getUserInfo(token) {
52
+ if (options.getUserInfo) return options.getUserInfo(token);
53
+ if (!token.idToken) return null;
54
+ const user = decodeJwt(token.idToken);
55
+ const profilePhotoSize = options.profilePhotoSize || 48;
56
+ await betterFetch(`https://graph.microsoft.com/v1.0/me/photos/${profilePhotoSize}x${profilePhotoSize}/$value`, {
57
+ headers: { Authorization: `Bearer ${token.accessToken}` },
58
+ async onResponse(context) {
59
+ if (options.disableProfilePhoto || !context.response.ok) return;
60
+ try {
61
+ const pictureBuffer = await context.response.clone().arrayBuffer();
62
+ user.picture = `data:image/jpeg;base64, ${base64.encode(pictureBuffer)}`;
63
+ } catch (e) {
64
+ logger.error(e && typeof e === "object" && "name" in e ? e.name : "", e);
65
+ }
66
+ }
67
+ });
68
+ const userMap = await options.mapProfileToUser?.(user);
69
+ const emailVerified = user.email_verified !== void 0 ? user.email_verified : user.email && (user.verified_primary_email?.includes(user.email) || user.verified_secondary_email?.includes(user.email)) ? true : false;
70
+ return {
71
+ user: {
72
+ id: user.sub,
73
+ name: user.name,
74
+ email: user.email,
75
+ image: user.picture,
76
+ emailVerified,
77
+ ...userMap
78
+ },
79
+ data: user
80
+ };
81
+ },
82
+ refreshAccessToken: options.refreshAccessToken ? options.refreshAccessToken : async (refreshToken) => {
83
+ const scopes = options.disableDefaultScope ? [] : [
84
+ "openid",
85
+ "profile",
86
+ "email",
87
+ "User.Read",
88
+ "offline_access"
89
+ ];
90
+ if (options.scope) scopes.push(...options.scope);
91
+ return refreshAccessToken({
92
+ refreshToken,
93
+ options: {
94
+ clientId: options.clientId,
95
+ clientSecret: options.clientSecret
96
+ },
97
+ extraParams: { scope: scopes.join(" ") },
98
+ tokenEndpoint
99
+ });
100
+ },
101
+ options
102
+ };
103
+ };
104
+
105
+ //#endregion
106
+ export { microsoft };
@@ -0,0 +1,104 @@
1
+ import { OAuth2Tokens, ProviderOptions } from "../oauth2/oauth-provider.mjs";
2
+ import "../oauth2/index.mjs";
3
+
4
+ //#region src/social-providers/naver.d.ts
5
+ interface NaverProfile {
6
+ /** API response result code */
7
+ resultcode: string;
8
+ /** API response message */
9
+ message: string;
10
+ response: {
11
+ /** Unique Naver user identifier */
12
+ id: string;
13
+ /** User nickname */
14
+ nickname: string;
15
+ /** User real name */
16
+ name: string;
17
+ /** User email address */
18
+ email: string;
19
+ /** Gender (F: female, M: male, U: unknown) */
20
+ gender: string;
21
+ /** Age range */
22
+ age: string;
23
+ /** Birthday (MM-DD format) */
24
+ birthday: string;
25
+ /** Birth year */
26
+ birthyear: string;
27
+ /** Profile image URL */
28
+ profile_image: string;
29
+ /** Mobile phone number */
30
+ mobile: string;
31
+ };
32
+ }
33
+ interface NaverOptions extends ProviderOptions<NaverProfile> {
34
+ clientId: string;
35
+ }
36
+ declare const naver: (options: NaverOptions) => {
37
+ id: "naver";
38
+ name: string;
39
+ createAuthorizationURL({
40
+ state,
41
+ scopes,
42
+ redirectURI
43
+ }: {
44
+ state: string;
45
+ codeVerifier: string;
46
+ scopes?: string[] | undefined;
47
+ redirectURI: string;
48
+ display?: string | undefined;
49
+ loginHint?: string | undefined;
50
+ }): Promise<URL>;
51
+ validateAuthorizationCode: ({
52
+ code,
53
+ redirectURI
54
+ }: {
55
+ code: string;
56
+ redirectURI: string;
57
+ codeVerifier?: string | undefined;
58
+ deviceId?: string | undefined;
59
+ }) => Promise<OAuth2Tokens>;
60
+ refreshAccessToken: (refreshToken: string) => Promise<OAuth2Tokens>;
61
+ getUserInfo(token: OAuth2Tokens & {
62
+ user?: {
63
+ name?: {
64
+ firstName?: string;
65
+ lastName?: string;
66
+ };
67
+ email?: string;
68
+ } | undefined;
69
+ }): Promise<{
70
+ user: {
71
+ id: string;
72
+ name?: string;
73
+ email?: string | null;
74
+ image?: string;
75
+ emailVerified: boolean;
76
+ [key: string]: any;
77
+ };
78
+ data: any;
79
+ } | {
80
+ user: {
81
+ id: string;
82
+ name: string;
83
+ email: string;
84
+ image: string;
85
+ emailVerified: boolean;
86
+ } | {
87
+ id: string;
88
+ name: string;
89
+ email: string | null;
90
+ image: string;
91
+ emailVerified: boolean;
92
+ } | {
93
+ id: string;
94
+ name: string;
95
+ email: string | null;
96
+ image: string;
97
+ emailVerified: boolean;
98
+ };
99
+ data: NaverProfile;
100
+ } | null>;
101
+ options: NaverOptions;
102
+ };
103
+ //#endregion
104
+ export { NaverOptions, NaverProfile, naver };
@@ -0,0 +1,67 @@
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/naver.ts
8
+ const naver = (options) => {
9
+ return {
10
+ id: "naver",
11
+ name: "Naver",
12
+ createAuthorizationURL({ state, scopes, redirectURI }) {
13
+ const _scopes = options.disableDefaultScope ? [] : ["profile", "email"];
14
+ if (options.scope) _scopes.push(...options.scope);
15
+ if (scopes) _scopes.push(...scopes);
16
+ return createAuthorizationURL({
17
+ id: "naver",
18
+ options,
19
+ authorizationEndpoint: "https://nid.naver.com/oauth2.0/authorize",
20
+ scopes: _scopes,
21
+ state,
22
+ redirectURI
23
+ });
24
+ },
25
+ validateAuthorizationCode: async ({ code, redirectURI }) => {
26
+ return validateAuthorizationCode({
27
+ code,
28
+ redirectURI,
29
+ options,
30
+ tokenEndpoint: "https://nid.naver.com/oauth2.0/token"
31
+ });
32
+ },
33
+ refreshAccessToken: options.refreshAccessToken ? options.refreshAccessToken : async (refreshToken) => {
34
+ return refreshAccessToken({
35
+ refreshToken,
36
+ options: {
37
+ clientId: options.clientId,
38
+ clientKey: options.clientKey,
39
+ clientSecret: options.clientSecret
40
+ },
41
+ tokenEndpoint: "https://nid.naver.com/oauth2.0/token"
42
+ });
43
+ },
44
+ async getUserInfo(token) {
45
+ if (options.getUserInfo) return options.getUserInfo(token);
46
+ const { data: profile, error } = await betterFetch("https://openapi.naver.com/v1/nid/me", { headers: { Authorization: `Bearer ${token.accessToken}` } });
47
+ if (error || !profile || profile.resultcode !== "00") return null;
48
+ const userMap = await options.mapProfileToUser?.(profile);
49
+ const res = profile.response || {};
50
+ return {
51
+ user: {
52
+ id: res.id,
53
+ name: res.name || res.nickname,
54
+ email: res.email,
55
+ image: res.profile_image,
56
+ emailVerified: false,
57
+ ...userMap
58
+ },
59
+ data: profile
60
+ };
61
+ },
62
+ options
63
+ };
64
+ };
65
+
66
+ //#endregion
67
+ export { naver };