@draftlab/auth 0.15.1 → 0.16.0

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 (272) hide show
  1. package/dist/esm/allow.js +26 -0
  2. package/dist/esm/client.js +254 -0
  3. package/dist/esm/core.js +597 -0
  4. package/dist/esm/css.d.js +0 -0
  5. package/dist/esm/error.js +88 -0
  6. package/dist/esm/index.js +5 -0
  7. package/dist/esm/keys.js +126 -0
  8. package/dist/esm/mutex.js +53 -0
  9. package/dist/esm/pkce.js +87 -0
  10. package/dist/esm/provider/apple.js +15 -0
  11. package/dist/esm/provider/code.js +62 -0
  12. package/dist/esm/provider/discord.js +15 -0
  13. package/dist/esm/provider/facebook.js +15 -0
  14. package/dist/esm/provider/github.js +15 -0
  15. package/dist/esm/provider/gitlab.js +15 -0
  16. package/dist/esm/provider/google.js +16 -0
  17. package/dist/esm/provider/linkedin.js +15 -0
  18. package/dist/esm/provider/magiclink.js +83 -0
  19. package/dist/esm/provider/microsoft.js +15 -0
  20. package/dist/esm/provider/oauth2.js +130 -0
  21. package/dist/esm/provider/password.js +331 -0
  22. package/dist/esm/provider/provider.js +18 -0
  23. package/dist/esm/provider/reddit.js +15 -0
  24. package/dist/esm/provider/slack.js +15 -0
  25. package/dist/esm/provider/spotify.js +15 -0
  26. package/dist/esm/provider/twitch.js +15 -0
  27. package/dist/esm/provider/vercel.js +17 -0
  28. package/dist/esm/random.js +40 -0
  29. package/dist/esm/revocation.js +27 -0
  30. package/dist/esm/storage/memory.js +110 -0
  31. package/dist/esm/storage/storage.js +56 -0
  32. package/dist/esm/storage/turso.js +93 -0
  33. package/dist/esm/storage/unstorage.js +78 -0
  34. package/dist/esm/subject.js +7 -0
  35. package/dist/esm/themes/theme.js +115 -0
  36. package/dist/esm/toolkit/client.js +119 -0
  37. package/dist/esm/toolkit/index.js +25 -0
  38. package/dist/esm/toolkit/providers/facebook.js +11 -0
  39. package/dist/esm/toolkit/providers/github.js +11 -0
  40. package/dist/esm/toolkit/providers/google.js +11 -0
  41. package/dist/esm/toolkit/providers/strategy.js +0 -0
  42. package/dist/esm/toolkit/storage.js +81 -0
  43. package/dist/esm/toolkit/utils.js +18 -0
  44. package/dist/esm/types.js +0 -0
  45. package/dist/esm/ui/base.js +478 -0
  46. package/dist/esm/ui/code.js +186 -0
  47. package/dist/esm/ui/form.js +46 -0
  48. package/dist/esm/ui/icon.js +242 -0
  49. package/dist/esm/ui/magiclink.js +158 -0
  50. package/dist/esm/ui/password.js +435 -0
  51. package/dist/esm/ui/select.js +102 -0
  52. package/dist/esm/util.js +59 -0
  53. package/dist/{allow.d.mts → types/allow.d.ts} +9 -11
  54. package/dist/types/allow.d.ts.map +1 -0
  55. package/dist/types/client.d.ts +462 -0
  56. package/dist/types/client.d.ts.map +1 -0
  57. package/dist/types/core.d.ts +113 -0
  58. package/dist/types/core.d.ts.map +1 -0
  59. package/dist/{error.d.mts → types/error.d.ts} +95 -97
  60. package/dist/types/error.d.ts.map +1 -0
  61. package/dist/types/index.d.ts +2 -0
  62. package/dist/types/index.d.ts.map +1 -0
  63. package/dist/{keys.d.mts → types/keys.d.ts} +20 -23
  64. package/dist/types/keys.d.ts.map +1 -0
  65. package/dist/types/mutex.d.ts +42 -0
  66. package/dist/types/mutex.d.ts.map +1 -0
  67. package/dist/{pkce.d.mts → types/pkce.d.ts} +10 -11
  68. package/dist/types/pkce.d.ts.map +1 -0
  69. package/dist/types/provider/apple.d.ts +197 -0
  70. package/dist/types/provider/apple.d.ts.map +1 -0
  71. package/dist/types/provider/code.d.ts +288 -0
  72. package/dist/types/provider/code.d.ts.map +1 -0
  73. package/dist/types/provider/discord.d.ts +206 -0
  74. package/dist/types/provider/discord.d.ts.map +1 -0
  75. package/dist/types/provider/facebook.d.ts +200 -0
  76. package/dist/types/provider/facebook.d.ts.map +1 -0
  77. package/dist/types/provider/github.d.ts +220 -0
  78. package/dist/types/provider/github.d.ts.map +1 -0
  79. package/dist/types/provider/gitlab.d.ts +180 -0
  80. package/dist/types/provider/gitlab.d.ts.map +1 -0
  81. package/dist/types/provider/google.d.ts +158 -0
  82. package/dist/types/provider/google.d.ts.map +1 -0
  83. package/dist/types/provider/linkedin.d.ts +190 -0
  84. package/dist/types/provider/linkedin.d.ts.map +1 -0
  85. package/dist/types/provider/magiclink.d.ts +141 -0
  86. package/dist/types/provider/magiclink.d.ts.map +1 -0
  87. package/dist/types/provider/microsoft.d.ts +247 -0
  88. package/dist/types/provider/microsoft.d.ts.map +1 -0
  89. package/dist/types/provider/oauth2.d.ts +229 -0
  90. package/dist/types/provider/oauth2.d.ts.map +1 -0
  91. package/dist/types/provider/password.d.ts +408 -0
  92. package/dist/types/provider/password.d.ts.map +1 -0
  93. package/dist/types/provider/provider.d.ts +226 -0
  94. package/dist/types/provider/provider.d.ts.map +1 -0
  95. package/dist/types/provider/reddit.d.ts +159 -0
  96. package/dist/types/provider/reddit.d.ts.map +1 -0
  97. package/dist/types/provider/slack.d.ts +171 -0
  98. package/dist/types/provider/slack.d.ts.map +1 -0
  99. package/dist/types/provider/spotify.d.ts +168 -0
  100. package/dist/types/provider/spotify.d.ts.map +1 -0
  101. package/dist/types/provider/twitch.d.ts +163 -0
  102. package/dist/types/provider/twitch.d.ts.map +1 -0
  103. package/dist/types/provider/vercel.d.ts +294 -0
  104. package/dist/types/provider/vercel.d.ts.map +1 -0
  105. package/dist/{random.d.mts → types/random.d.ts} +4 -6
  106. package/dist/types/random.d.ts.map +1 -0
  107. package/dist/types/revocation.d.ts +76 -0
  108. package/dist/types/revocation.d.ts.map +1 -0
  109. package/dist/{storage/memory.d.mts → types/storage/memory.d.ts} +17 -20
  110. package/dist/types/storage/memory.d.ts.map +1 -0
  111. package/dist/types/storage/storage.d.ts +177 -0
  112. package/dist/types/storage/storage.d.ts.map +1 -0
  113. package/dist/{storage/turso.d.mts → types/storage/turso.d.ts} +4 -7
  114. package/dist/types/storage/turso.d.ts.map +1 -0
  115. package/dist/{storage/unstorage.d.mts → types/storage/unstorage.d.ts} +12 -10
  116. package/dist/types/storage/unstorage.d.ts.map +1 -0
  117. package/dist/types/subject.d.ts +115 -0
  118. package/dist/types/subject.d.ts.map +1 -0
  119. package/dist/types/themes/theme.d.ts +207 -0
  120. package/dist/types/themes/theme.d.ts.map +1 -0
  121. package/dist/types/toolkit/client.d.ts +235 -0
  122. package/dist/types/toolkit/client.d.ts.map +1 -0
  123. package/dist/types/toolkit/index.d.ts +45 -0
  124. package/dist/types/toolkit/index.d.ts.map +1 -0
  125. package/dist/types/toolkit/providers/facebook.d.ts +8 -0
  126. package/dist/types/toolkit/providers/facebook.d.ts.map +1 -0
  127. package/dist/types/toolkit/providers/github.d.ts +8 -0
  128. package/dist/types/toolkit/providers/github.d.ts.map +1 -0
  129. package/dist/types/toolkit/providers/google.d.ts +8 -0
  130. package/dist/types/toolkit/providers/google.d.ts.map +1 -0
  131. package/dist/types/toolkit/providers/strategy.d.ts +38 -0
  132. package/dist/types/toolkit/providers/strategy.d.ts.map +1 -0
  133. package/dist/{toolkit/storage.d.mts → types/toolkit/storage.d.ts} +37 -39
  134. package/dist/types/toolkit/storage.d.ts.map +1 -0
  135. package/dist/{toolkit/utils.d.mts → types/toolkit/utils.d.ts} +2 -4
  136. package/dist/types/toolkit/utils.d.ts.map +1 -0
  137. package/dist/types/types.d.ts +92 -0
  138. package/dist/types/types.d.ts.map +1 -0
  139. package/dist/types/ui/base.d.ts +18 -0
  140. package/dist/types/ui/base.d.ts.map +1 -0
  141. package/dist/types/ui/code.d.ts +43 -0
  142. package/dist/types/ui/code.d.ts.map +1 -0
  143. package/dist/types/ui/form.d.ts +24 -0
  144. package/dist/types/ui/form.d.ts.map +1 -0
  145. package/dist/types/ui/icon.d.ts +60 -0
  146. package/dist/types/ui/icon.d.ts.map +1 -0
  147. package/dist/types/ui/magiclink.d.ts +41 -0
  148. package/dist/types/ui/magiclink.d.ts.map +1 -0
  149. package/dist/types/ui/password.d.ts +43 -0
  150. package/dist/types/ui/password.d.ts.map +1 -0
  151. package/dist/types/ui/select.d.ts +33 -0
  152. package/dist/types/ui/select.d.ts.map +1 -0
  153. package/dist/{util.d.mts → types/util.d.ts} +11 -12
  154. package/dist/types/util.d.ts.map +1 -0
  155. package/package.json +10 -16
  156. package/dist/adapters/node.d.mts +0 -17
  157. package/dist/adapters/node.mjs +0 -69
  158. package/dist/allow.mjs +0 -63
  159. package/dist/client.d.mts +0 -462
  160. package/dist/client.mjs +0 -284
  161. package/dist/core.d.mts +0 -109
  162. package/dist/core.mjs +0 -595
  163. package/dist/error.mjs +0 -237
  164. package/dist/index.d.mts +0 -2
  165. package/dist/index.mjs +0 -3
  166. package/dist/keys.mjs +0 -146
  167. package/dist/mutex.d.mts +0 -44
  168. package/dist/mutex.mjs +0 -110
  169. package/dist/pkce.mjs +0 -157
  170. package/dist/provider/apple.d.mts +0 -110
  171. package/dist/provider/apple.mjs +0 -164
  172. package/dist/provider/code.d.mts +0 -218
  173. package/dist/provider/code.mjs +0 -246
  174. package/dist/provider/discord.d.mts +0 -145
  175. package/dist/provider/discord.mjs +0 -156
  176. package/dist/provider/facebook.d.mts +0 -141
  177. package/dist/provider/facebook.mjs +0 -150
  178. package/dist/provider/github.d.mts +0 -139
  179. package/dist/provider/github.mjs +0 -169
  180. package/dist/provider/gitlab.d.mts +0 -105
  181. package/dist/provider/gitlab.mjs +0 -147
  182. package/dist/provider/google.d.mts +0 -111
  183. package/dist/provider/google.mjs +0 -109
  184. package/dist/provider/linkedin.d.mts +0 -131
  185. package/dist/provider/linkedin.mjs +0 -142
  186. package/dist/provider/magiclink.d.mts +0 -79
  187. package/dist/provider/magiclink.mjs +0 -143
  188. package/dist/provider/microsoft.d.mts +0 -177
  189. package/dist/provider/microsoft.mjs +0 -177
  190. package/dist/provider/oauth2.d.mts +0 -175
  191. package/dist/provider/oauth2.mjs +0 -222
  192. package/dist/provider/passkey.d.mts +0 -103
  193. package/dist/provider/passkey.mjs +0 -320
  194. package/dist/provider/password.d.mts +0 -384
  195. package/dist/provider/password.mjs +0 -363
  196. package/dist/provider/provider.d.mts +0 -225
  197. package/dist/provider/provider.mjs +0 -44
  198. package/dist/provider/reddit.d.mts +0 -106
  199. package/dist/provider/reddit.mjs +0 -127
  200. package/dist/provider/slack.d.mts +0 -113
  201. package/dist/provider/slack.mjs +0 -138
  202. package/dist/provider/spotify.d.mts +0 -112
  203. package/dist/provider/spotify.mjs +0 -135
  204. package/dist/provider/totp.d.mts +0 -111
  205. package/dist/provider/totp.mjs +0 -191
  206. package/dist/provider/twitch.d.mts +0 -107
  207. package/dist/provider/twitch.mjs +0 -131
  208. package/dist/provider/vercel.d.mts +0 -176
  209. package/dist/provider/vercel.mjs +0 -230
  210. package/dist/random.mjs +0 -86
  211. package/dist/revocation.d.mts +0 -54
  212. package/dist/revocation.mjs +0 -63
  213. package/dist/router/context.d.mts +0 -21
  214. package/dist/router/context.mjs +0 -193
  215. package/dist/router/cookies.d.mts +0 -8
  216. package/dist/router/cookies.mjs +0 -13
  217. package/dist/router/index.d.mts +0 -21
  218. package/dist/router/index.mjs +0 -107
  219. package/dist/router/matcher.d.mts +0 -15
  220. package/dist/router/matcher.mjs +0 -76
  221. package/dist/router/middleware/cors.d.mts +0 -15
  222. package/dist/router/middleware/cors.mjs +0 -114
  223. package/dist/router/safe-request.d.mts +0 -52
  224. package/dist/router/safe-request.mjs +0 -160
  225. package/dist/router/types.d.mts +0 -67
  226. package/dist/router/types.mjs +0 -1
  227. package/dist/router/variables.d.mts +0 -12
  228. package/dist/router/variables.mjs +0 -20
  229. package/dist/storage/memory.mjs +0 -125
  230. package/dist/storage/storage.d.mts +0 -179
  231. package/dist/storage/storage.mjs +0 -104
  232. package/dist/storage/turso.mjs +0 -117
  233. package/dist/storage/unstorage.mjs +0 -103
  234. package/dist/subject.d.mts +0 -61
  235. package/dist/subject.mjs +0 -36
  236. package/dist/themes/theme.d.mts +0 -209
  237. package/dist/themes/theme.mjs +0 -120
  238. package/dist/toolkit/client.d.mts +0 -168
  239. package/dist/toolkit/client.mjs +0 -209
  240. package/dist/toolkit/index.d.mts +0 -9
  241. package/dist/toolkit/index.mjs +0 -9
  242. package/dist/toolkit/providers/facebook.d.mts +0 -11
  243. package/dist/toolkit/providers/facebook.mjs +0 -16
  244. package/dist/toolkit/providers/github.d.mts +0 -11
  245. package/dist/toolkit/providers/github.mjs +0 -16
  246. package/dist/toolkit/providers/google.d.mts +0 -11
  247. package/dist/toolkit/providers/google.mjs +0 -20
  248. package/dist/toolkit/providers/strategy.d.mts +0 -40
  249. package/dist/toolkit/providers/strategy.mjs +0 -1
  250. package/dist/toolkit/storage.mjs +0 -157
  251. package/dist/toolkit/utils.mjs +0 -30
  252. package/dist/types.d.mts +0 -94
  253. package/dist/types.mjs +0 -1
  254. package/dist/ui/base.d.mts +0 -29
  255. package/dist/ui/base.mjs +0 -407
  256. package/dist/ui/code.d.mts +0 -42
  257. package/dist/ui/code.mjs +0 -173
  258. package/dist/ui/form.d.mts +0 -31
  259. package/dist/ui/form.mjs +0 -49
  260. package/dist/ui/icon.d.mts +0 -57
  261. package/dist/ui/icon.mjs +0 -247
  262. package/dist/ui/magiclink.d.mts +0 -40
  263. package/dist/ui/magiclink.mjs +0 -152
  264. package/dist/ui/passkey.d.mts +0 -26
  265. package/dist/ui/passkey.mjs +0 -323
  266. package/dist/ui/password.d.mts +0 -41
  267. package/dist/ui/password.mjs +0 -402
  268. package/dist/ui/select.d.mts +0 -33
  269. package/dist/ui/select.mjs +0 -98
  270. package/dist/ui/totp.d.mts +0 -33
  271. package/dist/ui/totp.mjs +0 -270
  272. package/dist/util.mjs +0 -128
