@draftlab/auth 0.15.0 → 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 -24
  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 -21
  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 -8
  114. package/dist/types/storage/turso.d.ts.map +1 -0
  115. package/dist/{storage/unstorage.d.mts → types/storage/unstorage.d.ts} +12 -11
  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 -13
  154. package/dist/types/util.d.ts.map +1 -0
  155. package/package.json +10 -16
  156. package/dist/adapters/node.d.mts +0 -18
  157. package/dist/adapters/node.mjs +0 -69
  158. package/dist/allow.mjs +0 -63
  159. package/dist/client.d.mts +0 -456
  160. package/dist/client.mjs +0 -283
  161. package/dist/core.d.mts +0 -110
  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 -111
  171. package/dist/provider/apple.mjs +0 -164
  172. package/dist/provider/code.d.mts +0 -228
  173. package/dist/provider/code.mjs +0 -246
  174. package/dist/provider/discord.d.mts +0 -146
  175. package/dist/provider/discord.mjs +0 -156
  176. package/dist/provider/facebook.d.mts +0 -142
  177. package/dist/provider/facebook.mjs +0 -150
  178. package/dist/provider/github.d.mts +0 -140
  179. package/dist/provider/github.mjs +0 -169
  180. package/dist/provider/gitlab.d.mts +0 -106
  181. package/dist/provider/gitlab.mjs +0 -147
  182. package/dist/provider/google.d.mts +0 -112
  183. package/dist/provider/google.mjs +0 -109
  184. package/dist/provider/linkedin.d.mts +0 -132
  185. package/dist/provider/linkedin.mjs +0 -142
  186. package/dist/provider/magiclink.d.mts +0 -89
  187. package/dist/provider/magiclink.mjs +0 -143
  188. package/dist/provider/microsoft.d.mts +0 -178
  189. package/dist/provider/microsoft.mjs +0 -177
  190. package/dist/provider/oauth2.d.mts +0 -176
  191. package/dist/provider/oauth2.mjs +0 -222
  192. package/dist/provider/passkey.d.mts +0 -104
  193. package/dist/provider/passkey.mjs +0 -320
  194. package/dist/provider/password.d.mts +0 -412
  195. package/dist/provider/password.mjs +0 -363
  196. package/dist/provider/provider.d.mts +0 -227
  197. package/dist/provider/provider.mjs +0 -44
  198. package/dist/provider/reddit.d.mts +0 -107
  199. package/dist/provider/reddit.mjs +0 -127
  200. package/dist/provider/slack.d.mts +0 -114
  201. package/dist/provider/slack.mjs +0 -138
  202. package/dist/provider/spotify.d.mts +0 -113
  203. package/dist/provider/spotify.mjs +0 -135
  204. package/dist/provider/totp.d.mts +0 -112
  205. package/dist/provider/totp.mjs +0 -191
  206. package/dist/provider/twitch.d.mts +0 -108
  207. package/dist/provider/twitch.mjs +0 -131
  208. package/dist/provider/vercel.d.mts +0 -177
  209. package/dist/provider/vercel.mjs +0 -230
  210. package/dist/random.mjs +0 -86
  211. package/dist/revocation.d.mts +0 -55
  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 -62
  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 -169
  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 -12
  243. package/dist/toolkit/providers/facebook.mjs +0 -16
  244. package/dist/toolkit/providers/github.d.mts +0 -12
  245. package/dist/toolkit/providers/github.mjs +0 -16
  246. package/dist/toolkit/providers/google.d.mts +0 -12
  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 -30
  255. package/dist/ui/base.mjs +0 -407
  256. package/dist/ui/code.d.mts +0 -43
  257. package/dist/ui/code.mjs +0 -173
  258. package/dist/ui/form.d.mts +0 -32
  259. package/dist/ui/form.mjs +0 -49
  260. package/dist/ui/icon.d.mts +0 -58
  261. package/dist/ui/icon.mjs +0 -247
  262. package/dist/ui/magiclink.d.mts +0 -41
  263. package/dist/ui/magiclink.mjs +0 -152
  264. package/dist/ui/passkey.d.mts +0 -27
  265. package/dist/ui/passkey.mjs +0 -323
  266. package/dist/ui/password.d.mts +0 -42
  267. package/dist/ui/password.mjs +0 -402
  268. package/dist/ui/select.d.mts +0 -34
  269. package/dist/ui/select.mjs +0 -98
  270. package/dist/ui/totp.d.mts +0 -34
  271. package/dist/ui/totp.mjs +0 -270
  272. package/dist/util.mjs +0 -128
