@aura-stack/auth 0.4.0-rc.5 → 0.5.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 (201) hide show
  1. package/dist/@types/index.d.ts +8 -3
  2. package/dist/@types/router.d.cjs +0 -17
  3. package/dist/@types/router.d.d.ts +7 -2
  4. package/dist/@types/router.d.js +0 -1
  5. package/dist/actions/callback/access-token.cjs +130 -71
  6. package/dist/actions/callback/access-token.d.ts +9 -4
  7. package/dist/actions/callback/access-token.js +3 -4
  8. package/dist/actions/callback/callback.cjs +428 -152
  9. package/dist/actions/callback/callback.d.ts +11 -3
  10. package/dist/actions/callback/callback.js +12 -10
  11. package/dist/actions/callback/userinfo.cjs +159 -65
  12. package/dist/actions/callback/userinfo.d.ts +8 -3
  13. package/dist/actions/callback/userinfo.js +7 -6
  14. package/dist/actions/csrfToken/csrfToken.cjs +70 -19
  15. package/dist/actions/csrfToken/csrfToken.js +8 -7
  16. package/dist/actions/index.cjs +780 -348
  17. package/dist/actions/index.d.ts +6 -2
  18. package/dist/actions/index.js +23 -18
  19. package/dist/actions/session/session.cjs +107 -26
  20. package/dist/actions/session/session.js +7 -5
  21. package/dist/actions/signIn/authorization-url.cjs +288 -0
  22. package/dist/actions/signIn/authorization-url.d.ts +31 -0
  23. package/dist/actions/signIn/authorization-url.js +16 -0
  24. package/dist/actions/signIn/authorization.cjs +209 -211
  25. package/dist/actions/signIn/authorization.d.ts +32 -21
  26. package/dist/actions/signIn/authorization.js +12 -9
  27. package/dist/actions/signIn/signIn.cjs +470 -235
  28. package/dist/actions/signIn/signIn.d.ts +12 -3
  29. package/dist/actions/signIn/signIn.js +11 -8
  30. package/dist/actions/signOut/signOut.cjs +376 -228
  31. package/dist/actions/signOut/signOut.d.ts +1 -1
  32. package/dist/actions/signOut/signOut.js +10 -9
  33. package/dist/api/createApi.cjs +750 -0
  34. package/dist/api/createApi.d.ts +12 -0
  35. package/dist/api/createApi.js +19 -0
  36. package/dist/api/getSession.cjs +141 -0
  37. package/dist/api/getSession.d.ts +16 -0
  38. package/dist/api/getSession.js +10 -0
  39. package/dist/api/signIn.cjs +549 -0
  40. package/dist/api/signIn.d.ts +26 -0
  41. package/dist/api/signIn.js +15 -0
  42. package/dist/api/signOut.cjs +279 -0
  43. package/dist/api/signOut.d.ts +16 -0
  44. package/dist/api/signOut.js +13 -0
  45. package/dist/assert.cjs +150 -5
  46. package/dist/assert.d.ts +26 -3
  47. package/dist/assert.js +17 -3
  48. package/dist/{chunk-YRCB5FLE.js → chunk-2A5B7GWR.js} +52 -6
  49. package/dist/chunk-2GQLSIJ2.js +40 -0
  50. package/dist/chunk-2IR674WX.js +44 -0
  51. package/dist/chunk-3J5TUH2I.js +50 -0
  52. package/dist/chunk-4RWSYUKX.js +98 -0
  53. package/dist/chunk-4YHJ4IEQ.js +25 -0
  54. package/dist/chunk-54CZPKR4.js +25 -0
  55. package/dist/chunk-5LZ7TOM3.js +25 -0
  56. package/dist/chunk-7BE46WWS.js +88 -0
  57. package/dist/chunk-7YYXFKLR.js +35 -0
  58. package/dist/chunk-C3A37LQC.js +33 -0
  59. package/dist/chunk-CITNGXDA.js +31 -0
  60. package/dist/chunk-CWX724AG.js +78 -0
  61. package/dist/chunk-D2CSIUKP.js +74 -0
  62. package/dist/chunk-E6G5YCI6.js +25 -0
  63. package/dist/chunk-EBAMFRB7.js +34 -0
  64. package/dist/chunk-EEE7UM5T.js +25 -0
  65. package/dist/{chunk-HT4YLL7N.js → chunk-FPCVZUVG.js} +10 -8
  66. package/dist/chunk-FW4W3REU.js +25 -0
  67. package/dist/chunk-GNNBM2WJ.js +83 -0
  68. package/dist/chunk-IPKO6UQN.js +25 -0
  69. package/dist/chunk-JOCGX3RP.js +59 -0
  70. package/dist/chunk-KBXWTD6E.js +94 -0
  71. package/dist/chunk-KMMAZFSJ.js +25 -0
  72. package/dist/chunk-LATR3NIV.js +117 -0
  73. package/dist/chunk-LAYPUDQF.js +39 -0
  74. package/dist/chunk-LDU7A2JE.js +25 -0
  75. package/dist/chunk-LX3TJ2TJ.js +294 -0
  76. package/dist/chunk-NHZBQNRR.js +143 -0
  77. package/dist/chunk-OVHNRULD.js +33 -0
  78. package/dist/chunk-PDP3PHB3.js +127 -0
  79. package/dist/chunk-PHYNROD4.js +47 -0
  80. package/dist/chunk-QQEKY4XP.js +29 -0
  81. package/dist/chunk-U4RK4LKJ.js +348 -0
  82. package/dist/{chunk-RRLIF4PQ.js → chunk-U5663F2U.js} +16 -1
  83. package/dist/chunk-UN7X6SU5.js +53 -0
  84. package/dist/chunk-UZQJJD6A.js +100 -0
  85. package/dist/chunk-V6LLEAR4.js +80 -0
  86. package/dist/chunk-WHNDRO3N.js +50 -0
  87. package/dist/{chunk-W6LG7BFW.js → chunk-XY5R3EHH.js} +30 -23
  88. package/dist/client/client.cjs +135 -0
  89. package/dist/client/client.d.ts +85 -0
  90. package/dist/client/client.js +9 -0
  91. package/dist/client/index.cjs +135 -0
  92. package/dist/client/index.d.ts +14 -0
  93. package/dist/client/index.js +10 -0
  94. package/dist/context.cjs +1237 -0
  95. package/dist/context.d.ts +16 -0
  96. package/dist/context.js +28 -0
  97. package/dist/cookie.cjs +57 -22
  98. package/dist/cookie.d.ts +11 -6
  99. package/dist/cookie.js +3 -2
  100. package/dist/createAuth.cjs +2320 -0
  101. package/dist/createAuth.d.ts +12 -0
  102. package/dist/createAuth.js +48 -0
  103. package/dist/env.cjs +78 -0
  104. package/dist/env.d.ts +10 -0
  105. package/dist/env.js +12 -0
  106. package/dist/errors.cjs +17 -0
  107. package/dist/errors.d.ts +15 -4
  108. package/dist/errors.js +5 -1
  109. package/dist/headers.cjs +28 -2
  110. package/dist/headers.d.ts +25 -1
  111. package/dist/headers.js +9 -3
  112. package/dist/index-_aXtxb_s.d.ts +1377 -0
  113. package/dist/index.cjs +1843 -610
  114. package/dist/index.d.ts +11 -92
  115. package/dist/index.js +53 -85
  116. package/dist/jose.cjs +113 -38
  117. package/dist/jose.d.ts +12 -23
  118. package/dist/jose.js +17 -7
  119. package/dist/logger.cjs +424 -0
  120. package/dist/logger.d.ts +12 -0
  121. package/dist/logger.js +17 -0
  122. package/dist/oauth/atlassian.cjs +57 -0
  123. package/dist/oauth/atlassian.d.ts +12 -0
  124. package/dist/oauth/atlassian.js +6 -0
  125. package/dist/oauth/bitbucket.cjs +19 -15
  126. package/dist/oauth/bitbucket.d.ts +7 -2
  127. package/dist/oauth/bitbucket.js +1 -1
  128. package/dist/oauth/discord.cjs +27 -24
  129. package/dist/oauth/discord.d.ts +7 -2
  130. package/dist/oauth/discord.js +1 -1
  131. package/dist/oauth/dropbox.cjs +53 -0
  132. package/dist/oauth/dropbox.d.ts +12 -0
  133. package/dist/oauth/dropbox.js +6 -0
  134. package/dist/oauth/figma.cjs +19 -16
  135. package/dist/oauth/figma.d.ts +7 -2
  136. package/dist/oauth/figma.js +1 -1
  137. package/dist/oauth/github.cjs +19 -8
  138. package/dist/oauth/github.d.ts +7 -2
  139. package/dist/oauth/github.js +1 -1
  140. package/dist/oauth/gitlab.cjs +19 -16
  141. package/dist/oauth/gitlab.d.ts +7 -2
  142. package/dist/oauth/gitlab.js +1 -1
  143. package/dist/oauth/index.cjs +529 -239
  144. package/dist/oauth/index.d.ts +7 -2
  145. package/dist/oauth/index.js +39 -22
  146. package/dist/oauth/mailchimp.cjs +19 -16
  147. package/dist/oauth/mailchimp.d.ts +7 -2
  148. package/dist/oauth/mailchimp.js +1 -1
  149. package/dist/oauth/notion.cjs +131 -0
  150. package/dist/oauth/notion.d.ts +12 -0
  151. package/dist/oauth/notion.js +9 -0
  152. package/dist/oauth/pinterest.cjs +19 -16
  153. package/dist/oauth/pinterest.d.ts +7 -2
  154. package/dist/oauth/pinterest.js +1 -1
  155. package/dist/oauth/spotify.cjs +19 -16
  156. package/dist/oauth/spotify.d.ts +7 -2
  157. package/dist/oauth/spotify.js +1 -1
  158. package/dist/oauth/strava.cjs +19 -16
  159. package/dist/oauth/strava.d.ts +7 -2
  160. package/dist/oauth/strava.js +1 -1
  161. package/dist/oauth/twitch.cjs +95 -0
  162. package/dist/oauth/twitch.d.ts +12 -0
  163. package/dist/oauth/twitch.js +7 -0
  164. package/dist/oauth/x.cjs +19 -16
  165. package/dist/oauth/x.d.ts +7 -2
  166. package/dist/oauth/x.js +1 -1
  167. package/dist/schemas.cjs +89 -42
  168. package/dist/schemas.d.ts +114 -18
  169. package/dist/schemas.js +5 -3
  170. package/dist/secure.cjs +73 -31
  171. package/dist/secure.d.ts +11 -11
  172. package/dist/secure.js +7 -6
  173. package/dist/utils.cjs +203 -90
  174. package/dist/utils.d.ts +21 -40
  175. package/dist/utils.js +21 -12
  176. package/package.json +9 -6
  177. package/dist/chunk-3EUWD5BB.js +0 -63
  178. package/dist/chunk-42XB3YCW.js +0 -22
  179. package/dist/chunk-6R2YZ4AC.js +0 -22
  180. package/dist/chunk-A3N4PVAT.js +0 -70
  181. package/dist/chunk-B737EUJV.js +0 -22
  182. package/dist/chunk-CXLATHS5.js +0 -143
  183. package/dist/chunk-E3OXBRYF.js +0 -22
  184. package/dist/chunk-EIL2FPSS.js +0 -22
  185. package/dist/chunk-EMKJA2GJ.js +0 -89
  186. package/dist/chunk-FIPU4MLT.js +0 -21
  187. package/dist/chunk-FKRDCWBF.js +0 -22
  188. package/dist/chunk-GA2SMTJO.js +0 -58
  189. package/dist/chunk-HP34YGGJ.js +0 -22
  190. package/dist/chunk-IKHPGFCW.js +0 -14
  191. package/dist/chunk-IUYZQTJV.js +0 -30
  192. package/dist/chunk-IVET23KF.js +0 -58
  193. package/dist/chunk-JVFTCTTE.js +0 -33
  194. package/dist/chunk-KRNOMBXQ.js +0 -22
  195. package/dist/chunk-KSWLO5ZU.js +0 -102
  196. package/dist/chunk-N2APGLXA.js +0 -71
  197. package/dist/chunk-N4SX7TZT.js +0 -96
  198. package/dist/chunk-STHEPPUZ.js +0 -11
  199. package/dist/chunk-TLE4PXY3.js +0 -39
  200. package/dist/index-B8jeIElf.d.ts +0 -679
  201. /package/dist/{chunk-DIVDFNAP.js → chunk-5X7JZMEF.js} +0 -0