@@ -1,111 +0,0 @@
1
- import { Provider } from "./provider.mjs";
2
- import { Oauth2UserData, Oauth2WrappedConfig } from "./oauth2.mjs";
3
-
4
- //#region src/provider/google.d.ts
5
- /**
6
- * Configuration options for Google OAuth 2.0 provider.
7
- * Extends the base OAuth 2.0 configuration with Google-specific defaults.
8
- */
9
- interface GoogleConfig extends Oauth2WrappedConfig {
10
- /**
11
- * Google OAuth 2.0 client ID from Google Cloud Console.
12
- *
13
- * @example
14
- * ```ts
15
- * {
16
- * clientID: "123456789-abc123.apps.googleusercontent.com"
17
- * }
18
- * ```
19
- */
20
- readonly clientID: string;
21
- /**
22
- * Google OAuth 2.0 client secret from Google Cloud Console.
23
- * Required for server-side OAuth 2.0 flows.
24
- *
25
- * @example
26
- * ```ts
27
- * {
28
- * clientSecret: process.env.GOOGLE_CLIENT_SECRET
29
- * }
30
- * ```
31
- */
32
- readonly clientSecret: string;
33
- /**
34
- * Google OAuth 2.0 scopes to request.
35
- * Common scopes include 'profile', 'email', and specific Google API scopes.
36
- *
37
- * @example
38
- * ```ts
39
- * {
40
- * scopes: [
41
- * "profile",
42
- * "email",
43
- * "https://www.googleapis.com/auth/calendar.readonly",
44
- * "https://www.googleapis.com/auth/drive.file"
45
- * ]
46
- * }
47
- * ```
48
- */
49
- readonly scopes: string[];
50
- /**
51
- * Additional query parameters for Google OAuth 2.0.
52
- * Useful for Google-specific options like hosted domain restrictions.
53
- *
54
- * @example
55
- * ```ts
56
- * {
57
- * query: {
58
- * hd: "mycompany.com", // Restrict to Google Workspace domain
59
- * access_type: "offline", // Request refresh token
60
- * prompt: "consent", // Force consent screen
61
- * include_granted_scopes: "true" // Incremental authorization
62
- * }
63
- * }
64
- * ```
65
- */
66
- readonly query?: Record<string, string>;
67
- }
68
- /**
69
- * Creates a Google OAuth 2.0 authentication provider.
70
- * Use this when you need access tokens to call Google APIs on behalf of the user.
71
- *
72
- * @param config - Google OAuth 2.0 configuration
73
- * @returns OAuth 2.0 provider configured for Google
74
- *
75
- * @example
76
- * ```ts
77
- * // Basic setup for user authentication
78
- * const basicGoogle = GoogleProvider({
79
- * clientID: process.env.GOOGLE_CLIENT_ID,
80
- * clientSecret: process.env.GOOGLE_CLIENT_SECRET
81
- * })
82
- *
83
- * // Advanced setup with API access
84
- * const advancedGoogle = GoogleProvider({
85
- * clientID: process.env.GOOGLE_CLIENT_ID,
86
- * clientSecret: process.env.GOOGLE_CLIENT_SECRET,
87
- * scopes: [
88
- * "profile",
89
- * "email",
90
- * "https://www.googleapis.com/auth/calendar.readonly",
91
- * "https://www.googleapis.com/auth/drive.file"
92
- * ],
93
- * query: {
94
- * access_type: "offline", // Get refresh token
95
- * prompt: "consent", // Force consent for refresh token
96
- * hd: "mycompany.com" // Restrict to company domain
97
- * }
98
- * })
99
- *
100
- * // Use the access token for API calls
101
- * success: async (ctx, value) => {
102
- * const accessToken = value.tokenset.access
103
- * const response = await fetch('https://www.googleapis.com/calendar/v3/calendars/primary/events', {
104
- * headers: { Authorization: `Bearer ${accessToken}` }
105
- * })
106
- * }
107
- * ```
108
- */
109
- declare const GoogleProvider: (config: GoogleConfig) => Provider<Oauth2UserData>;
110
- //#endregion
111
- export { GoogleConfig, GoogleProvider };
@@ -1,109 +0,0 @@
1
- import { Oauth2Provider } from "./oauth2.mjs";
2
-
3
- //#region src/provider/google.ts
4
- /**
5
- * Google OAuth 2.0 authentication provider for Draft Auth.
6
- * Provides access tokens for calling Google APIs on behalf of users.
7
- *
8
- * ## Quick Setup
9
- *
10
- * ```ts
11
- * import { GoogleProvider } from "@draftlab/auth/provider/google"
12
- *
13
- * export default issuer({
14
- * basePath: "/auth", // Important for callback URL
15
- * providers: {
16
- * google: GoogleProvider({
17
- * clientID: process.env.GOOGLE_CLIENT_ID,
18
- * clientSecret: process.env.GOOGLE_CLIENT_SECRET,
19
- * scopes: ["profile", "email", "https://www.googleapis.com/auth/calendar.readonly"]
20
- * })
21
- * }
22
- * })
23
- * ```
24
- *
25
- * **Callback URL Pattern**: `{baseURL}{basePath}/{provider}/callback`
26
- * - Development: `http://localhost:3000/auth/google/callback`
27
- * - Production: `https://yourapp.com/auth/google/callback`
28
- *
29
- * Register this URL in your Google Cloud Console OAuth 2.0 credentials.
30
- *
31
- * ## Configuration Options
32
- *
33
- * - Access tokens for Google API calls
34
- * - Refresh tokens for long-lived access
35
- * - Support for offline access
36
- * - Custom scopes for specific Google services
37
- *
38
- * ## User Data Access
39
- *
40
- * ```ts
41
- * success: async (ctx, value) => {
42
- * if (value.provider === "google") {
43
- * // Access token for API calls: value.tokenset.access
44
- * // Refresh token (if requested): value.tokenset.refresh
45
- * // Use the access token to call Google APIs
46
- * const response = await fetch('https://www.googleapis.com/oauth2/v2/userinfo', {
47
- * headers: { Authorization: `Bearer ${value.tokenset.access}` }
48
- * })
49
- * }
50
- * }
51
- * ```
52
- *
53
- * @packageDocumentation
54
- */
55
- /**
56
- * Creates a Google OAuth 2.0 authentication provider.
57
- * Use this when you need access tokens to call Google APIs on behalf of the user.
58
- *
59
- * @param config - Google OAuth 2.0 configuration
60
- * @returns OAuth 2.0 provider configured for Google
61
- *
62
- * @example
63
- * ```ts
64
- * // Basic setup for user authentication
65
- * const basicGoogle = GoogleProvider({
66
- * clientID: process.env.GOOGLE_CLIENT_ID,
67
- * clientSecret: process.env.GOOGLE_CLIENT_SECRET
68
- * })
69
- *
70
- * // Advanced setup with API access
71
- * const advancedGoogle = GoogleProvider({
72
- * clientID: process.env.GOOGLE_CLIENT_ID,
73
- * clientSecret: process.env.GOOGLE_CLIENT_SECRET,
74
- * scopes: [
75
- * "profile",
76
- * "email",
77
- * "https://www.googleapis.com/auth/calendar.readonly",
78
- * "https://www.googleapis.com/auth/drive.file"
79
- * ],
80
- * query: {
81
- * access_type: "offline", // Get refresh token
82
- * prompt: "consent", // Force consent for refresh token
83
- * hd: "mycompany.com" // Restrict to company domain
84
- * }
85
- * })
86
- *
87
- * // Use the access token for API calls
88
- * success: async (ctx, value) => {
89
- * const accessToken = value.tokenset.access
90
- * const response = await fetch('https://www.googleapis.com/calendar/v3/calendars/primary/events', {
91
- * headers: { Authorization: `Bearer ${accessToken}` }
92
- * })
93
- * }
94
- * ```
95
- */
96
- const GoogleProvider = (config) => {
97
- return Oauth2Provider({
98
- ...config,
99
- type: "google",
100
- endpoint: {
101
- authorization: "https://accounts.google.com/o/oauth2/v2/auth",
102
- token: "https://oauth2.googleapis.com/token",
103
- jwks: "https://www.googleapis.com/oauth2/v3/certs"
104
- }
105
- });
106
- };
107
-
108
- //#endregion
109
- export { GoogleProvider };
@@ -1,131 +0,0 @@
1
- import { Provider } from "./provider.mjs";
2
- import { Oauth2UserData, Oauth2WrappedConfig } from "./oauth2.mjs";
3
-
4
- //#region src/provider/linkedin.d.ts
5
- /**
6
- * Configuration options for LinkedIn OAuth 2.0 provider.
7
- * Extends the base OAuth 2.0 configuration with LinkedIn-specific documentation.
8
- */
9
- interface LinkedInConfig extends Oauth2WrappedConfig {
10
- /**
11
- * LinkedIn OAuth 2.0 client ID from LinkedIn Developer Console.
12
- * Found in your LinkedIn app settings.
13
- *
14
- * @example
15
- * ```ts
16
- * {
17
- * clientID: "78abc123456789"
18
- * }
19
- * ```
20
- */
21
- readonly clientID: string;
22
- /**
23
- * LinkedIn OAuth 2.0 client secret from LinkedIn Developer Console.
24
- * Keep this secure and never expose it to client-side code.
25
- *
26
- * @example
27
- * ```ts
28
- * {
29
- * clientSecret: process.env.LINKEDIN_CLIENT_SECRET
30
- * }
31
- * ```
32
- */
33
- readonly clientSecret: string;
34
- /**
35
- * LinkedIn OAuth scopes to request access for.
36
- * Determines what data and actions your app can access.
37
- *
38
- * @example
39
- * ```ts
40
- * {
41
- * scopes: [
42
- * "r_liteprofile", // Basic profile information
43
- * "r_emailaddress", // Email address
44
- * "w_member_social", // Share content on behalf of user
45
- * "r_organization_social" // Organization content access
46
- * ]
47
- * }
48
- * ```
49
- */
50
- readonly scopes: string[];
51
- /**
52
- * Additional query parameters for LinkedIn OAuth authorization.
53
- * Useful for LinkedIn-specific options.
54
- *
55
- * @example
56
- * ```ts
57
- * {
58
- * query: {
59
- * state: "custom-state-value" // Custom state parameter
60
- * }
61
- * }
62
- * ```
63
- */
64
- readonly query?: Record<string, string>;
65
- }
66
- /**
67
- * Creates a LinkedIn OAuth 2.0 authentication provider.
68
- * Use this when you need access tokens to call LinkedIn APIs on behalf of the user.
69
- *
70
- * @param config - LinkedIn OAuth 2.0 configuration
71
- * @returns OAuth 2.0 provider configured for LinkedIn
72
- *
73
- * @example
74
- * ```ts
75
- * // Basic LinkedIn authentication
76
- * const basicLinkedIn = LinkedInProvider({
77
- * clientID: process.env.LINKEDIN_CLIENT_ID,
78
- * clientSecret: process.env.LINKEDIN_CLIENT_SECRET
79
- * })
80
- *
81
- * // LinkedIn with specific scopes
82
- * const linkedInWithScopes = LinkedInProvider({
83
- * clientID: process.env.LINKEDIN_CLIENT_ID,
84
- * clientSecret: process.env.LINKEDIN_CLIENT_SECRET,
85
- * scopes: [
86
- * "r_liteprofile",
87
- * "r_emailaddress",
88
- * "w_member_social"
89
- * ]
90
- * })
91
- *
92
- * // Using the access token to fetch data
93
- * export default issuer({
94
- * providers: { linkedin: linkedInWithScopes },
95
- * success: async (ctx, value) => {
96
- * if (value.provider === "linkedin") {
97
- * const token = value.tokenset.access
98
- *
99
- * // Get user profile
100
- * const profileRes = await fetch('https://api.linkedin.com/v2/people/~', {
101
- * headers: { Authorization: `Bearer ${token}` }
102
- * })
103
- * const profile = await profileRes.json()
104
- *
105
- * // Get user email
106
- * const emailRes = await fetch('https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))', {
107
- * headers: { Authorization: `Bearer ${token}` }
108
- * })
109
- * const emailData = await emailRes.json()
110
- *
111
- * return ctx.subject("user", {
112
- * linkedinId: profile.id,
113
- * firstName: profile.localizedFirstName,
114
- * lastName: profile.localizedLastName,
115
- * email: emailData.elements[0]['handle~'].emailAddress,
116
- * profileUrl: `https://www.linkedin.com/in/${profile.vanityName || profile.id}`
117
- * })
118
- * }
119
- * }
120
- * })
121
- * ```
122
- *
123
- * **Callback URL Pattern**: `{baseURL}{basePath}/{provider}/callback`
124
- * - Development: `http://localhost:3000/auth/linkedin/callback`
125
- * - Production: `https://yourapp.com/auth/linkedin/callback`
126
- *
127
- * Register this URL in your LinkedIn Developer Portal.
128
- */
129
- declare const LinkedInProvider: (config: LinkedInConfig) => Provider<Oauth2UserData>;
130
- //#endregion
131
- export { LinkedInConfig, LinkedInProvider };
@@ -1,142 +0,0 @@
1
- import { Oauth2Provider } from "./oauth2.mjs";
2
-
3
- //#region src/provider/linkedin.ts
4
- /**
5
- * LinkedIn OAuth 2.0 authentication provider for Draft Auth.
6
- * Provides access tokens for calling LinkedIn APIs on behalf of users.
7
- *
8
- * ## Quick Setup
9
- *
10
- * ```ts
11
- * import { LinkedInProvider } from "@draftlab/auth/provider/linkedin"
12
- *
13
- * export default issuer({
14
- * basePath: "/auth", // Important for callback URL
15
- * providers: {
16
- * linkedin: LinkedInProvider({
17
- * clientID: process.env.LINKEDIN_CLIENT_ID,
18
- * clientSecret: process.env.LINKEDIN_CLIENT_SECRET,
19
- * scopes: ["r_liteprofile", "r_emailaddress", "w_member_social"]
20
- * })
21
- * }
22
- * })
23
- * ```
24
- *
25
- * **Callback URL Pattern**: `{baseURL}{basePath}/{provider}/callback`
26
- * - Development: `http://localhost:3000/auth/linkedin/callback`
27
- * - Production: `https://yourapp.com/auth/linkedin/callback`
28
- *
29
- * Register this URL in your LinkedIn Developer Portal.
30
- *
31
- * ## Common Scopes
32
- *
33
- * - `r_liteprofile` - Access to basic profile information
34
- * - `r_emailaddress` - Access to user's email address
35
- * - `r_basicprofile` - Access to full profile information (deprecated)
36
- * - `w_member_social` - Share content on behalf of user
37
- * - `r_organization_social` - Access to organization social content
38
- * - `rw_organization_admin` - Manage organization pages
39
- *
40
- * ## User Data Access
41
- *
42
- * ```ts
43
- * success: async (ctx, value) => {
44
- * if (value.provider === "linkedin") {
45
- * const accessToken = value.tokenset.access
46
- *
47
- * // Fetch user profile
48
- * const profileResponse = await fetch('https://api.linkedin.com/v2/people/~', {
49
- * headers: { Authorization: `Bearer ${accessToken}` }
50
- * })
51
- * const profile = await profileResponse.json()
52
- *
53
- * // Fetch user email (requires r_emailaddress scope)
54
- * const emailResponse = await fetch('https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))', {
55
- * headers: { Authorization: `Bearer ${accessToken}` }
56
- * })
57
- * const emailData = await emailResponse.json()
58
- *
59
- * // User info: profile.localizedFirstName + profile.localizedLastName
60
- * // Email: emailData.elements[0]['handle~'].emailAddress
61
- * }
62
- * }
63
- * ```
64
- *
65
- * @packageDocumentation
66
- */
67
- /**
68
- * Creates a LinkedIn OAuth 2.0 authentication provider.
69
- * Use this when you need access tokens to call LinkedIn APIs on behalf of the user.
70
- *
71
- * @param config - LinkedIn OAuth 2.0 configuration
72
- * @returns OAuth 2.0 provider configured for LinkedIn
73
- *
74
- * @example
75
- * ```ts
76
- * // Basic LinkedIn authentication
77
- * const basicLinkedIn = LinkedInProvider({
78
- * clientID: process.env.LINKEDIN_CLIENT_ID,
79
- * clientSecret: process.env.LINKEDIN_CLIENT_SECRET
80
- * })
81
- *
82
- * // LinkedIn with specific scopes
83
- * const linkedInWithScopes = LinkedInProvider({
84
- * clientID: process.env.LINKEDIN_CLIENT_ID,
85
- * clientSecret: process.env.LINKEDIN_CLIENT_SECRET,
86
- * scopes: [
87
- * "r_liteprofile",
88
- * "r_emailaddress",
89
- * "w_member_social"
90
- * ]
91
- * })
92
- *
93
- * // Using the access token to fetch data
94
- * export default issuer({
95
- * providers: { linkedin: linkedInWithScopes },
96
- * success: async (ctx, value) => {
97
- * if (value.provider === "linkedin") {
98
- * const token = value.tokenset.access
99
- *
100
- * // Get user profile
101
- * const profileRes = await fetch('https://api.linkedin.com/v2/people/~', {
102
- * headers: { Authorization: `Bearer ${token}` }
103
- * })
104
- * const profile = await profileRes.json()
105
- *
106
- * // Get user email
107
- * const emailRes = await fetch('https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))', {
108
- * headers: { Authorization: `Bearer ${token}` }
109
- * })
110
- * const emailData = await emailRes.json()
111
- *
112
- * return ctx.subject("user", {
113
- * linkedinId: profile.id,
114
- * firstName: profile.localizedFirstName,
115
- * lastName: profile.localizedLastName,
116
- * email: emailData.elements[0]['handle~'].emailAddress,
117
- * profileUrl: `https://www.linkedin.com/in/${profile.vanityName || profile.id}`
118
- * })
119
- * }
120
- * }
121
- * })
122
- * ```
123
- *
124
- * **Callback URL Pattern**: `{baseURL}{basePath}/{provider}/callback`
125
- * - Development: `http://localhost:3000/auth/linkedin/callback`
126
- * - Production: `https://yourapp.com/auth/linkedin/callback`
127
- *
128
- * Register this URL in your LinkedIn Developer Portal.
129
- */
130
- const LinkedInProvider = (config) => {
131
- return Oauth2Provider({
132
- ...config,
133
- type: "linkedin",
134
- endpoint: {
135
- authorization: "https://www.linkedin.com/oauth/v2/authorization",
136
- token: "https://www.linkedin.com/oauth/v2/accessToken"
137
- }
138
- });
139
- };
140
-
141
- //#endregion
142
- export { LinkedInProvider };
@@ -1,79 +0,0 @@
1
- import { Provider } from "./provider.mjs";
2
-
3
- //#region src/provider/magiclink.d.ts
4
- /**
5
- * Configuration options for the Magic Link authentication provider.
6
- *
7
- * @template Claims - Type of claims collected during authentication (email, phone, etc.)
8
- */
9
- interface MagicLinkConfig<Claims extends Record<string, string> = Record<string, string>> {
10
- /**
11
- * Token expiration time in seconds.
12
- * After this time, the magic link becomes invalid.
13
- *
14
- * @default 900 (15 minutes)
15
- */
16
- readonly expiry?: number;
17
- /**
18
- * Request handler for rendering the magic link UI.
19
- * Handles both the initial claim collection and "check your email" screens.
20
- *
21
- * @param req - The HTTP request object
22
- * @param state - Current authentication state
23
- * @param form - Form data from POST requests (if any)
24
- * @param error - Authentication error to display (if any)
25
- * @returns Promise resolving to the authentication page response
26
- */
27
- request: (req: Request, state: MagicLinkState, form?: FormData, error?: MagicLinkError) => Promise<Response>;
28
- /**
29
- * Callback for sending magic links to users.
30
- * Should handle delivery via email, SMS, or other communication channels.
31
- *
32
- * @param claims - User claims containing contact information
33
- * @param magicUrl - The magic link URL to send
34
- * @returns Promise resolving to undefined on success, or error object on failure
35
- */
36
- sendLink: (claims: Claims, magicUrl: string) => Promise<MagicLinkError | undefined>;
37
- }
38
- /**
39
- * Authentication flow states for the magic link provider.
40
- * The provider transitions between these states during authentication.
41
- */
42
- type MagicLinkState = {
43
- /** Initial state: user enters their claims (email, phone, etc.) */readonly type: "start";
44
- } | {
45
- /** Link sent state: user checks their email/phone */readonly type: "sent"; /** Whether this is a resend request */
46
- readonly resend?: boolean; /** The secure token for verification */
47
- readonly token: string; /** User claims collected during the start phase */
48
- readonly claims: Record<string, string>;
49
- };
50
- /**
51
- * Possible errors during magic link authentication.
52
- */
53
- type MagicLinkError = {
54
- /** The magic link is invalid or expired */readonly type: "invalid_link";
55
- } | {
56
- /** A user claim is invalid or missing */readonly type: "invalid_claim"; /** The claim field that failed validation */
57
- readonly key: string; /** The invalid value or error description */
58
- readonly value: string;
59
- };
60
- /**
61
- * User data returned by successful magic link authentication.
62
- *
63
- * @template Claims - Type of claims collected during authentication
64
- */
65
- interface MagicLinkUserData<Claims extends Record<string, string> = Record<string, string>> {
66
- /** The verified claims collected during authentication */
67
- readonly claims: Claims;
68
- }
69
- /**
70
- * Creates a Magic Link authentication provider.
71
- * Implements a flexible claim-based authentication flow with magic link verification.
72
- *
73
- * @template Claims - Type of claims to collect (email, phone, username, etc.)
74
- * @param config - Magic Link provider configuration
75
- * @returns Provider instance implementing magic link authentication
76
- */
77
- declare const MagicLinkProvider: <Claims extends Record<string, string> = Record<string, string>>(config: MagicLinkConfig<Claims>) => Provider<MagicLinkUserData<Claims>>;
78
- //#endregion
79
- export { MagicLinkConfig, MagicLinkError, MagicLinkProvider, MagicLinkState, MagicLinkUserData };