@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,226 @@
1
+ import type { Context, Hono } from "hono";
2
+ import type { StorageAdapter } from "../storage/storage";
3
+ /**
4
+ * OAuth provider system for Draft Auth.
5
+ * Defines the interfaces and utilities for implementing authentication providers
6
+ * that integrate with various OAuth 2.0 services.
7
+ *
8
+ * ## Creating a Provider
9
+ *
10
+ * ```ts
11
+ * export const MyProvider = (config: MyConfig): Provider<MyUserData> => ({
12
+ * type: "my-provider",
13
+ *
14
+ * init(routes, ctx) {
15
+ * routes.get("/authorize", async (c) => {
16
+ * // Redirect to provider's auth URL
17
+ * return c.redirect(authUrl)
18
+ * })
19
+ *
20
+ * routes.get("/callback", async (c) => {
21
+ * // Handle callback and extract user data
22
+ * const userData = await processCallback(c)
23
+ * return await ctx.success(c, userData)
24
+ * })
25
+ * }
26
+ * })
27
+ * ```
28
+ *
29
+ * ## Using Providers
30
+ *
31
+ * ```ts
32
+ * export default issuer({
33
+ * providers: {
34
+ * github: GithubProvider({ ... }),
35
+ * google: GoogleProvider({ ... })
36
+ * }
37
+ * })
38
+ * ```
39
+ */
40
+ /**
41
+ * Router instance used for provider route definitions.
42
+ * Providers use this to register their authorization and callback endpoints.
43
+ */
44
+ export type ProviderRoute = Hono<{
45
+ Variables: {
46
+ provider: string;
47
+ };
48
+ }>;
49
+ /**
50
+ * Authentication provider interface that handles OAuth flows.
51
+ * Each provider implements authentication with a specific service (GitHub, Google, etc.).
52
+ *
53
+ * @template Properties - Type of user data returned by successful authentication
54
+ */
55
+ export interface Provider<Properties = Record<string, unknown>> {
56
+ /**
57
+ * Unique identifier for this provider type.
58
+ * Used in URLs and provider selection UI.
59
+ *
60
+ * @example "github", "google", "steam"
61
+ */
62
+ readonly type: string;
63
+ /**
64
+ * Initializes the provider by registering required routes.
65
+ * Called during issuer setup to configure authorization and callback endpoints.
66
+ *
67
+ * @param route - Hono router instance for registering provider endpoints
68
+ * @param options - Provider utilities and configuration
69
+ *
70
+ * @example
71
+ * ```ts
72
+ * init(routes, ctx) {
73
+ * routes.get("/authorize", async (c) => {
74
+ * // Redirect to OAuth provider
75
+ * return c.redirect(buildAuthUrl())
76
+ * })
77
+ *
78
+ * routes.get("/callback", async (c) => {
79
+ * // Process callback and return user data
80
+ * const userData = await handleCallback(c)
81
+ * return await ctx.success(c, userData)
82
+ * })
83
+ * }
84
+ * ```
85
+ */
86
+ init: (route: ProviderRoute, options: ProviderOptions<Properties>) => void;
87
+ }
88
+ /**
89
+ * Utilities and callbacks provided to providers during initialization.
90
+ * Contains methods for state management, user flow completion, and storage access.
91
+ *
92
+ * @template Properties - Type of user data handled by the provider
93
+ */
94
+ export interface ProviderOptions<Properties> {
95
+ /**
96
+ * Name of the provider instance as configured in the issuer.
97
+ * Corresponds to the key used in the providers object.
98
+ */
99
+ readonly name: string;
100
+ /**
101
+ * Completes the authentication flow with user data.
102
+ * Called when the provider successfully authenticates a user.
103
+ *
104
+ * @param ctx - Hono request context
105
+ * @param properties - User data extracted from the provider
106
+ * @param opts - Optional utilities for session management
107
+ * @returns Response that completes the OAuth flow
108
+ *
109
+ * @example
110
+ * ```ts
111
+ * const userData = { userId: "123", email: "user@example.com" }
112
+ * return await ctx.success(c, userData)
113
+ * ```
114
+ */
115
+ success: (ctx: Context, properties: Properties, opts?: {
116
+ /** Function to invalidate existing user sessions */
117
+ readonly invalidate?: (subject: string) => Promise<void>;
118
+ }) => Promise<Response>;
119
+ /**
120
+ * Forwards a response through the provider context.
121
+ * Used for redirects and custom responses within the OAuth flow.
122
+ *
123
+ * @param ctx - Hono request context
124
+ * @param response - Response to forward
125
+ * @returns Forwarded response
126
+ */
127
+ forward: (ctx: Context, response: Response) => Response;
128
+ /**
129
+ * Stores a temporary value with expiration for the current session.
130
+ * Useful for storing OAuth state, PKCE verifiers, and other temporary data.
131
+ *
132
+ * @param ctx - Hono request context
133
+ * @param key - Storage key identifier
134
+ * @param maxAge - TTL in seconds
135
+ * @param value - Value to store
136
+ *
137
+ * @example
138
+ * ```ts
139
+ * // Store OAuth state for 10 minutes
140
+ * await ctx.set(c, "oauth_state", 600, { state, redirectUri })
141
+ * ```
142
+ */
143
+ set: <T>(ctx: Context, key: string, maxAge: number, value: T) => Promise<void>;
144
+ /**
145
+ * Retrieves a previously stored temporary value.
146
+ *
147
+ * @param ctx - Hono request context
148
+ * @param key - Storage key identifier
149
+ * @returns Promise resolving to the stored value or undefined if not found/expired
150
+ *
151
+ * @example
152
+ * ```ts
153
+ * const oauthState = await ctx.get<OAuthState>(c, "oauth_state")
154
+ * if (!oauthState) {
155
+ * throw new Error("OAuth state expired")
156
+ * }
157
+ * ```
158
+ */
159
+ get: <T>(ctx: Context, key: string) => Promise<T | undefined>;
160
+ /**
161
+ * Removes a stored temporary value.
162
+ *
163
+ * @param ctx - Hono request context
164
+ * @param key - Storage key identifier
165
+ *
166
+ * @example
167
+ * ```ts
168
+ * // Clean up OAuth state after use
169
+ * await ctx.unset(c, "oauth_state")
170
+ * ```
171
+ */
172
+ unset: (ctx: Context, key: string) => Promise<void>;
173
+ /**
174
+ * Invalidates all sessions for a given subject (user).
175
+ * Forces logout across all devices and applications.
176
+ *
177
+ * @param subject - Subject identifier to invalidate
178
+ *
179
+ * @example
180
+ * ```ts
181
+ * // Force logout on password change
182
+ * await ctx.invalidate(userId)
183
+ * ```
184
+ */
185
+ invalidate: (subject: string) => Promise<void>;
186
+ /**
187
+ * Storage adapter for persistent data operations.
188
+ * Provides access to the configured storage backend.
189
+ */
190
+ readonly storage: StorageAdapter;
191
+ }
192
+ /**
193
+ * Base error class for provider-related errors.
194
+ * Extend this class to create specific provider error types.
195
+ *
196
+ * @example
197
+ * ```ts
198
+ * export class GitHubApiError extends ProviderError {
199
+ * constructor(message: string, public readonly statusCode: number) {
200
+ * super(message)
201
+ * }
202
+ * }
203
+ * ```
204
+ */
205
+ export declare class ProviderError extends Error {
206
+ constructor(message: string);
207
+ }
208
+ /**
209
+ * Error thrown when a provider encounters an unknown or unexpected error.
210
+ * Used as a fallback for unhandled error conditions.
211
+ *
212
+ * @example
213
+ * ```ts
214
+ * catch (error) {
215
+ * if (error instanceof SomeSpecificError) {
216
+ * // Handle specific error
217
+ * } else {
218
+ * throw new ProviderUnknownError(`Unexpected error: ${error}`)
219
+ * }
220
+ * }
221
+ * ```
222
+ */
223
+ export declare class ProviderUnknownError extends ProviderError {
224
+ constructor(message?: string);
225
+ }
226
+ //# sourceMappingURL=provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../src/provider/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AACzC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAExD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAEH;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,IAAI,CAAC;IAAE,SAAS,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,CAAC,CAAA;AAErE;;;;;GAKG;AACH,MAAM,WAAW,QAAQ,CAAC,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC7D;;;;;OAKG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IAErB;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,IAAI,EAAE,CAAC,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,eAAe,CAAC,UAAU,CAAC,KAAK,IAAI,CAAA;CAC1E;AAED;;;;;GAKG;AACH,MAAM,WAAW,eAAe,CAAC,UAAU;IAC1C;;;OAGG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IAErB;;;;;;;;;;;;;;OAcG;IACH,OAAO,EAAE,CACR,GAAG,EAAE,OAAO,EACZ,UAAU,EAAE,UAAU,EACtB,IAAI,CAAC,EAAE;QACN,oDAAoD;QACpD,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;KACxD,KACG,OAAO,CAAC,QAAQ,CAAC,CAAA;IAEtB;;;;;;;OAOG;IACH,OAAO,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,KAAK,QAAQ,CAAA;IAEvD;;;;;;;;;;;;;;OAcG;IACH,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAE9E;;;;;;;;;;;;;;OAcG;IACH,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAAA;IAE7D;;;;;;;;;;;OAWG;IACH,KAAK,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAEnD;;;;;;;;;;;OAWG;IACH,UAAU,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAE9C;;;OAGG;IACH,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAA;CAChC;AAED;;;;;;;;;;;;GAYG;AACH,qBAAa,aAAc,SAAQ,KAAK;gBAC3B,OAAO,EAAE,MAAM;CAI3B;AAED;;;;;;;;;;;;;;GAcG;AACH,qBAAa,oBAAqB,SAAQ,aAAa;gBAC1C,OAAO,CAAC,EAAE,MAAM;CAI5B"}
@@ -0,0 +1,159 @@
1
+ /**
2
+ * Reddit authentication provider for Draft Auth.
3
+ * Implements OAuth 2.0 flow for authenticating users with their Reddit accounts.
4
+ *
5
+ * ## Quick Setup
6
+ *
7
+ * ```ts
8
+ * import { RedditProvider } from "@draftlab/auth/provider/reddit"
9
+ *
10
+ * export default issuer({
11
+ * basePath: "/auth", // Important for callback URL
12
+ * providers: {
13
+ * reddit: RedditProvider({
14
+ * clientID: process.env.REDDIT_CLIENT_ID,
15
+ * clientSecret: process.env.REDDIT_CLIENT_SECRET,
16
+ * scopes: ["identity"]
17
+ * })
18
+ * }
19
+ * })
20
+ * ```
21
+ *
22
+ * **Callback URL Pattern**: `{baseURL}{basePath}/{provider}/callback`
23
+ * - Development: `http://localhost:3000/auth/reddit/callback`
24
+ * - Production: `https://yourapp.com/auth/reddit/callback`
25
+ *
26
+ * Register this URL in your Reddit App Preferences.
27
+ *
28
+ * ## Common Scopes
29
+ *
30
+ * - `identity` - Access user's identity information
31
+ * - `read` - Access user's private data (saved posts, hidden posts, etc.)
32
+ * - `submit` - Submit links and posts
33
+ * - `modposts` - Moderate posts
34
+ * - `privatemessages` - Access private messages
35
+ * - `subscribe` - Subscribe to subreddits
36
+ * - `wikiread` - Read wiki pages
37
+ *
38
+ * ## User Data Access
39
+ *
40
+ * ```ts
41
+ * success: async (ctx, value) => {
42
+ * if (value.provider === "reddit") {
43
+ * const accessToken = value.tokenset.access
44
+ *
45
+ * // Fetch user information
46
+ * const userResponse = await fetch('https://oauth.reddit.com/api/v1/me', {
47
+ * headers: { Authorization: `Bearer ${accessToken}` }
48
+ * })
49
+ * const user = await userResponse.json()
50
+ *
51
+ * // User info: id, name, created_utc, link_karma, comment_karma
52
+ * }
53
+ * }
54
+ * ```
55
+ *
56
+ * @packageDocumentation
57
+ */
58
+ import { type Oauth2WrappedConfig } from "./oauth2";
59
+ /**
60
+ * Configuration options for Reddit OAuth 2.0 provider.
61
+ * Extends the base OAuth 2.0 configuration with Reddit-specific documentation.
62
+ */
63
+ export interface RedditConfig extends Oauth2WrappedConfig {
64
+ /**
65
+ * Reddit app client ID.
66
+ * Get this from your Reddit application preferences at https://www.reddit.com/prefs/apps
67
+ *
68
+ * @example
69
+ * ```ts
70
+ * {
71
+ * clientID: "abcdef123456"
72
+ * }
73
+ * ```
74
+ */
75
+ readonly clientID: string;
76
+ /**
77
+ * Reddit app client secret.
78
+ * Keep this secure and never expose it to client-side code.
79
+ *
80
+ * @example
81
+ * ```ts
82
+ * {
83
+ * clientSecret: process.env.REDDIT_CLIENT_SECRET
84
+ * }
85
+ * ```
86
+ */
87
+ readonly clientSecret: string;
88
+ /**
89
+ * Reddit OAuth scopes to request access for.
90
+ * Determines what data and actions your app can access.
91
+ *
92
+ * @example
93
+ * ```ts
94
+ * {
95
+ * scopes: [
96
+ * "identity", // Access user identity
97
+ * "read" // Read private data
98
+ * ]
99
+ * }
100
+ * ```
101
+ */
102
+ readonly scopes: string[];
103
+ }
104
+ /**
105
+ * Creates a Reddit OAuth 2.0 authentication provider.
106
+ * Allows users to authenticate using their Reddit accounts.
107
+ *
108
+ * @param config - Reddit OAuth 2.0 configuration
109
+ * @returns OAuth 2.0 provider configured for Reddit
110
+ *
111
+ * @example
112
+ * ```ts
113
+ * // Basic Reddit authentication
114
+ * const basicReddit = RedditProvider({
115
+ * clientID: process.env.REDDIT_CLIENT_ID,
116
+ * clientSecret: process.env.REDDIT_CLIENT_SECRET
117
+ * })
118
+ *
119
+ * // Reddit with identity scope
120
+ * const redditWithIdentity = RedditProvider({
121
+ * clientID: process.env.REDDIT_CLIENT_ID,
122
+ * clientSecret: process.env.REDDIT_CLIENT_SECRET,
123
+ * scopes: ["identity"]
124
+ * })
125
+ *
126
+ * // Using the access token to fetch user data
127
+ * export default issuer({
128
+ * providers: { reddit: redditWithIdentity },
129
+ * success: async (ctx, value) => {
130
+ * if (value.provider === "reddit") {
131
+ * const token = value.tokenset.access
132
+ *
133
+ * const userRes = await fetch('https://oauth.reddit.com/api/v1/me', {
134
+ * headers: {
135
+ * 'Authorization': `Bearer ${token}`,
136
+ * 'User-Agent': 'YourApp/1.0'
137
+ * }
138
+ * })
139
+ * const user = await userRes.json()
140
+ *
141
+ * return ctx.subject("user", {
142
+ * redditId: user.id,
143
+ * username: user.name,
144
+ * linkKarma: user.link_karma,
145
+ * commentKarma: user.comment_karma
146
+ * })
147
+ * }
148
+ * }
149
+ * })
150
+ * ```
151
+ *
152
+ * **Callback URL Pattern**: `{baseURL}{basePath}/{provider}/callback`
153
+ * - Development: `http://localhost:3000/auth/reddit/callback`
154
+ * - Production: `https://yourapp.com/auth/reddit/callback`
155
+ *
156
+ * Register this URL in your Reddit App Preferences.
157
+ */
158
+ export declare const RedditProvider: (config: RedditConfig) => import("./provider").Provider<import("./oauth2").Oauth2UserData>;
159
+ //# sourceMappingURL=reddit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reddit.d.ts","sourceRoot":"","sources":["../../../src/provider/reddit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AAEH,OAAO,EAAkB,KAAK,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAEnE;;;GAGG;AACH,MAAM,WAAW,YAAa,SAAQ,mBAAmB;IACxD;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IAEzB;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAE7B;;;;;;;;;;;;;OAaG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CACzB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,eAAO,MAAM,cAAc,GAAI,QAAQ,YAAY,qEASlD,CAAA"}
@@ -0,0 +1,171 @@
1
+ /**
2
+ * Slack authentication provider for Draft Auth.
3
+ * Implements OAuth 2.0 flow for authenticating users with their Slack accounts.
4
+ *
5
+ * ## Quick Setup
6
+ *
7
+ * ```ts
8
+ * import { SlackProvider } from "@draftlab/auth/provider/slack"
9
+ *
10
+ * export default issuer({
11
+ * basePath: "/auth", // Important for callback URL
12
+ * providers: {
13
+ * slack: SlackProvider({
14
+ * clientID: process.env.SLACK_CLIENT_ID,
15
+ * clientSecret: process.env.SLACK_CLIENT_SECRET,
16
+ * scopes: ["users:read", "users:read.email"]
17
+ * })
18
+ * }
19
+ * })
20
+ * ```
21
+ *
22
+ * **Callback URL Pattern**: `{baseURL}{basePath}/{provider}/callback`
23
+ * - Development: `http://localhost:3000/auth/slack/callback`
24
+ * - Production: `https://yourapp.com/auth/slack/callback`
25
+ *
26
+ * Register this URL in your Slack App settings.
27
+ *
28
+ * ## Common Scopes
29
+ *
30
+ * - `users:read` - Access to user profiles
31
+ * - `users:read.email` - Access user email addresses
32
+ * - `team:read` - Access team information
33
+ * - `channels:read` - View channels
34
+ * - `groups:read` - View private channels
35
+ * - `im:read` - View direct messages
36
+ * - `mpim:read` - View group direct messages
37
+ *
38
+ * ## User Data Access
39
+ *
40
+ * ```ts
41
+ * success: async (ctx, value) => {
42
+ * if (value.provider === "slack") {
43
+ * const accessToken = value.tokenset.access
44
+ *
45
+ * // Fetch user information
46
+ * const userResponse = await fetch('https://slack.com/api/auth.test', {
47
+ * headers: { Authorization: `Bearer ${accessToken}` }
48
+ * })
49
+ * const userInfo = await userResponse.json()
50
+ *
51
+ * // Get user details
52
+ * const userDetailsResponse = await fetch(
53
+ * `https://slack.com/api/users.info?user=${userInfo.user_id}`,
54
+ * { headers: { Authorization: `Bearer ${accessToken}` } }
55
+ * )
56
+ * const { user } = await userDetailsResponse.json()
57
+ * }
58
+ * }
59
+ * ```
60
+ *
61
+ * @packageDocumentation
62
+ */
63
+ import { type Oauth2WrappedConfig } from "./oauth2";
64
+ /**
65
+ * Configuration options for Slack OAuth 2.0 provider.
66
+ * Extends the base OAuth 2.0 configuration with Slack-specific documentation.
67
+ */
68
+ export interface SlackConfig extends Oauth2WrappedConfig {
69
+ /**
70
+ * Slack app client ID.
71
+ * Get this from your Slack App settings at https://api.slack.com/apps
72
+ *
73
+ * @example
74
+ * ```ts
75
+ * {
76
+ * clientID: "123456789.1234567890"
77
+ * }
78
+ * ```
79
+ */
80
+ readonly clientID: string;
81
+ /**
82
+ * Slack app client secret.
83
+ * Keep this secure and never expose it to client-side code.
84
+ *
85
+ * @example
86
+ * ```ts
87
+ * {
88
+ * clientSecret: process.env.SLACK_CLIENT_SECRET
89
+ * }
90
+ * ```
91
+ */
92
+ readonly clientSecret: string;
93
+ /**
94
+ * Slack OAuth scopes to request access for.
95
+ * Determines what data and actions your app can access.
96
+ *
97
+ * @example
98
+ * ```ts
99
+ * {
100
+ * scopes: [
101
+ * "users:read", // Access to user profiles
102
+ * "users:read.email", // Access user emails
103
+ * "team:read" // Access team information
104
+ * ]
105
+ * }
106
+ * ```
107
+ */
108
+ readonly scopes: string[];
109
+ }
110
+ /**
111
+ * Creates a Slack OAuth 2.0 authentication provider.
112
+ * Allows users to authenticate using their Slack accounts.
113
+ *
114
+ * @param config - Slack OAuth 2.0 configuration
115
+ * @returns OAuth 2.0 provider configured for Slack
116
+ *
117
+ * @example
118
+ * ```ts
119
+ * // Basic Slack authentication
120
+ * const basicSlack = SlackProvider({
121
+ * clientID: process.env.SLACK_CLIENT_ID,
122
+ * clientSecret: process.env.SLACK_CLIENT_SECRET
123
+ * })
124
+ *
125
+ * // Slack with user scopes
126
+ * const slackWithScopes = SlackProvider({
127
+ * clientID: process.env.SLACK_CLIENT_ID,
128
+ * clientSecret: process.env.SLACK_CLIENT_SECRET,
129
+ * scopes: ["users:read", "users:read.email", "team:read"]
130
+ * })
131
+ *
132
+ * // Using the access token to fetch user data
133
+ * export default issuer({
134
+ * providers: { slack: slackWithScopes },
135
+ * success: async (ctx, value) => {
136
+ * if (value.provider === "slack") {
137
+ * const token = value.tokenset.access
138
+ *
139
+ * // Get basic user info
140
+ * const authRes = await fetch('https://slack.com/api/auth.test', {
141
+ * headers: { Authorization: `Bearer ${token}` }
142
+ * })
143
+ * const authInfo = await authRes.json()
144
+ *
145
+ * // Get detailed user info
146
+ * const userRes = await fetch(
147
+ * `https://slack.com/api/users.info?user=${authInfo.user_id}`,
148
+ * { headers: { Authorization: `Bearer ${token}` } }
149
+ * )
150
+ * const { user } = await userRes.json()
151
+ *
152
+ * return ctx.subject("user", {
153
+ * slackId: user.id,
154
+ * username: user.name,
155
+ * realName: user.real_name,
156
+ * email: user.profile?.email,
157
+ * workspace: authInfo.team_id
158
+ * })
159
+ * }
160
+ * }
161
+ * })
162
+ * ```
163
+ *
164
+ * **Callback URL Pattern**: `{baseURL}{basePath}/{provider}/callback`
165
+ * - Development: `http://localhost:3000/auth/slack/callback`
166
+ * - Production: `https://yourapp.com/auth/slack/callback`
167
+ *
168
+ * Register this URL in your Slack App settings.
169
+ */
170
+ export declare const SlackProvider: (config: SlackConfig) => import("./provider").Provider<import("./oauth2").Oauth2UserData>;
171
+ //# sourceMappingURL=slack.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slack.d.ts","sourceRoot":"","sources":["../../../src/provider/slack.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AAEH,OAAO,EAAkB,KAAK,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAEnE;;;GAGG;AACH,MAAM,WAAW,WAAY,SAAQ,mBAAmB;IACvD;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IAEzB;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAE7B;;;;;;;;;;;;;;OAcG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CACzB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2DG;AACH,eAAO,MAAM,aAAa,GAAI,QAAQ,WAAW,qEAShD,CAAA"}