@hammadj/better-auth-core 1.5.0-beta.9

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 (353) hide show
  1. package/.turbo/turbo-build.log +266 -0
  2. package/.turbo/turbo-test.log +2 -0
  3. package/LICENSE.md +20 -0
  4. package/dist/api/index.d.mts +181 -0
  5. package/dist/api/index.mjs +34 -0
  6. package/dist/api/index.mjs.map +1 -0
  7. package/dist/async_hooks/index.d.mts +7 -0
  8. package/dist/async_hooks/index.mjs +22 -0
  9. package/dist/async_hooks/index.mjs.map +1 -0
  10. package/dist/async_hooks/pure.index.d.mts +7 -0
  11. package/dist/async_hooks/pure.index.mjs +35 -0
  12. package/dist/async_hooks/pure.index.mjs.map +1 -0
  13. package/dist/context/endpoint-context.d.mts +19 -0
  14. package/dist/context/endpoint-context.mjs +32 -0
  15. package/dist/context/endpoint-context.mjs.map +1 -0
  16. package/dist/context/global.d.mts +7 -0
  17. package/dist/context/global.mjs +38 -0
  18. package/dist/context/global.mjs.map +1 -0
  19. package/dist/context/index.d.mts +5 -0
  20. package/dist/context/index.mjs +6 -0
  21. package/dist/context/request-state.d.mts +26 -0
  22. package/dist/context/request-state.mjs +50 -0
  23. package/dist/context/request-state.mjs.map +1 -0
  24. package/dist/context/transaction.d.mts +25 -0
  25. package/dist/context/transaction.mjs +96 -0
  26. package/dist/context/transaction.mjs.map +1 -0
  27. package/dist/db/adapter/factory.d.mts +28 -0
  28. package/dist/db/adapter/factory.mjs +716 -0
  29. package/dist/db/adapter/factory.mjs.map +1 -0
  30. package/dist/db/adapter/get-default-field-name.d.mts +19 -0
  31. package/dist/db/adapter/get-default-field-name.mjs +39 -0
  32. package/dist/db/adapter/get-default-field-name.mjs.map +1 -0
  33. package/dist/db/adapter/get-default-model-name.d.mts +13 -0
  34. package/dist/db/adapter/get-default-model-name.mjs +33 -0
  35. package/dist/db/adapter/get-default-model-name.mjs.map +1 -0
  36. package/dist/db/adapter/get-field-attributes.d.mts +30 -0
  37. package/dist/db/adapter/get-field-attributes.mjs +40 -0
  38. package/dist/db/adapter/get-field-attributes.mjs.map +1 -0
  39. package/dist/db/adapter/get-field-name.d.mts +19 -0
  40. package/dist/db/adapter/get-field-name.mjs +34 -0
  41. package/dist/db/adapter/get-field-name.mjs.map +1 -0
  42. package/dist/db/adapter/get-id-field.d.mts +40 -0
  43. package/dist/db/adapter/get-id-field.mjs +68 -0
  44. package/dist/db/adapter/get-id-field.mjs.map +1 -0
  45. package/dist/db/adapter/get-model-name.d.mts +13 -0
  46. package/dist/db/adapter/get-model-name.mjs +24 -0
  47. package/dist/db/adapter/get-model-name.mjs.map +1 -0
  48. package/dist/db/adapter/index.d.mts +515 -0
  49. package/dist/db/adapter/index.mjs +10 -0
  50. package/dist/db/adapter/types.d.mts +140 -0
  51. package/dist/db/adapter/utils.d.mts +8 -0
  52. package/dist/db/adapter/utils.mjs +39 -0
  53. package/dist/db/adapter/utils.mjs.map +1 -0
  54. package/dist/db/get-tables.d.mts +9 -0
  55. package/dist/db/get-tables.mjs +267 -0
  56. package/dist/db/get-tables.mjs.map +1 -0
  57. package/dist/db/index.d.mts +10 -0
  58. package/dist/db/index.mjs +9 -0
  59. package/dist/db/plugin.d.mts +13 -0
  60. package/dist/db/schema/account.d.mts +27 -0
  61. package/dist/db/schema/account.mjs +20 -0
  62. package/dist/db/schema/account.mjs.map +1 -0
  63. package/dist/db/schema/rate-limit.d.mts +15 -0
  64. package/dist/db/schema/rate-limit.mjs +12 -0
  65. package/dist/db/schema/rate-limit.mjs.map +1 -0
  66. package/dist/db/schema/session.d.mts +22 -0
  67. package/dist/db/schema/session.mjs +15 -0
  68. package/dist/db/schema/session.mjs.map +1 -0
  69. package/dist/db/schema/shared.d.mts +11 -0
  70. package/dist/db/schema/shared.mjs +12 -0
  71. package/dist/db/schema/shared.mjs.map +1 -0
  72. package/dist/db/schema/user.d.mts +21 -0
  73. package/dist/db/schema/user.mjs +14 -0
  74. package/dist/db/schema/user.mjs.map +1 -0
  75. package/dist/db/schema/verification.d.mts +20 -0
  76. package/dist/db/schema/verification.mjs +13 -0
  77. package/dist/db/schema/verification.mjs.map +1 -0
  78. package/dist/db/type.d.mts +147 -0
  79. package/dist/env/color-depth.d.mts +5 -0
  80. package/dist/env/color-depth.mjs +89 -0
  81. package/dist/env/color-depth.mjs.map +1 -0
  82. package/dist/env/env-impl.d.mts +33 -0
  83. package/dist/env/env-impl.mjs +83 -0
  84. package/dist/env/env-impl.mjs.map +1 -0
  85. package/dist/env/index.d.mts +4 -0
  86. package/dist/env/index.mjs +5 -0
  87. package/dist/env/logger.d.mts +49 -0
  88. package/dist/env/logger.mjs +82 -0
  89. package/dist/env/logger.mjs.map +1 -0
  90. package/dist/error/codes.d.mts +199 -0
  91. package/dist/error/codes.mjs +57 -0
  92. package/dist/error/codes.mjs.map +1 -0
  93. package/dist/error/index.d.mts +20 -0
  94. package/dist/error/index.mjs +30 -0
  95. package/dist/error/index.mjs.map +1 -0
  96. package/dist/index.d.mts +8 -0
  97. package/dist/index.mjs +1 -0
  98. package/dist/oauth2/client-credentials-token.d.mts +37 -0
  99. package/dist/oauth2/client-credentials-token.mjs +55 -0
  100. package/dist/oauth2/client-credentials-token.mjs.map +1 -0
  101. package/dist/oauth2/create-authorization-url.d.mts +46 -0
  102. package/dist/oauth2/create-authorization-url.mjs +43 -0
  103. package/dist/oauth2/create-authorization-url.mjs.map +1 -0
  104. package/dist/oauth2/index.d.mts +8 -0
  105. package/dist/oauth2/index.mjs +8 -0
  106. package/dist/oauth2/oauth-provider.d.mts +195 -0
  107. package/dist/oauth2/refresh-access-token.d.mts +36 -0
  108. package/dist/oauth2/refresh-access-token.mjs +59 -0
  109. package/dist/oauth2/refresh-access-token.mjs.map +1 -0
  110. package/dist/oauth2/utils.d.mts +8 -0
  111. package/dist/oauth2/utils.mjs +28 -0
  112. package/dist/oauth2/utils.mjs.map +1 -0
  113. package/dist/oauth2/validate-authorization-code.d.mts +56 -0
  114. package/dist/oauth2/validate-authorization-code.mjs +72 -0
  115. package/dist/oauth2/validate-authorization-code.mjs.map +1 -0
  116. package/dist/oauth2/verify.d.mts +43 -0
  117. package/dist/oauth2/verify.mjs +96 -0
  118. package/dist/oauth2/verify.mjs.map +1 -0
  119. package/dist/social-providers/apple.d.mts +120 -0
  120. package/dist/social-providers/apple.mjs +105 -0
  121. package/dist/social-providers/apple.mjs.map +1 -0
  122. package/dist/social-providers/atlassian.d.mts +73 -0
  123. package/dist/social-providers/atlassian.mjs +84 -0
  124. package/dist/social-providers/atlassian.mjs.map +1 -0
  125. package/dist/social-providers/cognito.d.mts +88 -0
  126. package/dist/social-providers/cognito.mjs +166 -0
  127. package/dist/social-providers/cognito.mjs.map +1 -0
  128. package/dist/social-providers/discord.d.mts +127 -0
  129. package/dist/social-providers/discord.mjs +65 -0
  130. package/dist/social-providers/discord.mjs.map +1 -0
  131. package/dist/social-providers/dropbox.d.mts +72 -0
  132. package/dist/social-providers/dropbox.mjs +76 -0
  133. package/dist/social-providers/dropbox.mjs.map +1 -0
  134. package/dist/social-providers/facebook.d.mts +82 -0
  135. package/dist/social-providers/facebook.mjs +121 -0
  136. package/dist/social-providers/facebook.mjs.map +1 -0
  137. package/dist/social-providers/figma.d.mts +64 -0
  138. package/dist/social-providers/figma.mjs +87 -0
  139. package/dist/social-providers/figma.mjs.map +1 -0
  140. package/dist/social-providers/github.d.mts +105 -0
  141. package/dist/social-providers/github.mjs +97 -0
  142. package/dist/social-providers/github.mjs.map +1 -0
  143. package/dist/social-providers/gitlab.d.mts +126 -0
  144. package/dist/social-providers/gitlab.mjs +83 -0
  145. package/dist/social-providers/gitlab.mjs.map +1 -0
  146. package/dist/social-providers/google.d.mts +100 -0
  147. package/dist/social-providers/google.mjs +109 -0
  148. package/dist/social-providers/google.mjs.map +1 -0
  149. package/dist/social-providers/huggingface.d.mts +86 -0
  150. package/dist/social-providers/huggingface.mjs +76 -0
  151. package/dist/social-providers/huggingface.mjs.map +1 -0
  152. package/dist/social-providers/index.d.mts +1725 -0
  153. package/dist/social-providers/index.mjs +77 -0
  154. package/dist/social-providers/index.mjs.map +1 -0
  155. package/dist/social-providers/kakao.d.mts +164 -0
  156. package/dist/social-providers/kakao.mjs +73 -0
  157. package/dist/social-providers/kakao.mjs.map +1 -0
  158. package/dist/social-providers/kick.d.mts +76 -0
  159. package/dist/social-providers/kick.mjs +72 -0
  160. package/dist/social-providers/kick.mjs.map +1 -0
  161. package/dist/social-providers/line.d.mts +108 -0
  162. package/dist/social-providers/line.mjs +114 -0
  163. package/dist/social-providers/line.mjs.map +1 -0
  164. package/dist/social-providers/linear.d.mts +71 -0
  165. package/dist/social-providers/linear.mjs +89 -0
  166. package/dist/social-providers/linear.mjs.map +1 -0
  167. package/dist/social-providers/linkedin.d.mts +70 -0
  168. package/dist/social-providers/linkedin.mjs +77 -0
  169. package/dist/social-providers/linkedin.mjs.map +1 -0
  170. package/dist/social-providers/microsoft-entra-id.d.mts +175 -0
  171. package/dist/social-providers/microsoft-entra-id.mjs +107 -0
  172. package/dist/social-providers/microsoft-entra-id.mjs.map +1 -0
  173. package/dist/social-providers/naver.d.mts +95 -0
  174. package/dist/social-providers/naver.mjs +68 -0
  175. package/dist/social-providers/naver.mjs.map +1 -0
  176. package/dist/social-providers/notion.d.mts +67 -0
  177. package/dist/social-providers/notion.mjs +76 -0
  178. package/dist/social-providers/notion.mjs.map +1 -0
  179. package/dist/social-providers/paybin.d.mts +74 -0
  180. package/dist/social-providers/paybin.mjs +86 -0
  181. package/dist/social-providers/paybin.mjs.map +1 -0
  182. package/dist/social-providers/paypal.d.mts +132 -0
  183. package/dist/social-providers/paypal.mjs +145 -0
  184. package/dist/social-providers/paypal.mjs.map +1 -0
  185. package/dist/social-providers/polar.d.mts +77 -0
  186. package/dist/social-providers/polar.mjs +74 -0
  187. package/dist/social-providers/polar.mjs.map +1 -0
  188. package/dist/social-providers/reddit.d.mts +65 -0
  189. package/dist/social-providers/reddit.mjs +84 -0
  190. package/dist/social-providers/reddit.mjs.map +1 -0
  191. package/dist/social-providers/roblox.d.mts +73 -0
  192. package/dist/social-providers/roblox.mjs +60 -0
  193. package/dist/social-providers/roblox.mjs.map +1 -0
  194. package/dist/social-providers/salesforce.d.mts +82 -0
  195. package/dist/social-providers/salesforce.mjs +92 -0
  196. package/dist/social-providers/salesforce.mjs.map +1 -0
  197. package/dist/social-providers/slack.d.mts +86 -0
  198. package/dist/social-providers/slack.mjs +69 -0
  199. package/dist/social-providers/slack.mjs.map +1 -0
  200. package/dist/social-providers/spotify.d.mts +66 -0
  201. package/dist/social-providers/spotify.mjs +72 -0
  202. package/dist/social-providers/spotify.mjs.map +1 -0
  203. package/dist/social-providers/tiktok.d.mts +171 -0
  204. package/dist/social-providers/tiktok.mjs +63 -0
  205. package/dist/social-providers/tiktok.mjs.map +1 -0
  206. package/dist/social-providers/twitch.d.mts +82 -0
  207. package/dist/social-providers/twitch.mjs +79 -0
  208. package/dist/social-providers/twitch.mjs.map +1 -0
  209. package/dist/social-providers/twitter.d.mts +129 -0
  210. package/dist/social-providers/twitter.mjs +88 -0
  211. package/dist/social-providers/twitter.mjs.map +1 -0
  212. package/dist/social-providers/vercel.d.mts +65 -0
  213. package/dist/social-providers/vercel.mjs +62 -0
  214. package/dist/social-providers/vercel.mjs.map +1 -0
  215. package/dist/social-providers/vk.d.mts +73 -0
  216. package/dist/social-providers/vk.mjs +84 -0
  217. package/dist/social-providers/vk.mjs.map +1 -0
  218. package/dist/social-providers/zoom.d.mts +173 -0
  219. package/dist/social-providers/zoom.mjs +73 -0
  220. package/dist/social-providers/zoom.mjs.map +1 -0
  221. package/dist/types/context.d.mts +267 -0
  222. package/dist/types/cookie.d.mts +16 -0
  223. package/dist/types/helper.d.mts +10 -0
  224. package/dist/types/index.d.mts +8 -0
  225. package/dist/types/init-options.d.mts +1314 -0
  226. package/dist/types/plugin-client.d.mts +112 -0
  227. package/dist/types/plugin.d.mts +125 -0
  228. package/dist/utils/db.d.mts +12 -0
  229. package/dist/utils/db.mjs +17 -0
  230. package/dist/utils/db.mjs.map +1 -0
  231. package/dist/utils/deprecate.d.mts +10 -0
  232. package/dist/utils/deprecate.mjs +18 -0
  233. package/dist/utils/deprecate.mjs.map +1 -0
  234. package/dist/utils/error-codes.d.mts +13 -0
  235. package/dist/utils/error-codes.mjs +12 -0
  236. package/dist/utils/error-codes.mjs.map +1 -0
  237. package/dist/utils/id.d.mts +5 -0
  238. package/dist/utils/id.mjs +10 -0
  239. package/dist/utils/id.mjs.map +1 -0
  240. package/dist/utils/ip.d.mts +55 -0
  241. package/dist/utils/ip.mjs +119 -0
  242. package/dist/utils/ip.mjs.map +1 -0
  243. package/dist/utils/json.d.mts +5 -0
  244. package/dist/utils/json.mjs +26 -0
  245. package/dist/utils/json.mjs.map +1 -0
  246. package/dist/utils/string.d.mts +5 -0
  247. package/dist/utils/string.mjs +8 -0
  248. package/dist/utils/string.mjs.map +1 -0
  249. package/dist/utils/url.d.mts +21 -0
  250. package/dist/utils/url.mjs +33 -0
  251. package/dist/utils/url.mjs.map +1 -0
  252. package/package.json +147 -0
  253. package/src/api/index.ts +106 -0
  254. package/src/async_hooks/index.ts +40 -0
  255. package/src/async_hooks/pure.index.ts +46 -0
  256. package/src/context/endpoint-context.ts +50 -0
  257. package/src/context/global.ts +57 -0
  258. package/src/context/index.ts +23 -0
  259. package/src/context/request-state.test.ts +94 -0
  260. package/src/context/request-state.ts +91 -0
  261. package/src/context/transaction.ts +136 -0
  262. package/src/db/adapter/factory.ts +1362 -0
  263. package/src/db/adapter/get-default-field-name.ts +59 -0
  264. package/src/db/adapter/get-default-model-name.ts +51 -0
  265. package/src/db/adapter/get-field-attributes.ts +62 -0
  266. package/src/db/adapter/get-field-name.ts +43 -0
  267. package/src/db/adapter/get-id-field.ts +141 -0
  268. package/src/db/adapter/get-model-name.ts +36 -0
  269. package/src/db/adapter/index.ts +554 -0
  270. package/src/db/adapter/types.ts +171 -0
  271. package/src/db/adapter/utils.ts +61 -0
  272. package/src/db/get-tables.ts +296 -0
  273. package/src/db/index.ts +18 -0
  274. package/src/db/plugin.ts +11 -0
  275. package/src/db/schema/account.ts +34 -0
  276. package/src/db/schema/rate-limit.ts +21 -0
  277. package/src/db/schema/session.ts +17 -0
  278. package/src/db/schema/shared.ts +7 -0
  279. package/src/db/schema/user.ts +16 -0
  280. package/src/db/schema/verification.ts +15 -0
  281. package/src/db/test/get-tables.test.ts +116 -0
  282. package/src/db/type.ts +180 -0
  283. package/src/env/color-depth.ts +172 -0
  284. package/src/env/env-impl.ts +124 -0
  285. package/src/env/index.ts +23 -0
  286. package/src/env/logger.test.ts +34 -0
  287. package/src/env/logger.ts +145 -0
  288. package/src/error/codes.ts +58 -0
  289. package/src/error/index.ts +35 -0
  290. package/src/index.ts +1 -0
  291. package/src/oauth2/client-credentials-token.ts +102 -0
  292. package/src/oauth2/create-authorization-url.ts +87 -0
  293. package/src/oauth2/index.ts +26 -0
  294. package/src/oauth2/oauth-provider.ts +222 -0
  295. package/src/oauth2/refresh-access-token.ts +124 -0
  296. package/src/oauth2/utils.ts +38 -0
  297. package/src/oauth2/validate-authorization-code.ts +149 -0
  298. package/src/oauth2/validate-token.test.ts +174 -0
  299. package/src/oauth2/verify.ts +221 -0
  300. package/src/social-providers/apple.ts +223 -0
  301. package/src/social-providers/atlassian.ts +132 -0
  302. package/src/social-providers/cognito.ts +279 -0
  303. package/src/social-providers/discord.ts +169 -0
  304. package/src/social-providers/dropbox.ts +112 -0
  305. package/src/social-providers/facebook.ts +206 -0
  306. package/src/social-providers/figma.ts +117 -0
  307. package/src/social-providers/github.ts +184 -0
  308. package/src/social-providers/gitlab.ts +155 -0
  309. package/src/social-providers/google.ts +199 -0
  310. package/src/social-providers/huggingface.ts +118 -0
  311. package/src/social-providers/index.ts +127 -0
  312. package/src/social-providers/kakao.ts +178 -0
  313. package/src/social-providers/kick.ts +109 -0
  314. package/src/social-providers/line.ts +169 -0
  315. package/src/social-providers/linear.ts +121 -0
  316. package/src/social-providers/linkedin.ts +110 -0
  317. package/src/social-providers/microsoft-entra-id.ts +259 -0
  318. package/src/social-providers/naver.ts +112 -0
  319. package/src/social-providers/notion.ts +108 -0
  320. package/src/social-providers/paybin.ts +122 -0
  321. package/src/social-providers/paypal.ts +263 -0
  322. package/src/social-providers/polar.ts +110 -0
  323. package/src/social-providers/reddit.ts +122 -0
  324. package/src/social-providers/roblox.ts +111 -0
  325. package/src/social-providers/salesforce.ts +159 -0
  326. package/src/social-providers/slack.ts +111 -0
  327. package/src/social-providers/spotify.ts +93 -0
  328. package/src/social-providers/tiktok.ts +209 -0
  329. package/src/social-providers/twitch.ts +111 -0
  330. package/src/social-providers/twitter.ts +198 -0
  331. package/src/social-providers/vercel.ts +87 -0
  332. package/src/social-providers/vk.ts +124 -0
  333. package/src/social-providers/zoom.ts +238 -0
  334. package/src/types/context.ts +396 -0
  335. package/src/types/cookie.ts +10 -0
  336. package/src/types/helper.ts +26 -0
  337. package/src/types/index.ts +32 -0
  338. package/src/types/init-options.ts +1529 -0
  339. package/src/types/plugin-client.ts +127 -0
  340. package/src/types/plugin.ts +157 -0
  341. package/src/utils/db.ts +20 -0
  342. package/src/utils/deprecate.test.ts +72 -0
  343. package/src/utils/deprecate.ts +21 -0
  344. package/src/utils/error-codes.ts +65 -0
  345. package/src/utils/id.ts +5 -0
  346. package/src/utils/ip.test.ts +255 -0
  347. package/src/utils/ip.ts +211 -0
  348. package/src/utils/json.ts +25 -0
  349. package/src/utils/string.ts +3 -0
  350. package/src/utils/url.ts +43 -0
  351. package/tsconfig.json +7 -0
  352. package/tsdown.config.ts +35 -0
  353. package/vitest.config.ts +3 -0