@@ -0,0 +1,190 @@
1
+ /**
2
+ * LinkedIn OAuth 2.0 authentication provider for Draft Auth.
3
+ * Provides access tokens for calling LinkedIn APIs on behalf of users.
4
+ *
5
+ * ## Quick Setup
6
+ *
7
+ * ```ts
8
+ * import { LinkedInProvider } from "@draftlab/auth/provider/linkedin"
9
+ *
10
+ * export default issuer({
11
+ * basePath: "/auth", // Important for callback URL
12
+ * providers: {
13
+ * linkedin: LinkedInProvider({
14
+ * clientID: process.env.LINKEDIN_CLIENT_ID,
15
+ * clientSecret: process.env.LINKEDIN_CLIENT_SECRET,
16
+ * scopes: ["r_liteprofile", "r_emailaddress", "w_member_social"]
17
+ * })
18
+ * }
19
+ * })
20
+ * ```
21
+ *
22
+ * **Callback URL Pattern**: `{baseURL}{basePath}/{provider}/callback`
23
+ * - Development: `http://localhost:3000/auth/linkedin/callback`
24
+ * - Production: `https://yourapp.com/auth/linkedin/callback`
25
+ *
26
+ * Register this URL in your LinkedIn Developer Portal.
27
+ *
28
+ * ## Common Scopes
29
+ *
30
+ * - `r_liteprofile` - Access to basic profile information
31
+ * - `r_emailaddress` - Access to user's email address
32
+ * - `r_basicprofile` - Access to full profile information (deprecated)
33
+ * - `w_member_social` - Share content on behalf of user
34
+ * - `r_organization_social` - Access to organization social content
35
+ * - `rw_organization_admin` - Manage organization pages
36
+ *
37
+ * ## User Data Access
38
+ *
39
+ * ```ts
40
+ * success: async (ctx, value) => {
41
+ * if (value.provider === "linkedin") {
42
+ * const accessToken = value.tokenset.access
43
+ *
44
+ * // Fetch user profile
45
+ * const profileResponse = await fetch('https://api.linkedin.com/v2/people/~', {
46
+ * headers: { Authorization: `Bearer ${accessToken}` }
47
+ * })
48
+ * const profile = await profileResponse.json()
49
+ *
50
+ * // Fetch user email (requires r_emailaddress scope)
51
+ * const emailResponse = await fetch('https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))', {
52
+ * headers: { Authorization: `Bearer ${accessToken}` }
53
+ * })
54
+ * const emailData = await emailResponse.json()
55
+ *
56
+ * // User info: profile.localizedFirstName + profile.localizedLastName
57
+ * // Email: emailData.elements[0]['handle~'].emailAddress
58
+ * }
59
+ * }
60
+ * ```
61
+ *
62
+ * @packageDocumentation
63
+ */
64
+ import { type Oauth2WrappedConfig } from "./oauth2";
65
+ /**
66
+ * Configuration options for LinkedIn OAuth 2.0 provider.
67
+ * Extends the base OAuth 2.0 configuration with LinkedIn-specific documentation.
68
+ */
69
+ export interface LinkedInConfig extends Oauth2WrappedConfig {
70
+ /**
71
+ * LinkedIn OAuth 2.0 client ID from LinkedIn Developer Console.
72
+ * Found in your LinkedIn app settings.
73
+ *
74
+ * @example
75
+ * ```ts
76
+ * {
77
+ * clientID: "78abc123456789"
78
+ * }
79
+ * ```
80
+ */
81
+ readonly clientID: string;
82
+ /**
83
+ * LinkedIn OAuth 2.0 client secret from LinkedIn Developer Console.
84
+ * Keep this secure and never expose it to client-side code.
85
+ *
86
+ * @example
87
+ * ```ts
88
+ * {
89
+ * clientSecret: process.env.LINKEDIN_CLIENT_SECRET
90
+ * }
91
+ * ```
92
+ */
93
+ readonly clientSecret: string;
94
+ /**
95
+ * LinkedIn OAuth scopes to request access for.
96
+ * Determines what data and actions your app can access.
97
+ *
98
+ * @example
99
+ * ```ts
100
+ * {
101
+ * scopes: [
102
+ * "r_liteprofile", // Basic profile information
103
+ * "r_emailaddress", // Email address
104
+ * "w_member_social", // Share content on behalf of user
105
+ * "r_organization_social" // Organization content access
106
+ * ]
107
+ * }
108
+ * ```
109
+ */
110
+ readonly scopes: string[];
111
+ /**
112
+ * Additional query parameters for LinkedIn OAuth authorization.
113
+ * Useful for LinkedIn-specific options.
114
+ *
115
+ * @example
116
+ * ```ts
117
+ * {
118
+ * query: {
119
+ * state: "custom-state-value" // Custom state parameter
120
+ * }
121
+ * }
122
+ * ```
123
+ */
124
+ readonly query?: Record<string, string>;
125
+ }
126
+ /**
127
+ * Creates a LinkedIn OAuth 2.0 authentication provider.
128
+ * Use this when you need access tokens to call LinkedIn APIs on behalf of the user.
129
+ *
130
+ * @param config - LinkedIn OAuth 2.0 configuration
131
+ * @returns OAuth 2.0 provider configured for LinkedIn
132
+ *
133
+ * @example
134
+ * ```ts
135
+ * // Basic LinkedIn authentication
136
+ * const basicLinkedIn = LinkedInProvider({
137
+ * clientID: process.env.LINKEDIN_CLIENT_ID,
138
+ * clientSecret: process.env.LINKEDIN_CLIENT_SECRET
139
+ * })
140
+ *
141
+ * // LinkedIn with specific scopes
142
+ * const linkedInWithScopes = LinkedInProvider({
143
+ * clientID: process.env.LINKEDIN_CLIENT_ID,
144
+ * clientSecret: process.env.LINKEDIN_CLIENT_SECRET,
145
+ * scopes: [
146
+ * "r_liteprofile",
147
+ * "r_emailaddress",
148
+ * "w_member_social"
149
+ * ]
150
+ * })
151
+ *
152
+ * // Using the access token to fetch data
153
+ * export default issuer({
154
+ * providers: { linkedin: linkedInWithScopes },
155
+ * success: async (ctx, value) => {
156
+ * if (value.provider === "linkedin") {
157
+ * const token = value.tokenset.access
158
+ *
159
+ * // Get user profile
160
+ * const profileRes = await fetch('https://api.linkedin.com/v2/people/~', {
161
+ * headers: { Authorization: `Bearer ${token}` }
162
+ * })
163
+ * const profile = await profileRes.json()
164
+ *
165
+ * // Get user email
166
+ * const emailRes = await fetch('https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))', {
167
+ * headers: { Authorization: `Bearer ${token}` }
168
+ * })
169
+ * const emailData = await emailRes.json()
170
+ *
171
+ * return ctx.subject("user", {
172
+ * linkedinId: profile.id,
173
+ * firstName: profile.localizedFirstName,
174
+ * lastName: profile.localizedLastName,
175
+ * email: emailData.elements[0]['handle~'].emailAddress,
176
+ * profileUrl: `https://www.linkedin.com/in/${profile.vanityName || profile.id}`
177
+ * })
178
+ * }
179
+ * }
180
+ * })
181
+ * ```
182
+ *
183
+ * **Callback URL Pattern**: `{baseURL}{basePath}/{provider}/callback`
184
+ * - Development: `http://localhost:3000/auth/linkedin/callback`
185
+ * - Production: `https://yourapp.com/auth/linkedin/callback`
186
+ *
187
+ * Register this URL in your LinkedIn Developer Portal.
188
+ */
189
+ export declare const LinkedInProvider: (config: LinkedInConfig) => import("./provider").Provider<import("./oauth2").Oauth2UserData>;
190
+ //# sourceMappingURL=linkedin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"linkedin.d.ts","sourceRoot":"","sources":["../../../src/provider/linkedin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8DG;AAEH,OAAO,EAAkB,KAAK,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAEnE;;;GAGG;AACH,MAAM,WAAW,cAAe,SAAQ,mBAAmB;IAC1D;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IAEzB;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAE7B;;;;;;;;;;;;;;;OAeG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,CAAA;IAEzB;;;;;;;;;;;;OAYG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACvC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8DG;AACH,eAAO,MAAM,gBAAgB,GAAI,QAAQ,cAAc,qEAStD,CAAA"}
@@ -0,0 +1,141 @@
1
+ /**
2
+ * Magic Link authentication provider for Draft Auth.
3
+ * Sends clickable links that authenticate users in one click.
4
+ *
5
+ * ## Quick Setup
6
+ *
7
+ * ```ts
8
+ * import { MagicLinkUI } from "@draftlab/auth/ui/magiclink"
9
+ * import { MagicLinkProvider } from "@draftlab/auth/provider/magiclink"
10
+ *
11
+ * export default issuer({
12
+ * providers: {
13
+ * magiclink: MagicLinkProvider(
14
+ * MagicLinkUI({
15
+ * sendLink: async (claims, magicUrl) => {
16
+ * await emailService.send({
17
+ * to: claims.email,
18
+ * subject: "Sign in to your account",
19
+ * html: `<a href="${magicUrl}">Sign In</a>`
20
+ * })
21
+ * }
22
+ * })
23
+ * )
24
+ * }
25
+ * })
26
+ * ```
27
+ *
28
+ * ## Custom Configuration
29
+ *
30
+ * ```ts
31
+ * const customMagicLink = MagicLinkProvider({
32
+ * expiry: 600, // 10 minutes instead of default 15
33
+ *
34
+ * request: async (req, state, form, error) => {
35
+ * return new Response(renderMagicLinkForm(state, form, error))
36
+ * },
37
+ *
38
+ * sendLink: async (claims, magicUrl) => {
39
+ * try {
40
+ * if (claims.email) {
41
+ * await emailService.send(claims.email, {
42
+ * subject: "Your secure sign-in link",
43
+ * template: "magic-link",
44
+ * data: { magicUrl, userEmail: claims.email }
45
+ * })
46
+ * } else {
47
+ * return { type: "invalid_claim", key: "email", value: "Email is required" }
48
+ * }
49
+ * } catch {
50
+ * return { type: "invalid_claim", key: "delivery", value: "Failed to send magic link" }
51
+ * }
52
+ * }
53
+ * })
54
+ * ```
55
+ *
56
+ * @packageDocumentation
57
+ */
58
+ import type { Provider } from "./provider";
59
+ /**
60
+ * Configuration options for the Magic Link authentication provider.
61
+ *
62
+ * @template Claims - Type of claims collected during authentication (email, phone, etc.)
63
+ */
64
+ export interface MagicLinkConfig<Claims extends Record<string, string> = Record<string, string>> {
65
+ /**
66
+ * Token expiration time in seconds.
67
+ * After this time, the magic link becomes invalid.
68
+ *
69
+ * @default 900 (15 minutes)
70
+ */
71
+ readonly expiry?: number;
72
+ /**
73
+ * Request handler for rendering the magic link UI.
74
+ * Handles both the initial claim collection and "check your email" screens.
75
+ *
76
+ * @param req - The HTTP request object
77
+ * @param state - Current authentication state
78
+ * @param form - Form data from POST requests (if any)
79
+ * @param error - Authentication error to display (if any)
80
+ * @returns Promise resolving to the authentication page response
81
+ */
82
+ request: (req: Request, state: MagicLinkState, form?: FormData, error?: MagicLinkError) => Promise<Response>;
83
+ /**
84
+ * Callback for sending magic links to users.
85
+ * Should handle delivery via email, SMS, or other communication channels.
86
+ *
87
+ * @param claims - User claims containing contact information
88
+ * @param magicUrl - The magic link URL to send
89
+ */
90
+ sendLink: (claims: Claims, magicUrl: string) => Promise<void>;
91
+ }
92
+ /**
93
+ * Authentication flow states for the magic link provider.
94
+ * The provider transitions between these states during authentication.
95
+ */
96
+ export type MagicLinkState = {
97
+ /** Initial state: user enters their claims (email, phone, etc.) */
98
+ readonly type: "start";
99
+ } | {
100
+ /** Link sent state: user checks their email/phone */
101
+ readonly type: "sent";
102
+ /** Whether this is a resend request */
103
+ readonly resend?: boolean;
104
+ /** The secure token for verification */
105
+ readonly token: string;
106
+ /** User claims collected during the start phase */
107
+ readonly claims: Record<string, string>;
108
+ };
109
+ /**
110
+ * Possible errors during magic link authentication.
111
+ */
112
+ export type MagicLinkError = {
113
+ /** The magic link is invalid or expired */
114
+ readonly type: "invalid_link";
115
+ } | {
116
+ /** A user claim is invalid or missing */
117
+ readonly type: "invalid_claim";
118
+ /** The claim field that failed validation */
119
+ readonly key: string;
120
+ /** The invalid value or error description */
121
+ readonly value: string;
122
+ };
123
+ /**
124
+ * User data returned by successful magic link authentication.
125
+ *
126
+ * @template Claims - Type of claims collected during authentication
127
+ */
128
+ export interface MagicLinkUserData<Claims extends Record<string, string> = Record<string, string>> {
129
+ /** The verified claims collected during authentication */
130
+ readonly claims: Claims;
131
+ }
132
+ /**
133
+ * Creates a Magic Link authentication provider.
134
+ * Implements a flexible claim-based authentication flow with magic link verification.
135
+ *
136
+ * @template Claims - Type of claims to collect (email, phone, username, etc.)
137
+ * @param config - Magic Link provider configuration
138
+ * @returns Provider instance implementing magic link authentication
139
+ */
140
+ export declare const MagicLinkProvider: <Claims extends Record<string, string> = Record<string, string>>(config: MagicLinkConfig<Claims>) => Provider<MagicLinkUserData<Claims>>;
141
+ //# sourceMappingURL=magiclink.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"magiclink.d.ts","sourceRoot":"","sources":["../../../src/provider/magiclink.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AAIH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAE1C;;;;GAIG;AACH,MAAM,WAAW,eAAe,CAC/B,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAE9D;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;IAExB;;;;;;;;;OASG;IACH,OAAO,EAAE,CACR,GAAG,EAAE,OAAO,EACZ,KAAK,EAAE,cAAc,EACrB,IAAI,CAAC,EAAE,QAAQ,EACf,KAAK,CAAC,EAAE,cAAc,KAClB,OAAO,CAAC,QAAQ,CAAC,CAAA;IAEtB;;;;;;OAMG;IACH,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CAC7D;AAED;;;GAGG;AACH,MAAM,MAAM,cAAc,GACvB;IACA,mEAAmE;IACnE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;CACrB,GACD;IACA,qDAAqD;IACrD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,uCAAuC;IACvC,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAA;IACzB,wCAAwC;IACxC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,mDAAmD;IACnD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACtC,CAAA;AAEJ;;GAEG;AACH,MAAM,MAAM,cAAc,GACvB;IACA,2CAA2C;IAC3C,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAA;CAC5B,GACD;IACA,yCAAyC;IACzC,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAA;IAC9B,6CAA6C;IAC7C,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,6CAA6C;IAC7C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CACrB,CAAA;AAEJ;;;;GAIG;AACH,MAAM,WAAW,iBAAiB,CACjC,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAE9D,0DAA0D;IAC1D,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CACvB;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,GAC7B,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAE9D,QAAQ,eAAe,CAAC,MAAM,CAAC,KAC7B,QAAQ,CAAC,iBAAiB,CAAC,MAAM,CAAC,CA8HpC,CAAA"}
@@ -0,0 +1,247 @@
1
+ /**
2
+ * Microsoft OAuth 2.0 authentication provider for Draft Auth.
3
+ * Supports Microsoft personal accounts, work accounts, and Azure AD.
4
+ * Provides access tokens for calling Microsoft Graph APIs on behalf of users.
5
+ *
6
+ * ## Quick Setup
7
+ *
8
+ * ```ts
9
+ * import { MicrosoftProvider } from "@draftlab/auth/provider/microsoft"
10
+ *
11
+ * export default issuer({
12
+ * basePath: "/auth", // Important for callback URL
13
+ * providers: {
14
+ * microsoft: MicrosoftProvider({
15
+ * tenant: "common", // or specific tenant ID
16
+ * clientID: process.env.MICROSOFT_CLIENT_ID,
17
+ * clientSecret: process.env.MICROSOFT_CLIENT_SECRET,
18
+ * scopes: ["openid", "profile", "email", "User.Read"]
19
+ * })
20
+ * }
21
+ * })
22
+ * ```
23
+ *
24
+ * **Callback URL Pattern**: `{baseURL}{basePath}/{provider}/callback`
25
+ * - Development: `http://localhost:3000/auth/microsoft/callback`
26
+ * - Production: `https://yourapp.com/auth/microsoft/callback`
27
+ *
28
+ * Register this URL in your Azure Portal App Registration.
29
+ *
30
+ * ## Tenant Configuration
31
+ *
32
+ * - `common` - Both personal and work/school accounts
33
+ * - `organizations` - Work/school accounts only
34
+ * - `consumers` - Personal Microsoft accounts only
35
+ * - `{tenant-id}` - Specific Azure AD tenant only
36
+ *
37
+ * ## Common Scopes
38
+ *
39
+ * - `openid` - Basic OpenID Connect sign-in
40
+ * - `profile` - User's basic profile information
41
+ * - `email` - User's email address
42
+ * - `User.Read` - Read user's profile via Microsoft Graph
43
+ * - `Mail.Read` - Read user's mail
44
+ * - `Calendars.Read` - Read user's calendars
45
+ * - `Files.Read` - Read user's files in OneDrive
46
+ * - `Sites.Read.All` - Read SharePoint sites
47
+ * - `Directory.Read.All` - Read directory data (requires admin consent)
48
+ *
49
+ * ## User Data Access
50
+ *
51
+ * ```ts
52
+ * success: async (ctx, value) => {
53
+ * if (value.provider === "microsoft") {
54
+ * const accessToken = value.tokenset.access
55
+ *
56
+ * // Fetch user profile via Microsoft Graph
57
+ * const userResponse = await fetch('https://graph.microsoft.com/v1.0/me', {
58
+ * headers: { Authorization: `Bearer ${accessToken}` }
59
+ * })
60
+ * const user = await userResponse.json()
61
+ *
62
+ * // Fetch user photo (requires User.Read scope)
63
+ * const photoResponse = await fetch('https://graph.microsoft.com/v1.0/me/photo/$value', {
64
+ * headers: { Authorization: `Bearer ${accessToken}` }
65
+ * })
66
+ * const photoBlob = await photoResponse.blob()
67
+ *
68
+ * // User info: user.displayName, user.mail, user.userPrincipalName
69
+ * }
70
+ * }
71
+ * ```
72
+ *
73
+ * @packageDocumentation
74
+ */
75
+ import { type Oauth2WrappedConfig } from "./oauth2";
76
+ /**
77
+ * Configuration options for Microsoft OAuth 2.0 provider.
78
+ * Extends the base OAuth 2.0 configuration with Microsoft-specific documentation.
79
+ */
80
+ export interface MicrosoftConfig extends Oauth2WrappedConfig {
81
+ /**
82
+ * Microsoft Azure AD tenant ID or tenant type.
83
+ * Determines which types of accounts can sign in.
84
+ *
85
+ * @example
86
+ * ```ts
87
+ * {
88
+ * tenant: "common" // Personal + work/school accounts
89
+ * // or
90
+ * tenant: "organizations" // Work/school accounts only
91
+ * // or
92
+ * tenant: "consumers" // Personal accounts only
93
+ * // or
94
+ * tenant: "12345678-1234-1234-1234-123456789012" // Specific tenant
95
+ * }
96
+ * ```
97
+ */
98
+ readonly tenant: string;
99
+ /**
100
+ * Microsoft OAuth 2.0 client ID from Azure App Registration.
101
+ * Found in your Azure portal app registration.
102
+ *
103
+ * @example
104
+ * ```ts
105
+ * {
106
+ * clientID: "12345678-1234-1234-1234-123456789012"
107
+ * }
108
+ * ```
109
+ */
110
+ readonly clientID: string;
111
+ /**
112
+ * Microsoft OAuth 2.0 client secret from Azure App Registration.
113
+ * Keep this secure and never expose it to client-side code.
114
+ *
115
+ * @example
116
+ * ```ts
117
+ * {
118
+ * clientSecret: process.env.MICROSOFT_CLIENT_SECRET
119
+ * }
120
+ * ```
121
+ */
122
+ readonly clientSecret: string;
123
+ /**
124
+ * Microsoft OAuth scopes to request access for.
125
+ * Determines what data and actions your app can access via Microsoft Graph.
126
+ *
127
+ * @example
128
+ * ```ts
129
+ * {
130
+ * scopes: [
131
+ * "openid", // OpenID Connect sign-in
132
+ * "profile", // Basic profile
133
+ * "email", // Email address
134
+ * "User.Read", // Read user profile
135
+ * "Mail.Read", // Read user mail
136
+ * "Calendars.Read" // Read user calendars
137
+ * ]
138
+ * }
139
+ * ```
140
+ */
141
+ readonly scopes: string[];
142
+ /**
143
+ * Additional query parameters for Microsoft OAuth authorization.
144
+ * Useful for Microsoft-specific options like domain hints.
145
+ *
146
+ * @example
147
+ * ```ts
148
+ * {
149
+ * query: {
150
+ * domain_hint: "contoso.com", // Pre-fill domain
151
+ * login_hint: "user@contoso.com", // Pre-fill username
152
+ * prompt: "consent" // Force consent screen
153
+ * }
154
+ * }
155
+ * ```
156
+ */
157
+ readonly query?: Record<string, string>;
158
+ }
159
+ /**
160
+ * Creates a Microsoft OAuth 2.0 authentication provider.
161
+ * Use this when you need access tokens to call Microsoft Graph APIs on behalf of the user.
162
+ *
163
+ * @param config - Microsoft OAuth 2.0 configuration
164
+ * @returns OAuth 2.0 provider configured for Microsoft
165
+ *
166
+ * @example
167
+ * ```ts
168
+ * // Basic Microsoft authentication (all account types)
169
+ * const basicMicrosoft = MicrosoftProvider({
170
+ * tenant: "common",
171
+ * clientID: process.env.MICROSOFT_CLIENT_ID,
172
+ * clientSecret: process.env.MICROSOFT_CLIENT_SECRET
173
+ * })
174
+ *
175
+ * // Work/school accounts only
176
+ * const workMicrosoft = MicrosoftProvider({
177
+ * tenant: "organizations",
178
+ * clientID: process.env.MICROSOFT_CLIENT_ID,
179
+ * clientSecret: process.env.MICROSOFT_CLIENT_SECRET,
180
+ * scopes: [
181
+ * "openid",
182
+ * "profile",
183
+ * "email",
184
+ * "User.Read",
185
+ * "Mail.Read"
186
+ * ]
187
+ * })
188
+ *
189
+ * // Specific tenant with advanced scopes
190
+ * const enterpriseMicrosoft = MicrosoftProvider({
191
+ * tenant: "12345678-1234-1234-1234-123456789012",
192
+ * clientID: process.env.MICROSOFT_CLIENT_ID,
193
+ * clientSecret: process.env.MICROSOFT_CLIENT_SECRET,
194
+ * scopes: [
195
+ * "openid",
196
+ * "profile",
197
+ * "email",
198
+ * "User.Read",
199
+ * "Directory.Read.All",
200
+ * "Sites.Read.All"
201
+ * ],
202
+ * query: {
203
+ * domain_hint: "contoso.com"
204
+ * }
205
+ * })
206
+ *
207
+ * // Using the access token to fetch data
208
+ * export default issuer({
209
+ * providers: { microsoft: workMicrosoft },
210
+ * success: async (ctx, value) => {
211
+ * if (value.provider === "microsoft") {
212
+ * const token = value.tokenset.access
213
+ *
214
+ * // Get user profile from Microsoft Graph
215
+ * const userRes = await fetch('https://graph.microsoft.com/v1.0/me', {
216
+ * headers: { Authorization: `Bearer ${token}` }
217
+ * })
218
+ * const user = await userRes.json()
219
+ *
220
+ * // Get user's manager (if available)
221
+ * const managerRes = await fetch('https://graph.microsoft.com/v1.0/me/manager', {
222
+ * headers: { Authorization: `Bearer ${token}` }
223
+ * })
224
+ * const manager = await managerRes.json()
225
+ *
226
+ * return ctx.subject("user", {
227
+ * microsoftId: user.id,
228
+ * displayName: user.displayName,
229
+ * email: user.mail || user.userPrincipalName,
230
+ * jobTitle: user.jobTitle,
231
+ * department: user.department,
232
+ * officeLocation: user.officeLocation,
233
+ * managerName: manager?.displayName
234
+ * })
235
+ * }
236
+ * }
237
+ * })
238
+ * ```
239
+ *
240
+ * **Callback URL Pattern**: `{baseURL}{basePath}/{provider}/callback`
241
+ * - Development: `http://localhost:3000/auth/microsoft/callback`
242
+ * - Production: `https://yourapp.com/auth/microsoft/callback`
243
+ *
244
+ * Register this URL in your Azure Portal App Registration.
245
+ */
246
+ export declare const MicrosoftProvider: (config: MicrosoftConfig) => import("./provider").Provider<import("./oauth2").Oauth2UserData>;
247
+ //# sourceMappingURL=microsoft.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"microsoft.d.ts","sourceRoot":"","sources":["../../../src/provider/microsoft.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyEG;AAEH,OAAO,EAAkB,KAAK,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAEnE;;;GAGG;AACH,MAAM,WAAW,eAAgB,SAAQ,mBAAmB;IAC3D;;;;;;;;;;;;;;;;OAgBG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IAEvB;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IAEzB;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAE7B;;;;;;;;;;;;;;;;;OAiBG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,CAAA;IAEzB;;;;;;;;;;;;;;OAcG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACvC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsFG;AACH,eAAO,MAAM,iBAAiB,GAAI,QAAQ,eAAe,qEASxD,CAAA"}