@@ -0,0 +1,549 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/api/signIn.ts
21
+ var signIn_exports = {};
22
+ __export(signIn_exports, {
23
+ signIn: () => signIn
24
+ });
25
+ module.exports = __toCommonJS(signIn_exports);
26
+
27
+ // src/headers.ts
28
+ var cacheControl = {
29
+ "Cache-Control": "no-store",
30
+ Pragma: "no-cache",
31
+ Expires: "0",
32
+ Vary: "Cookie"
33
+ };
34
+ var contentSecurityPolicy = {
35
+ "Content-Security-Policy": [
36
+ "default-src 'none'",
37
+ "script-src 'self'",
38
+ "frame-src 'none'",
39
+ "object-src 'none'",
40
+ "frame-ancestors 'none'",
41
+ "base-uri 'none'"
42
+ ].join("; ")
43
+ };
44
+ var secureHeaders = {
45
+ "X-Content-Type-Options": "nosniff",
46
+ "X-Frame-Options": "DENY",
47
+ "Referrer-Policy": "strict-origin-when-cross-origin"
48
+ };
49
+ var secureApiHeaders = {
50
+ ...cacheControl,
51
+ ...contentSecurityPolicy,
52
+ ...secureHeaders
53
+ };
54
+
55
+ // src/errors.ts
56
+ var AuthInternalError = class extends Error {
57
+ type = "AUTH_INTERNAL_ERROR";
58
+ code;
59
+ constructor(code, message, options2) {
60
+ super(message, options2);
61
+ this.code = code;
62
+ this.name = new.target.name;
63
+ Error.captureStackTrace(this, new.target);
64
+ }
65
+ };
66
+ var AuthSecurityError = class extends Error {
67
+ type = "AUTH_SECURITY_ERROR";
68
+ code;
69
+ constructor(code, message, options2) {
70
+ super(message, options2);
71
+ this.code = code;
72
+ this.name = new.target.name;
73
+ Error.captureStackTrace(this, new.target);
74
+ }
75
+ };
76
+
77
+ // src/api/signIn.ts
78
+ var import_router2 = require("@aura-stack/router");
79
+
80
+ // src/schemas.ts
81
+ var import_v4 = require("zod/v4");
82
+ var AuthorizeConfigSchema = import_v4.z.union([
83
+ (0, import_v4.string)().url(),
84
+ (0, import_v4.object)({
85
+ url: (0, import_v4.string)().url(),
86
+ params: (0, import_v4.object)({
87
+ responseType: (0, import_v4.enum)(["code", "token", "id_token", "refresh_token"]).optional(),
88
+ scope: (0, import_v4.string)().optional()
89
+ })
90
+ })
91
+ ]);
92
+ var AccessTokenConfigSchema = import_v4.z.union([
93
+ (0, import_v4.string)().url(),
94
+ (0, import_v4.object)({
95
+ url: (0, import_v4.string)().url(),
96
+ headers: import_v4.z.record((0, import_v4.string)(), (0, import_v4.string)()).optional()
97
+ })
98
+ ]);
99
+ var UserInfoConfigSchema = import_v4.z.union([
100
+ (0, import_v4.string)().url(),
101
+ (0, import_v4.object)({
102
+ url: (0, import_v4.string)().url(),
103
+ headers: import_v4.z.record((0, import_v4.string)(), (0, import_v4.string)()).optional(),
104
+ method: (0, import_v4.string)().optional()
105
+ })
106
+ ]);
107
+ var OAuthProviderCredentialsSchema = (0, import_v4.object)({
108
+ id: (0, import_v4.string)(),
109
+ name: (0, import_v4.string)(),
110
+ authorize: AuthorizeConfigSchema.optional(),
111
+ /** @deprecated */
112
+ authorizeURL: (0, import_v4.string)().url().optional(),
113
+ accessToken: AccessTokenConfigSchema,
114
+ /** @deprecated */
115
+ scope: (0, import_v4.string)().optional(),
116
+ userInfo: UserInfoConfigSchema,
117
+ /** @deprecated */
118
+ responseType: (0, import_v4.enum)(["code", "token", "id_token", "refresh_token"]).optional(),
119
+ clientId: (0, import_v4.string)(),
120
+ clientSecret: (0, import_v4.string)(),
121
+ profile: import_v4.z.function().optional()
122
+ });
123
+ var OAuthProviderConfigSchema = (0, import_v4.object)({
124
+ authorize: AuthorizeConfigSchema.optional(),
125
+ /** @deprecated */
126
+ authorizeURL: (0, import_v4.string)().url().optional(),
127
+ accessToken: AccessTokenConfigSchema,
128
+ /** @deprecated */
129
+ scope: (0, import_v4.string)().optional(),
130
+ userInfo: UserInfoConfigSchema,
131
+ /** @deprecated */
132
+ responseType: (0, import_v4.enum)(["code", "token", "id_token", "refresh_token"]).optional(),
133
+ clientId: (0, import_v4.string)(),
134
+ clientSecret: (0, import_v4.string)()
135
+ });
136
+ var OAuthAuthorization = OAuthProviderConfigSchema.extend({
137
+ redirectURI: (0, import_v4.string)(),
138
+ state: (0, import_v4.string)(),
139
+ codeChallenge: (0, import_v4.string)(),
140
+ codeChallengeMethod: (0, import_v4.enum)(["plain", "S256"])
141
+ });
142
+ var OAuthAuthorizationResponse = (0, import_v4.object)({
143
+ state: (0, import_v4.string)({ message: "Missing state parameter in the OAuth authorization response." }),
144
+ code: (0, import_v4.string)({ message: "Missing code parameter in the OAuth authorization response." })
145
+ });
146
+ var OAuthAuthorizationErrorResponse = (0, import_v4.object)({
147
+ error: (0, import_v4.enum)([
148
+ "invalid_request",
149
+ "unauthorized_client",
150
+ "access_denied",
151
+ "unsupported_response_type",
152
+ "invalid_scope",
153
+ "server_error",
154
+ "temporarily_unavailable"
155
+ ]),
156
+ error_description: (0, import_v4.string)().optional(),
157
+ error_uri: (0, import_v4.string)().optional(),
158
+ state: (0, import_v4.string)()
159
+ });
160
+ var OAuthAccessToken = OAuthProviderConfigSchema.extend({
161
+ redirectURI: (0, import_v4.string)(),
162
+ code: (0, import_v4.string)(),
163
+ codeVerifier: (0, import_v4.string)().min(43).max(128)
164
+ });
165
+ var OAuthAccessTokenResponse = (0, import_v4.object)({
166
+ access_token: (0, import_v4.string)(),
167
+ token_type: (0, import_v4.string)().optional(),
168
+ expires_in: (0, import_v4.number)().optional(),
169
+ refresh_token: (0, import_v4.string)().optional(),
170
+ scope: (0, import_v4.union)([(0, import_v4.string)().optional().or((0, import_v4.null)()), (0, import_v4.array)((0, import_v4.string)()).optional()])
171
+ });
172
+ var OAuthAccessTokenErrorResponse = (0, import_v4.object)({
173
+ error: (0, import_v4.enum)([
174
+ "invalid_request",
175
+ "invalid_client",
176
+ "invalid_grant",
177
+ "unauthorized_client",
178
+ "unsupported_grant_type",
179
+ "invalid_scope"
180
+ ]),
181
+ error_description: (0, import_v4.string)().optional(),
182
+ error_uri: (0, import_v4.string)().optional()
183
+ });
184
+ var OAuthErrorResponse = (0, import_v4.object)({
185
+ error: (0, import_v4.string)(),
186
+ error_description: (0, import_v4.string)().optional()
187
+ });
188
+ var OAuthEnvSchema = (0, import_v4.object)({
189
+ clientId: import_v4.z.string().min(1, "OAuth Client ID is required in the environment variables."),
190
+ clientSecret: import_v4.z.string().min(1, "OAuth Client Secret is required in the environment variables.")
191
+ });
192
+
193
+ // src/utils.ts
194
+ var import_router = require("@aura-stack/router");
195
+
196
+ // src/env.ts
197
+ var import_meta = {};
198
+ var env = new Proxy({}, {
199
+ get(_, prop) {
200
+ if (typeof prop !== "string") return void 0;
201
+ const hasProperty = (process2) => {
202
+ return process2 && Object.prototype.hasOwnProperty.call(process2, prop);
203
+ };
204
+ try {
205
+ if (typeof process !== "undefined" && hasProperty(process.env)) {
206
+ return process.env[prop];
207
+ }
208
+ if (typeof import_meta !== "undefined" && hasProperty(import_meta.env)) {
209
+ return import_meta.env[prop];
210
+ }
211
+ if (typeof Deno !== "undefined" && Deno.env?.get) {
212
+ return Deno.env.get(prop);
213
+ }
214
+ if (typeof Bun !== "undefined" && hasProperty(Bun.env)) {
215
+ return Bun.env[prop];
216
+ }
217
+ const globalValue = globalThis[prop];
218
+ return typeof globalValue === "string" ? globalValue : void 0;
219
+ } catch {
220
+ return void 0;
221
+ }
222
+ }
223
+ });
224
+ var getEnv = (key) => {
225
+ const keys = [`AURA_AUTH_${key.toUpperCase()}`, `AURA_${key.toUpperCase()}`, `AUTH_${key.toUpperCase()}`, key.toUpperCase()];
226
+ return env[keys.find((k) => env[k]) ?? ""];
227
+ };
228
+
229
+ // src/assert.ts
230
+ var import_crypto = require("@aura-stack/jose/crypto");
231
+ var unsafeChars = [
232
+ "<",
233
+ ">",
234
+ '"',
235
+ "`",
236
+ " ",
237
+ "\r",
238
+ "\n",
239
+ " ",
240
+ "\\",
241
+ "%2F",
242
+ "%5C",
243
+ "%2f",
244
+ "%5c",
245
+ "\r\n",
246
+ "%0A",
247
+ "%0D",
248
+ "%0a",
249
+ "%0d",
250
+ "..",
251
+ "//",
252
+ "///",
253
+ "...",
254
+ "%20",
255
+ "\0"
256
+ ];
257
+ var isValidURL = (value) => {
258
+ if (!new RegExp(/^https?:\/\/[^/]/).test(value)) {
259
+ return false;
260
+ }
261
+ const match = value.match(/^(https?:\/\/)(.*)$/);
262
+ if (!match) return false;
263
+ const rest = match[2];
264
+ for (const char of unsafeChars) {
265
+ if (rest.includes(char)) return false;
266
+ }
267
+ const regex = /^https?:\/\/(?:[a-zA-Z0-9._-]+|localhost|\[[0-9a-fA-F:]+\])(?::\d{1,5})?(?:\/[a-zA-Z0-9._~!$&'()?#*+,;=:@-]*)*\/?$/;
268
+ return regex.test(match[0]);
269
+ };
270
+ var isRelativeURL = (value) => {
271
+ if (value.length > 100) return false;
272
+ for (const char of unsafeChars) {
273
+ if (value.includes(char)) return false;
274
+ }
275
+ const regex = /^\/[a-zA-Z0-9\-_\/.?&=#]*\/?$/;
276
+ return regex.test(value);
277
+ };
278
+ var isSameOrigin = (origin, expected) => {
279
+ const originURL = new URL(origin);
280
+ const expectedURL = new URL(expected);
281
+ return equals(originURL.origin, expectedURL.origin);
282
+ };
283
+ var patternToRegex = (pattern) => {
284
+ try {
285
+ if (pattern.length > 2048) return null;
286
+ pattern = pattern.replace(/\\/g, "");
287
+ const match = pattern.match(/^(https?):\/\/([a-zA-Z0-9.*-]{1,253})(?::(\d{1,5}|\*))?(?:\/.*)?$/);
288
+ if (!match) return null;
289
+ const [, protocol, host, port] = match;
290
+ const hasWildcard = host.includes("*");
291
+ if (hasWildcard && !host.startsWith("*.")) return null;
292
+ if (hasWildcard && host.slice(2).includes("*")) return null;
293
+ const domain = hasWildcard ? host.slice(2) : host;
294
+ const escapedDomain = domain.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
295
+ const hostRegex = hasWildcard ? `[^.]+\\.${escapedDomain}` : escapedDomain;
296
+ const portRegex = port === "*" ? ":\\d{1,5}" : port ? `:${port}` : "";
297
+ return new RegExp(`^${protocol}:\\/\\/${hostRegex}${portRegex}$`);
298
+ } catch {
299
+ return null;
300
+ }
301
+ };
302
+ var isTrustedOrigin = (url, trustedOrigins) => {
303
+ if (!isValidURL(url) || trustedOrigins.length === 0) return false;
304
+ try {
305
+ const urlOrigin = new URL(url).origin;
306
+ for (const pattern of trustedOrigins) {
307
+ const regex = patternToRegex(pattern);
308
+ if (regex?.test(urlOrigin)) return true;
309
+ try {
310
+ if (isValidURL(pattern) && equals(new URL(pattern).origin, urlOrigin)) return true;
311
+ } catch {
312
+ }
313
+ }
314
+ } catch {
315
+ }
316
+ return false;
317
+ };
318
+
319
+ // src/utils.ts
320
+ var equals = (a, b) => {
321
+ if (a === null || b === null || a === void 0 || b === void 0) return false;
322
+ return a === b;
323
+ };
324
+ var extractPath = (url) => {
325
+ const pathRegex = /^https?:\/\/[a-zA-Z0-9_\-\.]+(:\d+)?(\/.*)$/;
326
+ const match = url.match(pathRegex);
327
+ return match && match[2] ? match[2] : "/";
328
+ };
329
+
330
+ // src/jose.ts
331
+ var import_jose = require("@aura-stack/jose");
332
+ var import_jose2 = require("@aura-stack/jose/jose");
333
+ var import_crypto2 = require("@aura-stack/jose/crypto");
334
+
335
+ // src/secure.ts
336
+ var generateSecure = (length = 32) => {
337
+ return import_jose2.base64url.encode((0, import_crypto2.getRandomBytes)(length));
338
+ };
339
+ var createSecretValue = (length = 32) => {
340
+ return import_jose2.base64url.encode((0, import_crypto2.getRandomBytes)(length));
341
+ };
342
+ var createHash = async (data) => {
343
+ const subtle = (0, import_crypto2.getSubtleCrypto)();
344
+ const digest = await subtle.digest("SHA-256", import_crypto2.encoder.encode(data));
345
+ return import_jose2.base64url.encode(new Uint8Array(digest));
346
+ };
347
+ var createPKCE = async (verifier) => {
348
+ const byteLength = verifier ? void 0 : Math.floor(Math.random() * (96 - 32 + 1) + 32);
349
+ const codeVerifier = verifier ?? generateSecure(byteLength ?? 64);
350
+ if (codeVerifier.length < 43 || codeVerifier.length > 128) {
351
+ throw new AuthSecurityError("PKCE_VERIFIER_INVALID", "The code verifier must be between 43 and 128 characters in length.");
352
+ }
353
+ const codeChallenge = await createHash(codeVerifier);
354
+ return { codeVerifier, codeChallenge, method: "S256" };
355
+ };
356
+
357
+ // src/actions/signIn/authorization-url.ts
358
+ var setSearchParams = (url, params) => {
359
+ for (const [key, value] of Object.entries(params)) {
360
+ if (value !== void 0 && value !== "") {
361
+ url.searchParams.set(key, value);
362
+ }
363
+ }
364
+ };
365
+ var buildAuthorizationURL = (oauth, redirect_uri, state, code_challenge, code_challenge_method) => {
366
+ const authorizeConfig = oauth.authorize;
367
+ const baseURL = typeof authorizeConfig === "string" ? authorizeConfig : authorizeConfig?.url ?? oauth.authorizeURL;
368
+ if (!baseURL) {
369
+ throw new AuthInternalError("INVALID_OAUTH_CONFIGURATION", "Missing authorization URL in OAuth provider configuration.");
370
+ }
371
+ const url = new URL(baseURL);
372
+ const authorizeParams = typeof authorizeConfig === "string" ? void 0 : authorizeConfig?.params;
373
+ setSearchParams(url, {
374
+ response_type: authorizeParams?.responseType ?? oauth.responseType ?? "code",
375
+ client_id: oauth.clientId,
376
+ redirect_uri,
377
+ state,
378
+ code_challenge,
379
+ code_challenge_method,
380
+ scope: authorizeParams?.scope ?? oauth.scope,
381
+ prompt: authorizeParams?.prompt,
382
+ response_mode: authorizeParams?.responseMode,
383
+ login_hint: authorizeParams?.loginHint,
384
+ nonce: authorizeParams?.nonce,
385
+ display: authorizeParams?.display,
386
+ audience: authorizeParams?.audience
387
+ });
388
+ return url.toString();
389
+ };
390
+ var createAuthorizationURL = async (oauth, redirectURI, ctx) => {
391
+ const state = createSecretValue();
392
+ const { codeVerifier, codeChallenge, method } = await createPKCE();
393
+ const authorization = buildAuthorizationURL(oauth, redirectURI, state, codeChallenge, method);
394
+ const parsed = OAuthAuthorization.safeParse({ ...oauth, redirectURI, state, codeChallenge, codeChallengeMethod: method });
395
+ if (!parsed.success) {
396
+ ctx?.logger?.log("INVALID_OAUTH_CONFIGURATION", {
397
+ structuredData: {
398
+ scope: oauth?.scope ?? "",
399
+ redirect_uri: redirectURI,
400
+ has_state: Boolean(state),
401
+ has_code_challenge: Boolean(codeChallenge),
402
+ code_challenge_method: method
403
+ }
404
+ });
405
+ throw new AuthInternalError("INVALID_OAUTH_CONFIGURATION", "The OAuth provider configuration is invalid.");
406
+ }
407
+ return {
408
+ authorization,
409
+ state,
410
+ codeVerifier,
411
+ method
412
+ };
413
+ };
414
+
415
+ // src/actions/signIn/authorization.ts
416
+ var getTrustedOrigins = async (request, trustedOrigins) => {
417
+ if (!trustedOrigins) return [];
418
+ const raw = typeof trustedOrigins === "function" ? await trustedOrigins(request) : trustedOrigins;
419
+ return Array.isArray(raw) ? raw : typeof raw === "string" ? [raw] : [];
420
+ };
421
+ var getBaseURL = async ({
422
+ ctx,
423
+ request,
424
+ headers: headersInit
425
+ }) => {
426
+ const origin = getEnv("BASE_URL") || ctx?.baseURL;
427
+ if (origin && origin !== "/") return origin;
428
+ if (ctx?.trustedProxyHeaders) {
429
+ const headers = headersInit && new Headers(headersInit) || request?.headers;
430
+ const protocol = headers?.get("Forwarded")?.match(/proto=([^;]+)/i)?.[1] ?? headers?.get("X-Forwarded-Proto") ?? "http";
431
+ const host = headers?.get("Host") ?? headers?.get("Forwarded")?.match(/host=([^;]+)/i)?.[1] ?? headers?.get("X-Forwarded-Host") ?? null;
432
+ if (host) return `${protocol}://${host}`;
433
+ throw new AuthInternalError(
434
+ "INVALID_OAUTH_CONFIGURATION",
435
+ "The URL cannot be constructed. Please set the BASE_URL environment variable or provide trusted proxy host headers."
436
+ );
437
+ }
438
+ try {
439
+ return new URL(request?.url ?? "not-found").origin;
440
+ } catch (error) {
441
+ throw new AuthInternalError(
442
+ "INVALID_OAUTH_CONFIGURATION",
443
+ "The URL cannot be constructed. Please set the BASE_URL environment variable or enable trustedProxyHeaders.",
444
+ { cause: error }
445
+ );
446
+ }
447
+ };
448
+ var getOriginURL = async (request, context) => {
449
+ const trustedOrigins = await getTrustedOrigins(request, context?.trustedOrigins);
450
+ trustedOrigins.push(new URL(request.url).origin);
451
+ const origin = await getBaseURL({ request, ctx: context });
452
+ if (!isTrustedOrigin(origin, trustedOrigins)) {
453
+ context?.logger?.log("UNTRUSTED_ORIGIN", { structuredData: { origin } });
454
+ throw new AuthInternalError("UNTRUSTED_ORIGIN", "The constructed origin URL is not trusted.");
455
+ }
456
+ return origin;
457
+ };
458
+ var createRedirectURI = async (request, oauth, context) => {
459
+ const origin = await getOriginURL(request, context);
460
+ return `${origin}${context.basePath}/callback/${oauth}`;
461
+ };
462
+ var createSignInURL = async ({
463
+ request,
464
+ oauth,
465
+ ctx,
466
+ redirectTo
467
+ }) => {
468
+ const origin = await getOriginURL(request, ctx);
469
+ const searchParams = new URLSearchParams();
470
+ if (redirectTo !== void 0) searchParams.set("redirectTo", String(redirectTo));
471
+ return `${origin}${ctx.basePath}/signIn/${oauth}?${searchParams.toString()}`;
472
+ };
473
+ var createRedirectTo = async (request, redirectTo, context) => {
474
+ try {
475
+ const headers = request.headers;
476
+ const requestOrigin = await getOriginURL(request, context);
477
+ const origins = await getTrustedOrigins(request, context?.trustedOrigins);
478
+ const validateURL = (url) => {
479
+ if (!isRelativeURL(url) && !isValidURL(url)) return "/";
480
+ if (isRelativeURL(url)) return url;
481
+ if (origins.length > 0) {
482
+ if (isTrustedOrigin(url, origins)) {
483
+ const urlOrigin = new URL(url).origin;
484
+ for (const pattern of origins) {
485
+ const regex = patternToRegex(pattern);
486
+ if (regex?.test(urlOrigin)) {
487
+ return isSameOrigin(url, request.url) ? extractPath(url) : url;
488
+ }
489
+ if (isValidURL(pattern) && equals(new URL(pattern).origin, urlOrigin)) return url;
490
+ }
491
+ }
492
+ context?.logger?.log("OPEN_REDIRECT_ATTACK");
493
+ return "/";
494
+ }
495
+ if (isSameOrigin(url, requestOrigin)) {
496
+ return extractPath(url);
497
+ }
498
+ context?.logger?.log("OPEN_REDIRECT_ATTACK");
499
+ return "/";
500
+ };
501
+ return validateURL(redirectTo ?? headers.get("Referer") ?? headers.get("Origin") ?? "/");
502
+ } catch (error) {
503
+ context?.logger?.log("POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED");
504
+ return "/";
505
+ }
506
+ };
507
+
508
+ // src/api/signIn.ts
509
+ var signIn = async (oauth, {
510
+ ctx,
511
+ headers: headersInit,
512
+ redirectTo = "/",
513
+ redirect,
514
+ request: requestInit
515
+ }) => {
516
+ const headers = new Headers(headersInit);
517
+ const provider = ctx.oauth[oauth];
518
+ if (!provider) {
519
+ throw new AuthInternalError("INVALID_OAUTH_CONFIGURATION", `The OAuth provider "${oauth}" is not configured.`);
520
+ }
521
+ let request = requestInit;
522
+ if (!request) {
523
+ const origin = await getBaseURL({ ctx, headers });
524
+ const url = `${origin}${ctx.basePath}/signIn/${oauth}`;
525
+ request = new Request(url, { headers });
526
+ }
527
+ if (redirect === false) {
528
+ const signInURL = await createSignInURL({ request, oauth, ctx, redirectTo });
529
+ return { redirect: false, signInURL };
530
+ }
531
+ const redirectURI = await createRedirectURI(request, oauth, ctx);
532
+ const redirectToValue = await createRedirectTo(request, redirectTo, ctx);
533
+ const { authorization, state, codeVerifier } = await createAuthorizationURL(provider, redirectURI, ctx);
534
+ ctx?.logger?.log("SIGN_IN_INITIATED", {
535
+ structuredData: { oauth_provider: oauth }
536
+ });
537
+ const headersList = new import_router2.HeadersBuilder(cacheControl).setHeader("Location", authorization).setCookie(ctx.cookies.state.name, state, ctx.cookies.state.attributes).setCookie(ctx.cookies.redirectURI.name, redirectURI, ctx.cookies.redirectURI.attributes).setCookie(ctx.cookies.redirectTo.name, redirectToValue, ctx.cookies.redirectTo.attributes).setCookie(ctx.cookies.codeVerifier.name, codeVerifier, ctx.cookies.codeVerifier.attributes).toHeaders();
538
+ return Response.json(
539
+ { redirect: redirect ?? true, signInURL: authorization },
540
+ {
541
+ status: redirect ?? true ? 302 : 200,
542
+ headers: headersList
543
+ }
544
+ );
545
+ };
546
+ // Annotate the CommonJS export names for ESM import in node:
547
+ 0 && (module.exports = {
548
+ signIn
549
+ });
@@ -0,0 +1,26 @@
1
+ import { B as BuiltInOAuthProvider, F as FunctionAPIContext, g as SignInAPIOptions, h as SignInReturn } from '../index-_aXtxb_s.js';
2
+ import { LiteralUnion } from '../@types/utility.js';
3
+ import 'zod';
4
+ import '../schemas.js';
5
+ import 'zod/v4';
6
+ import '@aura-stack/jose';
7
+ import '@aura-stack/jose/jose';
8
+ import '@aura-stack/jose/crypto';
9
+ import '@aura-stack/router/cookie';
10
+ import 'jose';
11
+ import '@aura-stack/router';
12
+ import 'zod/v4/core';
13
+
14
+ /**
15
+ * Initiates the sign-in flow on the server. Called when the client invokes the `signIn` API route.
16
+ * By default, it redirects to the authorization URL. If the `redirect` option is set to `false`,
17
+ * it returns a JSON response containing the authorization URL, allowing the client to handle redirection.
18
+ * @example
19
+ * const response = await api.signIn("github", {
20
+ * redirect: true,
21
+ * headers: await getAuthHeaders(),
22
+ * })
23
+ */
24
+ declare const signIn: <Redirect extends boolean = true>(oauth: LiteralUnion<BuiltInOAuthProvider>, { ctx, headers: headersInit, redirectTo, redirect, request: requestInit, }: FunctionAPIContext<SignInAPIOptions<Redirect>>) => Promise<SignInReturn<Redirect>>;
25
+
26
+ export { signIn };
@@ -0,0 +1,15 @@
1
+ import {
2
+ signIn
3
+ } from "../chunk-JOCGX3RP.js";
4
+ import "../chunk-D2CSIUKP.js";
5
+ import "../chunk-LATR3NIV.js";
6
+ import "../chunk-V6LLEAR4.js";
7
+ import "../chunk-2A5B7GWR.js";
8
+ import "../chunk-UZQJJD6A.js";
9
+ import "../chunk-LX3TJ2TJ.js";
10
+ import "../chunk-WHNDRO3N.js";
11
+ import "../chunk-U5663F2U.js";
12
+ import "../chunk-EBAMFRB7.js";
13
+ export {
14
+ signIn
15
+ };