@@ -0,0 +1,110 @@
1
+ import { betterFetch } from "@better-fetch/fetch";
2
+ import type { OAuthProvider, ProviderOptions } from "../oauth2";
3
+ import {
4
+ createAuthorizationURL,
5
+ refreshAccessToken,
6
+ validateAuthorizationCode,
7
+ } from "../oauth2";
8
+
9
+ export interface LinkedInProfile {
10
+ sub: string;
11
+ name: string;
12
+ given_name: string;
13
+ family_name: string;
14
+ picture: string;
15
+ locale: {
16
+ country: string;
17
+ language: string;
18
+ };
19
+ email: string;
20
+ email_verified: boolean;
21
+ }
22
+
23
+ export interface LinkedInOptions extends ProviderOptions<LinkedInProfile> {
24
+ clientId: string;
25
+ }
26
+
27
+ export const linkedin = (options: LinkedInOptions) => {
28
+ const authorizationEndpoint =
29
+ "https://www.linkedin.com/oauth/v2/authorization";
30
+ const tokenEndpoint = "https://www.linkedin.com/oauth/v2/accessToken";
31
+
32
+ return {
33
+ id: "linkedin",
34
+ name: "Linkedin",
35
+ createAuthorizationURL: async ({
36
+ state,
37
+ scopes,
38
+ redirectURI,
39
+ loginHint,
40
+ }) => {
41
+ const _scopes = options.disableDefaultScope
42
+ ? []
43
+ : ["profile", "email", "openid"];
44
+ if (options.scope) _scopes.push(...options.scope);
45
+ if (scopes) _scopes.push(...scopes);
46
+ return await createAuthorizationURL({
47
+ id: "linkedin",
48
+ options,
49
+ authorizationEndpoint,
50
+ scopes: _scopes,
51
+ state,
52
+ loginHint,
53
+ redirectURI,
54
+ });
55
+ },
56
+ validateAuthorizationCode: async ({ code, redirectURI }) => {
57
+ return await validateAuthorizationCode({
58
+ code,
59
+ redirectURI,
60
+ options,
61
+ tokenEndpoint,
62
+ });
63
+ },
64
+ refreshAccessToken: options.refreshAccessToken
65
+ ? options.refreshAccessToken
66
+ : async (refreshToken) => {
67
+ return refreshAccessToken({
68
+ refreshToken,
69
+ options: {
70
+ clientId: options.clientId,
71
+ clientKey: options.clientKey,
72
+ clientSecret: options.clientSecret,
73
+ },
74
+ tokenEndpoint,
75
+ });
76
+ },
77
+ async getUserInfo(token) {
78
+ if (options.getUserInfo) {
79
+ return options.getUserInfo(token);
80
+ }
81
+ const { data: profile, error } = await betterFetch<LinkedInProfile>(
82
+ "https://api.linkedin.com/v2/userinfo",
83
+ {
84
+ method: "GET",
85
+ headers: {
86
+ Authorization: `Bearer ${token.accessToken}`,
87
+ },
88
+ },
89
+ );
90
+
91
+ if (error) {
92
+ return null;
93
+ }
94
+
95
+ const userMap = await options.mapProfileToUser?.(profile);
96
+ return {
97
+ user: {
98
+ id: profile.sub,
99
+ name: profile.name,
100
+ email: profile.email,
101
+ emailVerified: profile.email_verified || false,
102
+ image: profile.picture,
103
+ ...userMap,
104
+ },
105
+ data: profile,
106
+ };
107
+ },
108
+ options,
109
+ } satisfies OAuthProvider<LinkedInProfile>;
110
+ };
@@ -0,0 +1,259 @@
1
+ import { base64 } from "@better-auth/utils/base64";
2
+ import { betterFetch } from "@better-fetch/fetch";
3
+ import { decodeJwt } from "jose";
4
+ import { logger } from "../env";
5
+ import type { OAuthProvider, ProviderOptions } from "../oauth2";
6
+ import {
7
+ createAuthorizationURL,
8
+ refreshAccessToken,
9
+ validateAuthorizationCode,
10
+ } from "../oauth2";
11
+
12
+ /**
13
+ * @see [Microsoft Identity Platform - Optional claims reference](https://learn.microsoft.com/en-us/entra/identity-platform/optional-claims-reference)
14
+ */
15
+ export interface MicrosoftEntraIDProfile extends Record<string, any> {
16
+ /** Identifies the intended recipient of the token */
17
+ aud: string;
18
+ /** Identifies the issuer, or "authorization server" that constructs and returns the token */
19
+ iss: string;
20
+ /** Indicates when the authentication for the token occurred */
21
+ iat: Date;
22
+ /** Records the identity provider that authenticated the subject of the token */
23
+ idp: string;
24
+ /** Identifies the time before which the JWT can't be accepted for processing */
25
+ nbf: Date;
26
+ /** Identifies the expiration time on or after which the JWT can't be accepted for processing */
27
+ exp: Date;
28
+ /** Code hash included in ID tokens when issued with an OAuth 2.0 authorization code */
29
+ c_hash: string;
30
+ /** Access token hash included in ID tokens when issued with an OAuth 2.0 access token */
31
+ at_hash: string;
32
+ /** Internal claim used to record data for token reuse */
33
+ aio: string;
34
+ /** The primary username that represents the user */
35
+ preferred_username: string;
36
+ /** User's email address */
37
+ email: string;
38
+ /** Human-readable value that identifies the subject of the token */
39
+ name: string;
40
+ /** Matches the parameter included in the original authorize request */
41
+ nonce: string;
42
+ /** User's profile picture */
43
+ picture: string;
44
+ /** Immutable identifier for the user account */
45
+ oid: string;
46
+ /** Set of roles assigned to the user */
47
+ roles: string[];
48
+ /** Internal claim used to revalidate tokens */
49
+ rh: string;
50
+ /** Subject identifier - unique to application ID */
51
+ sub: string;
52
+ /** Tenant ID the user is signing in to */
53
+ tid: string;
54
+ /** Unique identifier for a session */
55
+ sid: string;
56
+ /** Token identifier claim */
57
+ uti: string;
58
+ /** Indicates if user is in at least one group */
59
+ hasgroups: boolean;
60
+ /** User account status in tenant (0 = member, 1 = guest) */
61
+ acct: 0 | 1;
62
+ /** Auth Context IDs */
63
+ acrs: string;
64
+ /** Time when the user last authenticated */
65
+ auth_time: Date;
66
+ /** User's country/region */
67
+ ctry: string;
68
+ /** IP address of requesting client when inside VNET */
69
+ fwd: string;
70
+ /** Group claims */
71
+ groups: string;
72
+ /** Login hint for SSO */
73
+ login_hint: string;
74
+ /** Resource tenant's country/region */
75
+ tenant_ctry: string;
76
+ /** Region of the resource tenant */
77
+ tenant_region_scope: string;
78
+ /** UserPrincipalName */
79
+ upn: string;
80
+ /** User's verified primary email addresses */
81
+ verified_primary_email: string[];
82
+ /** User's verified secondary email addresses */
83
+ verified_secondary_email: string[];
84
+ /** Whether the user's email is verified (optional claim, must be configured in app registration) */
85
+ email_verified?: boolean | undefined;
86
+ /** VNET specifier information */
87
+ vnet: string;
88
+ /** Client Capabilities */
89
+ xms_cc: string;
90
+ /** Whether user's email domain is verified */
91
+ xms_edov: boolean;
92
+ /** Preferred data location for Multi-Geo tenants */
93
+ xms_pdl: string;
94
+ /** User preferred language */
95
+ xms_pl: string;
96
+ /** Tenant preferred language */
97
+ xms_tpl: string;
98
+ /** Zero-touch Deployment ID */
99
+ ztdid: string;
100
+ /** IP Address */
101
+ ipaddr: string;
102
+ /** On-premises Security Identifier */
103
+ onprem_sid: string;
104
+ /** Password Expiration Time */
105
+ pwd_exp: number;
106
+ /** Change Password URL */
107
+ pwd_url: string;
108
+ /** Inside Corporate Network flag */
109
+ in_corp: string;
110
+ /** User's family name/surname */
111
+ family_name: string;
112
+ /** User's given/first name */
113
+ given_name: string;
114
+ }
115
+
116
+ export interface MicrosoftOptions
117
+ extends ProviderOptions<MicrosoftEntraIDProfile> {
118
+ clientId: string;
119
+ /**
120
+ * The tenant ID of the Microsoft account
121
+ * @default "common"
122
+ */
123
+ tenantId?: string | undefined;
124
+ /**
125
+ * The authentication authority URL. Use the default "https://login.microsoftonline.com" for standard Entra ID or "https://<tenant-id>.ciamlogin.com" for CIAM scenarios.
126
+ * @default "https://login.microsoftonline.com"
127
+ */
128
+ authority?: string | undefined;
129
+ /**
130
+ * The size of the profile photo
131
+ * @default 48
132
+ */
133
+ profilePhotoSize?:
134
+ | (48 | 64 | 96 | 120 | 240 | 360 | 432 | 504 | 648)
135
+ | undefined;
136
+ /**
137
+ * Disable profile photo
138
+ */
139
+ disableProfilePhoto?: boolean | undefined;
140
+ }
141
+
142
+ export const microsoft = (options: MicrosoftOptions) => {
143
+ const tenant = options.tenantId || "common";
144
+ const authority = options.authority || "https://login.microsoftonline.com";
145
+ const authorizationEndpoint = `${authority}/${tenant}/oauth2/v2.0/authorize`;
146
+ const tokenEndpoint = `${authority}/${tenant}/oauth2/v2.0/token`;
147
+ return {
148
+ id: "microsoft",
149
+ name: "Microsoft EntraID",
150
+ createAuthorizationURL(data) {
151
+ const scopes = options.disableDefaultScope
152
+ ? []
153
+ : ["openid", "profile", "email", "User.Read", "offline_access"];
154
+ if (options.scope) scopes.push(...options.scope);
155
+ if (data.scopes) scopes.push(...data.scopes);
156
+ return createAuthorizationURL({
157
+ id: "microsoft",
158
+ options,
159
+ authorizationEndpoint,
160
+ state: data.state,
161
+ codeVerifier: data.codeVerifier,
162
+ scopes,
163
+ redirectURI: data.redirectURI,
164
+ prompt: options.prompt,
165
+ loginHint: data.loginHint,
166
+ });
167
+ },
168
+ validateAuthorizationCode({ code, codeVerifier, redirectURI }) {
169
+ return validateAuthorizationCode({
170
+ code,
171
+ codeVerifier,
172
+ redirectURI,
173
+ options,
174
+ tokenEndpoint,
175
+ });
176
+ },
177
+ async getUserInfo(token) {
178
+ if (options.getUserInfo) {
179
+ return options.getUserInfo(token);
180
+ }
181
+ if (!token.idToken) {
182
+ return null;
183
+ }
184
+ const user = decodeJwt(token.idToken) as MicrosoftEntraIDProfile;
185
+ const profilePhotoSize = options.profilePhotoSize || 48;
186
+ await betterFetch<ArrayBuffer>(
187
+ `https://graph.microsoft.com/v1.0/me/photos/${profilePhotoSize}x${profilePhotoSize}/$value`,
188
+ {
189
+ headers: {
190
+ Authorization: `Bearer ${token.accessToken}`,
191
+ },
192
+ async onResponse(context) {
193
+ if (options.disableProfilePhoto || !context.response.ok) {
194
+ return;
195
+ }
196
+ try {
197
+ const response = context.response.clone();
198
+ const pictureBuffer = await response.arrayBuffer();
199
+ const pictureBase64 = base64.encode(pictureBuffer);
200
+ user.picture = `data:image/jpeg;base64, ${pictureBase64}`;
201
+ } catch (e) {
202
+ logger.error(
203
+ e && typeof e === "object" && "name" in e
204
+ ? (e.name as string)
205
+ : "",
206
+ e,
207
+ );
208
+ }
209
+ },
210
+ },
211
+ );
212
+ const userMap = await options.mapProfileToUser?.(user);
213
+ // Microsoft Entra ID does NOT include email_verified claim by default.
214
+ // It must be configured as an optional claim in the app registration.
215
+ // We default to false when not provided for security consistency.
216
+ // We can also check verified_primary_email/verified_secondary_email arrays as fallback.
217
+ const emailVerified =
218
+ user.email_verified !== undefined
219
+ ? user.email_verified
220
+ : user.email &&
221
+ (user.verified_primary_email?.includes(user.email) ||
222
+ user.verified_secondary_email?.includes(user.email))
223
+ ? true
224
+ : false;
225
+ return {
226
+ user: {
227
+ id: user.sub,
228
+ name: user.name,
229
+ email: user.email,
230
+ image: user.picture,
231
+ emailVerified,
232
+ ...userMap,
233
+ },
234
+ data: user,
235
+ };
236
+ },
237
+ refreshAccessToken: options.refreshAccessToken
238
+ ? options.refreshAccessToken
239
+ : async (refreshToken) => {
240
+ const scopes = options.disableDefaultScope
241
+ ? []
242
+ : ["openid", "profile", "email", "User.Read", "offline_access"];
243
+ if (options.scope) scopes.push(...options.scope);
244
+
245
+ return refreshAccessToken({
246
+ refreshToken,
247
+ options: {
248
+ clientId: options.clientId,
249
+ clientSecret: options.clientSecret,
250
+ },
251
+ extraParams: {
252
+ scope: scopes.join(" "), // Include the scopes in request to microsoft
253
+ },
254
+ tokenEndpoint,
255
+ });
256
+ },
257
+ options,
258
+ } satisfies OAuthProvider;
259
+ };
@@ -0,0 +1,112 @@
1
+ import { betterFetch } from "@better-fetch/fetch";
2
+ import type { OAuthProvider, ProviderOptions } from "../oauth2";
3
+ import {
4
+ createAuthorizationURL,
5
+ refreshAccessToken,
6
+ validateAuthorizationCode,
7
+ } from "../oauth2";
8
+
9
+ export interface NaverProfile {
10
+ /** API response result code */
11
+ resultcode: string;
12
+ /** API response message */
13
+ message: string;
14
+ response: {
15
+ /** Unique Naver user identifier */
16
+ id: string;
17
+ /** User nickname */
18
+ nickname: string;
19
+ /** User real name */
20
+ name: string;
21
+ /** User email address */
22
+ email: string;
23
+ /** Gender (F: female, M: male, U: unknown) */
24
+ gender: string;
25
+ /** Age range */
26
+ age: string;
27
+ /** Birthday (MM-DD format) */
28
+ birthday: string;
29
+ /** Birth year */
30
+ birthyear: string;
31
+ /** Profile image URL */
32
+ profile_image: string;
33
+ /** Mobile phone number */
34
+ mobile: string;
35
+ };
36
+ }
37
+
38
+ export interface NaverOptions extends ProviderOptions<NaverProfile> {
39
+ clientId: string;
40
+ }
41
+
42
+ export const naver = (options: NaverOptions) => {
43
+ return {
44
+ id: "naver",
45
+ name: "Naver",
46
+ createAuthorizationURL({ state, scopes, redirectURI }) {
47
+ const _scopes = options.disableDefaultScope ? [] : ["profile", "email"];
48
+ if (options.scope) _scopes.push(...options.scope);
49
+ if (scopes) _scopes.push(...scopes);
50
+ return createAuthorizationURL({
51
+ id: "naver",
52
+ options,
53
+ authorizationEndpoint: "https://nid.naver.com/oauth2.0/authorize",
54
+ scopes: _scopes,
55
+ state,
56
+ redirectURI,
57
+ });
58
+ },
59
+ validateAuthorizationCode: async ({ code, redirectURI }) => {
60
+ return validateAuthorizationCode({
61
+ code,
62
+ redirectURI,
63
+ options,
64
+ tokenEndpoint: "https://nid.naver.com/oauth2.0/token",
65
+ });
66
+ },
67
+ refreshAccessToken: options.refreshAccessToken
68
+ ? options.refreshAccessToken
69
+ : async (refreshToken) => {
70
+ return refreshAccessToken({
71
+ refreshToken,
72
+ options: {
73
+ clientId: options.clientId,
74
+ clientKey: options.clientKey,
75
+ clientSecret: options.clientSecret,
76
+ },
77
+ tokenEndpoint: "https://nid.naver.com/oauth2.0/token",
78
+ });
79
+ },
80
+ async getUserInfo(token) {
81
+ if (options.getUserInfo) {
82
+ return options.getUserInfo(token);
83
+ }
84
+ const { data: profile, error } = await betterFetch<NaverProfile>(
85
+ "https://openapi.naver.com/v1/nid/me",
86
+ {
87
+ headers: {
88
+ Authorization: `Bearer ${token.accessToken}`,
89
+ },
90
+ },
91
+ );
92
+ if (error || !profile || profile.resultcode !== "00") {
93
+ return null;
94
+ }
95
+ const userMap = await options.mapProfileToUser?.(profile);
96
+ const res = profile.response || {};
97
+ const user = {
98
+ id: res.id,
99
+ name: res.name || res.nickname,
100
+ email: res.email,
101
+ image: res.profile_image,
102
+ emailVerified: false,
103
+ ...userMap,
104
+ };
105
+ return {
106
+ user,
107
+ data: profile,
108
+ };
109
+ },
110
+ options,
111
+ } satisfies OAuthProvider<NaverProfile>;
112
+ };
@@ -0,0 +1,108 @@
1
+ import { betterFetch } from "@better-fetch/fetch";
2
+ import type { OAuthProvider, ProviderOptions } from "../oauth2";
3
+ import {
4
+ createAuthorizationURL,
5
+ refreshAccessToken,
6
+ validateAuthorizationCode,
7
+ } from "../oauth2";
8
+
9
+ export interface NotionProfile {
10
+ object: "user";
11
+ id: string;
12
+ type: "person" | "bot";
13
+ name?: string | undefined;
14
+ avatar_url?: string | undefined;
15
+ person?:
16
+ | {
17
+ email?: string;
18
+ }
19
+ | undefined;
20
+ }
21
+
22
+ export interface NotionOptions extends ProviderOptions<NotionProfile> {
23
+ clientId: string;
24
+ }
25
+
26
+ export const notion = (options: NotionOptions) => {
27
+ const tokenEndpoint = "https://api.notion.com/v1/oauth/token";
28
+ return {
29
+ id: "notion",
30
+ name: "Notion",
31
+ createAuthorizationURL({ state, scopes, loginHint, redirectURI }) {
32
+ const _scopes: string[] = options.disableDefaultScope ? [] : [];
33
+ if (options.scope) _scopes.push(...options.scope);
34
+ if (scopes) _scopes.push(...scopes);
35
+ return createAuthorizationURL({
36
+ id: "notion",
37
+ options,
38
+ authorizationEndpoint: "https://api.notion.com/v1/oauth/authorize",
39
+ scopes: _scopes,
40
+ state,
41
+ redirectURI,
42
+ loginHint,
43
+ additionalParams: {
44
+ owner: "user",
45
+ },
46
+ });
47
+ },
48
+ validateAuthorizationCode: async ({ code, redirectURI }) => {
49
+ return validateAuthorizationCode({
50
+ code,
51
+ redirectURI,
52
+ options,
53
+ tokenEndpoint,
54
+ authentication: "basic",
55
+ });
56
+ },
57
+ refreshAccessToken: options.refreshAccessToken
58
+ ? options.refreshAccessToken
59
+ : async (refreshToken) => {
60
+ return refreshAccessToken({
61
+ refreshToken,
62
+ options: {
63
+ clientId: options.clientId,
64
+ clientKey: options.clientKey,
65
+ clientSecret: options.clientSecret,
66
+ },
67
+ tokenEndpoint,
68
+ });
69
+ },
70
+ async getUserInfo(token) {
71
+ if (options.getUserInfo) {
72
+ return options.getUserInfo(token);
73
+ }
74
+ const { data: profile, error } = await betterFetch<{
75
+ bot: {
76
+ owner: {
77
+ user: NotionProfile;
78
+ };
79
+ };
80
+ }>("https://api.notion.com/v1/users/me", {
81
+ headers: {
82
+ Authorization: `Bearer ${token.accessToken}`,
83
+ "Notion-Version": "2022-06-28",
84
+ },
85
+ });
86
+ if (error || !profile) {
87
+ return null;
88
+ }
89
+ const userProfile = profile.bot?.owner?.user;
90
+ if (!userProfile) {
91
+ return null;
92
+ }
93
+ const userMap = await options.mapProfileToUser?.(userProfile);
94
+ return {
95
+ user: {
96
+ id: userProfile.id,
97
+ name: userProfile.name || "Notion User",
98
+ email: userProfile.person?.email || null,
99
+ image: userProfile.avatar_url,
100
+ emailVerified: false,
101
+ ...userMap,
102
+ },
103
+ data: userProfile,
104
+ };
105
+ },
106
+ options,
107
+ } satisfies OAuthProvider<NotionProfile>;
108
+ };
@@ -0,0 +1,122 @@
1
+ import { decodeJwt } from "jose";
2
+ import { logger } from "../env";
3
+ import { BetterAuthError } from "../error";
4
+ import type { OAuthProvider, ProviderOptions } from "../oauth2";
5
+ import {
6
+ createAuthorizationURL,
7
+ refreshAccessToken,
8
+ validateAuthorizationCode,
9
+ } from "../oauth2";
10
+
11
+ export interface PaybinProfile {
12
+ sub: string;
13
+ email: string;
14
+ email_verified?: boolean | undefined;
15
+ name?: string | undefined;
16
+ preferred_username?: string | undefined;
17
+ picture?: string | undefined;
18
+ given_name?: string | undefined;
19
+ family_name?: string | undefined;
20
+ }
21
+
22
+ export interface PaybinOptions extends ProviderOptions<PaybinProfile> {
23
+ clientId: string;
24
+ /**
25
+ * The issuer URL of your Paybin OAuth server
26
+ * @default "https://idp.paybin.io"
27
+ */
28
+ issuer?: string | undefined;
29
+ }
30
+
31
+ export const paybin = (options: PaybinOptions) => {
32
+ const issuer = options.issuer || "https://idp.paybin.io";
33
+ const authorizationEndpoint = `${issuer}/oauth2/authorize`;
34
+ const tokenEndpoint = `${issuer}/oauth2/token`;
35
+
36
+ return {
37
+ id: "paybin",
38
+ name: "Paybin",
39
+ async createAuthorizationURL({
40
+ state,
41
+ scopes,
42
+ codeVerifier,
43
+ redirectURI,
44
+ loginHint,
45
+ }) {
46
+ if (!options.clientId || !options.clientSecret) {
47
+ logger.error(
48
+ "Client Id and Client Secret is required for Paybin. Make sure to provide them in the options.",
49
+ );
50
+ throw new BetterAuthError("CLIENT_ID_AND_SECRET_REQUIRED");
51
+ }
52
+ if (!codeVerifier) {
53
+ throw new BetterAuthError("codeVerifier is required for Paybin");
54
+ }
55
+ const _scopes = options.disableDefaultScope
56
+ ? []
57
+ : ["openid", "email", "profile"];
58
+ if (options.scope) _scopes.push(...options.scope);
59
+ if (scopes) _scopes.push(...scopes);
60
+ const url = await createAuthorizationURL({
61
+ id: "paybin",
62
+ options,
63
+ authorizationEndpoint,
64
+ scopes: _scopes,
65
+ state,
66
+ codeVerifier,
67
+ redirectURI,
68
+ prompt: options.prompt,
69
+ loginHint,
70
+ });
71
+ return url;
72
+ },
73
+ validateAuthorizationCode: async ({ code, codeVerifier, redirectURI }) => {
74
+ return validateAuthorizationCode({
75
+ code,
76
+ codeVerifier,
77
+ redirectURI,
78
+ options,
79
+ tokenEndpoint,
80
+ });
81
+ },
82
+ refreshAccessToken: options.refreshAccessToken
83
+ ? options.refreshAccessToken
84
+ : async (refreshToken) => {
85
+ return refreshAccessToken({
86
+ refreshToken,
87
+ options: {
88
+ clientId: options.clientId,
89
+ clientKey: options.clientKey,
90
+ clientSecret: options.clientSecret,
91
+ },
92
+ tokenEndpoint,
93
+ });
94
+ },
95
+ async getUserInfo(token) {
96
+ if (options.getUserInfo) {
97
+ return options.getUserInfo(token);
98
+ }
99
+ if (!token.idToken) {
100
+ return null;
101
+ }
102
+ const user = decodeJwt(token.idToken) as PaybinProfile;
103
+ const userMap = await options.mapProfileToUser?.(user);
104
+ return {
105
+ user: {
106
+ id: user.sub,
107
+ name:
108
+ user.name ||
109
+ user.preferred_username ||
110
+ (user.email ? user.email.split("@")[0] : "User") ||
111
+ "User",
112
+ email: user.email,
113
+ image: user.picture,
114
+ emailVerified: user.email_verified || false,
115
+ ...userMap,
116
+ },
117
+ data: user,
118
+ };
119
+ },
120
+ options,
121
+ } satisfies OAuthProvider<PaybinProfile>;
122
+ };