@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
@@ -1,107 +0,0 @@
1
- import { Provider } from "./provider.mjs";
2
- import { Oauth2UserData, Oauth2WrappedConfig } from "./oauth2.mjs";
3
-
4
- //#region src/provider/reddit.d.ts
5
-
6
- /**
7
- * Configuration options for Reddit OAuth 2.0 provider.
8
- * Extends the base OAuth 2.0 configuration with Reddit-specific documentation.
9
- */
10
- interface RedditConfig extends Oauth2WrappedConfig {
11
- /**
12
- * Reddit app client ID.
13
- * Get this from your Reddit application preferences at https://www.reddit.com/prefs/apps
14
- *
15
- * @example
16
- * ```ts
17
- * {
18
- * clientID: "abcdef123456"
19
- * }
20
- * ```
21
- */
22
- readonly clientID: string;
23
- /**
24
- * Reddit app client secret.
25
- * Keep this secure and never expose it to client-side code.
26
- *
27
- * @example
28
- * ```ts
29
- * {
30
- * clientSecret: process.env.REDDIT_CLIENT_SECRET
31
- * }
32
- * ```
33
- */
34
- readonly clientSecret: string;
35
- /**
36
- * Reddit OAuth scopes to request access for.
37
- * Determines what data and actions your app can access.
38
- *
39
- * @example
40
- * ```ts
41
- * {
42
- * scopes: [
43
- * "identity", // Access user identity
44
- * "read" // Read private data
45
- * ]
46
- * }
47
- * ```
48
- */
49
- readonly scopes: string[];
50
- }
51
- /**
52
- * Creates a Reddit OAuth 2.0 authentication provider.
53
- * Allows users to authenticate using their Reddit accounts.
54
- *
55
- * @param config - Reddit OAuth 2.0 configuration
56
- * @returns OAuth 2.0 provider configured for Reddit
57
- *
58
- * @example
59
- * ```ts
60
- * // Basic Reddit authentication
61
- * const basicReddit = RedditProvider({
62
- * clientID: process.env.REDDIT_CLIENT_ID,
63
- * clientSecret: process.env.REDDIT_CLIENT_SECRET
64
- * })
65
- *
66
- * // Reddit with identity scope
67
- * const redditWithIdentity = RedditProvider({
68
- * clientID: process.env.REDDIT_CLIENT_ID,
69
- * clientSecret: process.env.REDDIT_CLIENT_SECRET,
70
- * scopes: ["identity"]
71
- * })
72
- *
73
- * // Using the access token to fetch user data
74
- * export default issuer({
75
- * providers: { reddit: redditWithIdentity },
76
- * success: async (ctx, value) => {
77
- * if (value.provider === "reddit") {
78
- * const token = value.tokenset.access
79
- *
80
- * const userRes = await fetch('https://oauth.reddit.com/api/v1/me', {
81
- * headers: {
82
- * 'Authorization': `Bearer ${token}`,
83
- * 'User-Agent': 'YourApp/1.0'
84
- * }
85
- * })
86
- * const user = await userRes.json()
87
- *
88
- * return ctx.subject("user", {
89
- * redditId: user.id,
90
- * username: user.name,
91
- * linkKarma: user.link_karma,
92
- * commentKarma: user.comment_karma
93
- * })
94
- * }
95
- * }
96
- * })
97
- * ```
98
- *
99
- * **Callback URL Pattern**: `{baseURL}{basePath}/{provider}/callback`
100
- * - Development: `http://localhost:3000/auth/reddit/callback`
101
- * - Production: `https://yourapp.com/auth/reddit/callback`
102
- *
103
- * Register this URL in your Reddit App Preferences.
104
- */
105
- declare const RedditProvider: (config: RedditConfig) => Provider<Oauth2UserData>;
106
- //#endregion
107
- export { RedditConfig, RedditProvider };
@@ -1,127 +0,0 @@
1
- import { Oauth2Provider } from "./oauth2.mjs";
2
-
3
- //#region src/provider/reddit.ts
4
- /**
5
- * Reddit authentication provider for Draft Auth.
6
- * Implements OAuth 2.0 flow for authenticating users with their Reddit accounts.
7
- *
8
- * ## Quick Setup
9
- *
10
- * ```ts
11
- * import { RedditProvider } from "@draftlab/auth/provider/reddit"
12
- *
13
- * export default issuer({
14
- * basePath: "/auth", // Important for callback URL
15
- * providers: {
16
- * reddit: RedditProvider({
17
- * clientID: process.env.REDDIT_CLIENT_ID,
18
- * clientSecret: process.env.REDDIT_CLIENT_SECRET,
19
- * scopes: ["identity"]
20
- * })
21
- * }
22
- * })
23
- * ```
24
- *
25
- * **Callback URL Pattern**: `{baseURL}{basePath}/{provider}/callback`
26
- * - Development: `http://localhost:3000/auth/reddit/callback`
27
- * - Production: `https://yourapp.com/auth/reddit/callback`
28
- *
29
- * Register this URL in your Reddit App Preferences.
30
- *
31
- * ## Common Scopes
32
- *
33
- * - `identity` - Access user's identity information
34
- * - `read` - Access user's private data (saved posts, hidden posts, etc.)
35
- * - `submit` - Submit links and posts
36
- * - `modposts` - Moderate posts
37
- * - `privatemessages` - Access private messages
38
- * - `subscribe` - Subscribe to subreddits
39
- * - `wikiread` - Read wiki pages
40
- *
41
- * ## User Data Access
42
- *
43
- * ```ts
44
- * success: async (ctx, value) => {
45
- * if (value.provider === "reddit") {
46
- * const accessToken = value.tokenset.access
47
- *
48
- * // Fetch user information
49
- * const userResponse = await fetch('https://oauth.reddit.com/api/v1/me', {
50
- * headers: { Authorization: `Bearer ${accessToken}` }
51
- * })
52
- * const user = await userResponse.json()
53
- *
54
- * // User info: id, name, created_utc, link_karma, comment_karma
55
- * }
56
- * }
57
- * ```
58
- *
59
- * @packageDocumentation
60
- */
61
- /**
62
- * Creates a Reddit OAuth 2.0 authentication provider.
63
- * Allows users to authenticate using their Reddit accounts.
64
- *
65
- * @param config - Reddit OAuth 2.0 configuration
66
- * @returns OAuth 2.0 provider configured for Reddit
67
- *
68
- * @example
69
- * ```ts
70
- * // Basic Reddit authentication
71
- * const basicReddit = RedditProvider({
72
- * clientID: process.env.REDDIT_CLIENT_ID,
73
- * clientSecret: process.env.REDDIT_CLIENT_SECRET
74
- * })
75
- *
76
- * // Reddit with identity scope
77
- * const redditWithIdentity = RedditProvider({
78
- * clientID: process.env.REDDIT_CLIENT_ID,
79
- * clientSecret: process.env.REDDIT_CLIENT_SECRET,
80
- * scopes: ["identity"]
81
- * })
82
- *
83
- * // Using the access token to fetch user data
84
- * export default issuer({
85
- * providers: { reddit: redditWithIdentity },
86
- * success: async (ctx, value) => {
87
- * if (value.provider === "reddit") {
88
- * const token = value.tokenset.access
89
- *
90
- * const userRes = await fetch('https://oauth.reddit.com/api/v1/me', {
91
- * headers: {
92
- * 'Authorization': `Bearer ${token}`,
93
- * 'User-Agent': 'YourApp/1.0'
94
- * }
95
- * })
96
- * const user = await userRes.json()
97
- *
98
- * return ctx.subject("user", {
99
- * redditId: user.id,
100
- * username: user.name,
101
- * linkKarma: user.link_karma,
102
- * commentKarma: user.comment_karma
103
- * })
104
- * }
105
- * }
106
- * })
107
- * ```
108
- *
109
- * **Callback URL Pattern**: `{baseURL}{basePath}/{provider}/callback`
110
- * - Development: `http://localhost:3000/auth/reddit/callback`
111
- * - Production: `https://yourapp.com/auth/reddit/callback`
112
- *
113
- * Register this URL in your Reddit App Preferences.
114
- */
115
- const RedditProvider = (config) => {
116
- return Oauth2Provider({
117
- ...config,
118
- type: "reddit",
119
- endpoint: {
120
- authorization: "https://www.reddit.com/api/v1/authorize",
121
- token: "https://www.reddit.com/api/v1/access_token"
122
- }
123
- });
124
- };
125
-
126
- //#endregion
127
- export { RedditProvider };
@@ -1,114 +0,0 @@
1
- import { Provider } from "./provider.mjs";
2
- import { Oauth2UserData, Oauth2WrappedConfig } from "./oauth2.mjs";
3
-
4
- //#region src/provider/slack.d.ts
5
-
6
- /**
7
- * Configuration options for Slack OAuth 2.0 provider.
8
- * Extends the base OAuth 2.0 configuration with Slack-specific documentation.
9
- */
10
- interface SlackConfig extends Oauth2WrappedConfig {
11
- /**
12
- * Slack app client ID.
13
- * Get this from your Slack App settings at https://api.slack.com/apps
14
- *
15
- * @example
16
- * ```ts
17
- * {
18
- * clientID: "123456789.1234567890"
19
- * }
20
- * ```
21
- */
22
- readonly clientID: string;
23
- /**
24
- * Slack app client secret.
25
- * Keep this secure and never expose it to client-side code.
26
- *
27
- * @example
28
- * ```ts
29
- * {
30
- * clientSecret: process.env.SLACK_CLIENT_SECRET
31
- * }
32
- * ```
33
- */
34
- readonly clientSecret: string;
35
- /**
36
- * Slack OAuth scopes to request access for.
37
- * Determines what data and actions your app can access.
38
- *
39
- * @example
40
- * ```ts
41
- * {
42
- * scopes: [
43
- * "users:read", // Access to user profiles
44
- * "users:read.email", // Access user emails
45
- * "team:read" // Access team information
46
- * ]
47
- * }
48
- * ```
49
- */
50
- readonly scopes: string[];
51
- }
52
- /**
53
- * Creates a Slack OAuth 2.0 authentication provider.
54
- * Allows users to authenticate using their Slack accounts.
55
- *
56
- * @param config - Slack OAuth 2.0 configuration
57
- * @returns OAuth 2.0 provider configured for Slack
58
- *
59
- * @example
60
- * ```ts
61
- * // Basic Slack authentication
62
- * const basicSlack = SlackProvider({
63
- * clientID: process.env.SLACK_CLIENT_ID,
64
- * clientSecret: process.env.SLACK_CLIENT_SECRET
65
- * })
66
- *
67
- * // Slack with user scopes
68
- * const slackWithScopes = SlackProvider({
69
- * clientID: process.env.SLACK_CLIENT_ID,
70
- * clientSecret: process.env.SLACK_CLIENT_SECRET,
71
- * scopes: ["users:read", "users:read.email", "team:read"]
72
- * })
73
- *
74
- * // Using the access token to fetch user data
75
- * export default issuer({
76
- * providers: { slack: slackWithScopes },
77
- * success: async (ctx, value) => {
78
- * if (value.provider === "slack") {
79
- * const token = value.tokenset.access
80
- *
81
- * // Get basic user info
82
- * const authRes = await fetch('https://slack.com/api/auth.test', {
83
- * headers: { Authorization: `Bearer ${token}` }
84
- * })
85
- * const authInfo = await authRes.json()
86
- *
87
- * // Get detailed user info
88
- * const userRes = await fetch(
89
- * `https://slack.com/api/users.info?user=${authInfo.user_id}`,
90
- * { headers: { Authorization: `Bearer ${token}` } }
91
- * )
92
- * const { user } = await userRes.json()
93
- *
94
- * return ctx.subject("user", {
95
- * slackId: user.id,
96
- * username: user.name,
97
- * realName: user.real_name,
98
- * email: user.profile?.email,
99
- * workspace: authInfo.team_id
100
- * })
101
- * }
102
- * }
103
- * })
104
- * ```
105
- *
106
- * **Callback URL Pattern**: `{baseURL}{basePath}/{provider}/callback`
107
- * - Development: `http://localhost:3000/auth/slack/callback`
108
- * - Production: `https://yourapp.com/auth/slack/callback`
109
- *
110
- * Register this URL in your Slack App settings.
111
- */
112
- declare const SlackProvider: (config: SlackConfig) => Provider<Oauth2UserData>;
113
- //#endregion
114
- export { SlackConfig, SlackProvider };
@@ -1,138 +0,0 @@
1
- import { Oauth2Provider } from "./oauth2.mjs";
2
-
3
- //#region src/provider/slack.ts
4
- /**
5
- * Slack authentication provider for Draft Auth.
6
- * Implements OAuth 2.0 flow for authenticating users with their Slack accounts.
7
- *
8
- * ## Quick Setup
9
- *
10
- * ```ts
11
- * import { SlackProvider } from "@draftlab/auth/provider/slack"
12
- *
13
- * export default issuer({
14
- * basePath: "/auth", // Important for callback URL
15
- * providers: {
16
- * slack: SlackProvider({
17
- * clientID: process.env.SLACK_CLIENT_ID,
18
- * clientSecret: process.env.SLACK_CLIENT_SECRET,
19
- * scopes: ["users:read", "users:read.email"]
20
- * })
21
- * }
22
- * })
23
- * ```
24
- *
25
- * **Callback URL Pattern**: `{baseURL}{basePath}/{provider}/callback`
26
- * - Development: `http://localhost:3000/auth/slack/callback`
27
- * - Production: `https://yourapp.com/auth/slack/callback`
28
- *
29
- * Register this URL in your Slack App settings.
30
- *
31
- * ## Common Scopes
32
- *
33
- * - `users:read` - Access to user profiles
34
- * - `users:read.email` - Access user email addresses
35
- * - `team:read` - Access team information
36
- * - `channels:read` - View channels
37
- * - `groups:read` - View private channels
38
- * - `im:read` - View direct messages
39
- * - `mpim:read` - View group direct messages
40
- *
41
- * ## User Data Access
42
- *
43
- * ```ts
44
- * success: async (ctx, value) => {
45
- * if (value.provider === "slack") {
46
- * const accessToken = value.tokenset.access
47
- *
48
- * // Fetch user information
49
- * const userResponse = await fetch('https://slack.com/api/auth.test', {
50
- * headers: { Authorization: `Bearer ${accessToken}` }
51
- * })
52
- * const userInfo = await userResponse.json()
53
- *
54
- * // Get user details
55
- * const userDetailsResponse = await fetch(
56
- * `https://slack.com/api/users.info?user=${userInfo.user_id}`,
57
- * { headers: { Authorization: `Bearer ${accessToken}` } }
58
- * )
59
- * const { user } = await userDetailsResponse.json()
60
- * }
61
- * }
62
- * ```
63
- *
64
- * @packageDocumentation
65
- */
66
- /**
67
- * Creates a Slack OAuth 2.0 authentication provider.
68
- * Allows users to authenticate using their Slack accounts.
69
- *
70
- * @param config - Slack OAuth 2.0 configuration
71
- * @returns OAuth 2.0 provider configured for Slack
72
- *
73
- * @example
74
- * ```ts
75
- * // Basic Slack authentication
76
- * const basicSlack = SlackProvider({
77
- * clientID: process.env.SLACK_CLIENT_ID,
78
- * clientSecret: process.env.SLACK_CLIENT_SECRET
79
- * })
80
- *
81
- * // Slack with user scopes
82
- * const slackWithScopes = SlackProvider({
83
- * clientID: process.env.SLACK_CLIENT_ID,
84
- * clientSecret: process.env.SLACK_CLIENT_SECRET,
85
- * scopes: ["users:read", "users:read.email", "team:read"]
86
- * })
87
- *
88
- * // Using the access token to fetch user data
89
- * export default issuer({
90
- * providers: { slack: slackWithScopes },
91
- * success: async (ctx, value) => {
92
- * if (value.provider === "slack") {
93
- * const token = value.tokenset.access
94
- *
95
- * // Get basic user info
96
- * const authRes = await fetch('https://slack.com/api/auth.test', {
97
- * headers: { Authorization: `Bearer ${token}` }
98
- * })
99
- * const authInfo = await authRes.json()
100
- *
101
- * // Get detailed user info
102
- * const userRes = await fetch(
103
- * `https://slack.com/api/users.info?user=${authInfo.user_id}`,
104
- * { headers: { Authorization: `Bearer ${token}` } }
105
- * )
106
- * const { user } = await userRes.json()
107
- *
108
- * return ctx.subject("user", {
109
- * slackId: user.id,
110
- * username: user.name,
111
- * realName: user.real_name,
112
- * email: user.profile?.email,
113
- * workspace: authInfo.team_id
114
- * })
115
- * }
116
- * }
117
- * })
118
- * ```
119
- *
120
- * **Callback URL Pattern**: `{baseURL}{basePath}/{provider}/callback`
121
- * - Development: `http://localhost:3000/auth/slack/callback`
122
- * - Production: `https://yourapp.com/auth/slack/callback`
123
- *
124
- * Register this URL in your Slack App settings.
125
- */
126
- const SlackProvider = (config) => {
127
- return Oauth2Provider({
128
- ...config,
129
- type: "slack",
130
- endpoint: {
131
- authorization: "https://slack.com/oauth/v2/authorize",
132
- token: "https://slack.com/api/oauth.v2.access"
133
- }
134
- });
135
- };
136
-
137
- //#endregion
138
- export { SlackProvider };
@@ -1,113 +0,0 @@
1
- import { Provider } from "./provider.mjs";
2
- import { Oauth2UserData, Oauth2WrappedConfig } from "./oauth2.mjs";
3
-
4
- //#region src/provider/spotify.d.ts
5
-
6
- /**
7
- * Configuration options for Spotify OAuth 2.0 provider.
8
- * Extends the base OAuth 2.0 configuration with Spotify-specific documentation.
9
- */
10
- interface SpotifyConfig extends Oauth2WrappedConfig {
11
- /**
12
- * Spotify app client ID.
13
- * Get this from your Spotify App at https://developer.spotify.com/dashboard
14
- *
15
- * @example
16
- * ```ts
17
- * {
18
- * clientID: "abcdef123456"
19
- * }
20
- * ```
21
- */
22
- readonly clientID: string;
23
- /**
24
- * Spotify app client secret.
25
- * Keep this secure and never expose it to client-side code.
26
- *
27
- * @example
28
- * ```ts
29
- * {
30
- * clientSecret: process.env.SPOTIFY_CLIENT_SECRET
31
- * }
32
- * ```
33
- */
34
- readonly clientSecret: string;
35
- /**
36
- * Spotify OAuth scopes to request access for.
37
- * Determines what data and actions your app can access.
38
- *
39
- * @example
40
- * ```ts
41
- * {
42
- * scopes: [
43
- * "user-read-private", // Access private user data
44
- * "user-read-email", // Access user email
45
- * "user-top-read" // Read top artists and tracks
46
- * ]
47
- * }
48
- * ```
49
- */
50
- readonly scopes: string[];
51
- }
52
- /**
53
- * Creates a Spotify OAuth 2.0 authentication provider.
54
- * Allows users to authenticate using their Spotify accounts.
55
- *
56
- * @param config - Spotify OAuth 2.0 configuration
57
- * @returns OAuth 2.0 provider configured for Spotify
58
- *
59
- * @example
60
- * ```ts
61
- * // Basic Spotify authentication
62
- * const basicSpotify = SpotifyProvider({
63
- * clientID: process.env.SPOTIFY_CLIENT_ID,
64
- * clientSecret: process.env.SPOTIFY_CLIENT_SECRET
65
- * })
66
- *
67
- * // Spotify with user data access
68
- * const spotifyWithScopes = SpotifyProvider({
69
- * clientID: process.env.SPOTIFY_CLIENT_ID,
70
- * clientSecret: process.env.SPOTIFY_CLIENT_SECRET,
71
- * scopes: ["user-read-private", "user-read-email", "user-top-read"]
72
- * })
73
- *
74
- * // Using the access token to fetch user data
75
- * export default issuer({
76
- * providers: { spotify: spotifyWithScopes },
77
- * success: async (ctx, value) => {
78
- * if (value.provider === "spotify") {
79
- * const token = value.tokenset.access
80
- *
81
- * const userRes = await fetch('https://api.spotify.com/v1/me', {
82
- * headers: { Authorization: `Bearer ${token}` }
83
- * })
84
- * const user = await userRes.json()
85
- *
86
- * // Optionally fetch top tracks
87
- * const topRes = await fetch('https://api.spotify.com/v1/me/top/tracks?limit=5', {
88
- * headers: { Authorization: `Bearer ${token}` }
89
- * })
90
- * const { items: topTracks } = await topRes.json()
91
- *
92
- * return ctx.subject("user", {
93
- * spotifyId: user.id,
94
- * email: user.email,
95
- * displayName: user.display_name,
96
- * profileUrl: user.external_urls?.spotify,
97
- * followers: user.followers?.total,
98
- * topTracks: topTracks.map(t => t.name)
99
- * })
100
- * }
101
- * }
102
- * })
103
- * ```
104
- *
105
- * **Callback URL Pattern**: `{baseURL}{basePath}/{provider}/callback`
106
- * - Development: `http://localhost:3000/auth/spotify/callback`
107
- * - Production: `https://yourapp.com/auth/spotify/callback`
108
- *
109
- * Register this URL in your Spotify Developer Dashboard.
110
- */
111
- declare const SpotifyProvider: (config: SpotifyConfig) => Provider<Oauth2UserData>;
112
- //#endregion
113
- export { SpotifyConfig, SpotifyProvider };