@aura-stack/auth 0.1.0 → 0.2.0-rc.1

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 (111) hide show
  1. package/dist/@types/index.d.ts +5 -5
  2. package/dist/@types/router.d.d.ts +5 -5
  3. package/dist/@types/utility.d.ts +1 -5
  4. package/dist/actions/callback/access-token.cjs +95 -74
  5. package/dist/actions/callback/access-token.d.ts +7 -7
  6. package/dist/actions/callback/access-token.js +5 -3
  7. package/dist/actions/callback/callback.cjs +171 -249
  8. package/dist/actions/callback/callback.d.ts +6 -6
  9. package/dist/actions/callback/callback.js +10 -10
  10. package/dist/actions/callback/userinfo.cjs +81 -57
  11. package/dist/actions/callback/userinfo.d.ts +5 -5
  12. package/dist/actions/callback/userinfo.js +7 -5
  13. package/dist/actions/csrfToken/csrfToken.cjs +36 -105
  14. package/dist/actions/csrfToken/csrfToken.js +6 -6
  15. package/dist/actions/index.cjs +309 -444
  16. package/dist/actions/index.d.ts +5 -5
  17. package/dist/actions/index.js +19 -19
  18. package/dist/actions/session/session.cjs +25 -109
  19. package/dist/actions/session/session.js +4 -5
  20. package/dist/actions/signIn/authorization.cjs +96 -87
  21. package/dist/actions/signIn/authorization.d.ts +5 -5
  22. package/dist/actions/signIn/authorization.js +5 -5
  23. package/dist/actions/signIn/signIn.cjs +133 -242
  24. package/dist/actions/signIn/signIn.d.ts +6 -6
  25. package/dist/actions/signIn/signIn.js +8 -9
  26. package/dist/actions/signOut/signOut.cjs +136 -282
  27. package/dist/actions/signOut/signOut.js +8 -9
  28. package/dist/assert.cjs +5 -0
  29. package/dist/assert.d.ts +10 -1
  30. package/dist/assert.js +3 -1
  31. package/dist/chunk-3EUWD5BB.js +63 -0
  32. package/dist/chunk-6R2YZ4AC.js +22 -0
  33. package/dist/chunk-A3N4PVAT.js +70 -0
  34. package/dist/chunk-B737EUJV.js +22 -0
  35. package/dist/{chunk-256KIVJL.js → chunk-CXLATHS5.js} +53 -9
  36. package/dist/{chunk-6SM22VVJ.js → chunk-EIL2FPSS.js} +5 -1
  37. package/dist/{chunk-VFTYH33W.js → chunk-EMKJA2GJ.js} +36 -8
  38. package/dist/{chunk-UJJ7R56J.js → chunk-GA2SMTJO.js} +16 -10
  39. package/dist/chunk-HP34YGGJ.js +22 -0
  40. package/dist/chunk-HT4YLL7N.js +35 -0
  41. package/dist/{chunk-EBPE35JT.js → chunk-IUYZQTJV.js} +0 -1
  42. package/dist/{chunk-RLT4RFKV.js → chunk-IVET23KF.js} +21 -8
  43. package/dist/{chunk-XXJKNKGQ.js → chunk-JVFTCTTE.js} +9 -13
  44. package/dist/chunk-KSWLO5ZU.js +102 -0
  45. package/dist/{chunk-GZU3RBTB.js → chunk-N2APGLXA.js} +19 -10
  46. package/dist/{chunk-CAKJT3KS.js → chunk-N4SX7TZT.js} +21 -17
  47. package/dist/chunk-RRLIF4PQ.js +55 -0
  48. package/dist/chunk-TLE4PXY3.js +39 -0
  49. package/dist/chunk-W6LG7BFW.js +197 -0
  50. package/dist/{chunk-HMRKN75I.js → chunk-YRCB5FLE.js} +14 -9
  51. package/dist/chunk-ZNCZVF6U.js +14 -0
  52. package/dist/cookie.cjs +140 -99
  53. package/dist/cookie.d.ts +35 -44
  54. package/dist/cookie.js +10 -17
  55. package/dist/errors.cjs +85 -0
  56. package/dist/errors.d.ts +49 -0
  57. package/dist/errors.js +18 -0
  58. package/dist/{index-DpfbvTZ_.d.ts → index-DkaLJFn8.d.ts} +192 -61
  59. package/dist/index.cjs +543 -443
  60. package/dist/index.d.ts +6 -6
  61. package/dist/index.js +42 -28
  62. package/dist/jose.cjs +25 -14
  63. package/dist/jose.d.ts +4 -1
  64. package/dist/jose.js +5 -4
  65. package/dist/oauth/bitbucket.d.ts +5 -5
  66. package/dist/oauth/discord.cjs +0 -1
  67. package/dist/oauth/discord.d.ts +5 -5
  68. package/dist/oauth/discord.js +1 -1
  69. package/dist/oauth/figma.d.ts +5 -5
  70. package/dist/oauth/github.d.ts +5 -5
  71. package/dist/oauth/gitlab.d.ts +5 -5
  72. package/dist/oauth/index.cjs +176 -6
  73. package/dist/oauth/index.d.ts +5 -5
  74. package/dist/oauth/index.js +19 -4
  75. package/dist/oauth/mailchimp.cjs +46 -0
  76. package/dist/oauth/mailchimp.d.ts +7 -0
  77. package/dist/oauth/mailchimp.js +6 -0
  78. package/dist/oauth/pinterest.cjs +46 -0
  79. package/dist/oauth/pinterest.d.ts +7 -0
  80. package/dist/oauth/pinterest.js +6 -0
  81. package/dist/oauth/spotify.d.ts +5 -5
  82. package/dist/oauth/strava.cjs +46 -0
  83. package/dist/oauth/strava.d.ts +7 -0
  84. package/dist/oauth/strava.js +6 -0
  85. package/dist/oauth/x.d.ts +5 -5
  86. package/dist/{response.cjs → request.cjs} +14 -10
  87. package/dist/request.d.ts +13 -0
  88. package/dist/request.js +6 -0
  89. package/dist/schemas.cjs +43 -37
  90. package/dist/schemas.d.ts +67 -64
  91. package/dist/schemas.js +3 -1
  92. package/dist/secure.cjs +32 -24
  93. package/dist/secure.d.ts +5 -5
  94. package/dist/secure.js +4 -3
  95. package/dist/utils.cjs +90 -15
  96. package/dist/utils.d.ts +11 -2
  97. package/dist/utils.js +8 -4
  98. package/package.json +8 -7
  99. package/dist/chunk-FJUDBLCP.js +0 -59
  100. package/dist/chunk-HGJ4TXY4.js +0 -137
  101. package/dist/chunk-JAPMIE6S.js +0 -10
  102. package/dist/chunk-LLR722CL.js +0 -96
  103. package/dist/chunk-SJPDVKUS.js +0 -112
  104. package/dist/chunk-SMQO5WD7.js +0 -30
  105. package/dist/chunk-UTDLUEEG.js +0 -31
  106. package/dist/chunk-ZV4BH47P.js +0 -154
  107. package/dist/error.cjs +0 -88
  108. package/dist/error.d.ts +0 -62
  109. package/dist/error.js +0 -16
  110. package/dist/response.d.ts +0 -10
  111. package/dist/response.js +0 -6
@@ -33,57 +33,46 @@ __export(signIn_exports, {
33
33
  signInAction: () => signInAction
34
34
  });
35
35
  module.exports = __toCommonJS(signIn_exports);
36
- var import_zod = __toESM(require("zod"), 1);
36
+ var import_zod2 = require("zod");
37
37
  var import_router2 = require("@aura-stack/router");
38
38
 
39
- // src/response.ts
40
- var AuraResponse = class extends Response {
41
- static json(body, init) {
42
- return Response.json(body, init);
43
- }
39
+ // src/headers.ts
40
+ var cacheControl = {
41
+ "Cache-Control": "no-store",
42
+ Pragma: "no-cache",
43
+ Expires: "0",
44
+ Vary: "Cookie"
44
45
  };
45
46
 
46
47
  // src/secure.ts
47
- var import_node_crypto = __toESM(require("crypto"), 1);
48
+ var import_crypto = __toESM(require("crypto"), 1);
48
49
 
49
50
  // src/utils.ts
50
51
  var import_router = require("@aura-stack/router");
51
52
 
52
- // src/error.ts
53
- var AuthError = class extends Error {
54
- constructor(type, message) {
55
- super(message);
56
- this.type = type;
57
- this.name = "AuthError";
53
+ // src/errors.ts
54
+ var AuthInternalError = class extends Error {
55
+ type = "AUTH_INTERNAL_ERROR";
56
+ code;
57
+ constructor(code, message, options2) {
58
+ super(message, options2);
59
+ this.code = code;
60
+ this.name = new.target.name;
61
+ Error.captureStackTrace(this, new.target);
58
62
  }
59
63
  };
60
- var InvalidRedirectToError = class extends AuthError {
61
- constructor(message = "The redirectTo parameter does not match the hosted origin.") {
62
- super("invalid_redirect_to", message);
63
- this.name = "InvalidRedirectToError";
64
+ var AuthSecurityError = class extends Error {
65
+ type = "AUTH_SECURITY_ERROR";
66
+ code;
67
+ constructor(code, message, options2) {
68
+ super(message, options2);
69
+ this.code = code;
70
+ this.name = new.target.name;
71
+ Error.captureStackTrace(this, new.target);
64
72
  }
65
73
  };
66
- var isAuthError = (error) => {
67
- return error instanceof AuthError;
68
- };
69
- var ERROR_RESPONSE = {
70
- AUTHORIZATION: {
71
- INVALID_REQUEST: "invalid_request",
72
- UNAUTHORIZED_CLIENT: "unauthorized_client",
73
- ACCESS_DENIED: "access_denied",
74
- UNSUPPORTED_RESPONSE_TYPE: "unsupported_response_type",
75
- INVALID_SCOPE: "invalid_scope",
76
- SERVER_ERROR: "server_error",
77
- TEMPORARILY_UNAVAILABLE: "temporarily_unavailable"
78
- },
79
- ACCESS_TOKEN: {
80
- INVALID_REQUEST: "invalid_request",
81
- INVALID_CLIENT: "invalid_client",
82
- INVALID_GRANT: "invalid_grant",
83
- UNAUTHORIZED_CLIENT: "unauthorized_client",
84
- UNSUPPORTED_GRANT_TYPE: "unsupported_grant_type",
85
- INVALID_SCOPE: "invalid_scope"
86
- }
74
+ var isAuthSecurityError = (error) => {
75
+ return error instanceof AuthSecurityError;
87
76
  };
88
77
 
89
78
  // src/utils.ts
@@ -103,9 +92,9 @@ var equals = (a, b) => {
103
92
  if (a === null || b === null || a === void 0 || b === void 0) return false;
104
93
  return a === b;
105
94
  };
106
- var sanitizeURL = (url2) => {
95
+ var sanitizeURL = (url) => {
107
96
  try {
108
- let decodedURL = decodeURIComponent(url2).trim();
97
+ let decodedURL = decodeURIComponent(url).trim();
109
98
  const protocolMatch = decodedURL.match(/^([a-zA-Z][a-zA-Z0-9+.-]*:\/\/)/);
110
99
  let protocol = "";
111
100
  let rest = decodedURL;
@@ -133,36 +122,35 @@ var sanitizeURL = (url2) => {
133
122
  }
134
123
  return sanitized;
135
124
  } catch {
136
- return url2.trim();
125
+ return url.trim();
137
126
  }
138
127
  };
139
128
  var getNormalizedOriginPath = (path) => {
140
129
  try {
141
- const url2 = new URL(path);
142
- url2.hash = "";
143
- url2.search = "";
144
- return `${url2.origin}${url2.pathname}`;
130
+ const url = new URL(path);
131
+ url.hash = "";
132
+ url.search = "";
133
+ return `${url.origin}${url.pathname}`;
145
134
  } catch {
146
135
  return sanitizeURL(path);
147
136
  }
148
137
  };
149
-
150
- // src/secure.ts
151
- var generateSecure = (length = 32) => {
152
- return import_node_crypto.default.randomBytes(length).toString("base64url");
153
- };
154
- var createHash = (data, base = "hex") => {
155
- return import_node_crypto.default.createHash("sha256").update(data).digest().toString(base);
156
- };
157
- var createPKCE = async (verifier) => {
158
- const codeVerifier = verifier ?? generateSecure(86);
159
- const codeChallenge = createHash(codeVerifier, "base64url");
160
- return { codeVerifier, codeChallenge, method: "S256" };
138
+ var formatZodError = (error) => {
139
+ if (!error.issues || error.issues.length === 0) {
140
+ return {};
141
+ }
142
+ return error.issues.reduce((previous, issue) => {
143
+ const key = issue.path.join(".");
144
+ return {
145
+ ...previous,
146
+ [key]: {
147
+ code: issue.code,
148
+ message: issue.message
149
+ }
150
+ };
151
+ }, {});
161
152
  };
162
153
 
163
- // src/cookie.ts
164
- var import_cookie = require("cookie");
165
-
166
154
  // src/assert.ts
167
155
  var isValidURL = (value) => {
168
156
  if (value.includes("\r\n") || value.includes("\n") || value.includes("\r")) return false;
@@ -170,123 +158,42 @@ var isValidURL = (value) => {
170
158
  return regex.test(value);
171
159
  };
172
160
 
173
- // src/cookie.ts
174
- var import_cookie2 = require("cookie");
175
- var COOKIE_NAME = "aura-auth";
176
- var defaultCookieOptions = {
177
- httpOnly: true,
178
- sameSite: "lax",
179
- path: "/",
180
- maxAge: 60 * 60 * 24 * 15
181
- };
182
- var defaultStandardCookieConfig = {
183
- secure: false,
184
- httpOnly: true,
185
- prefix: ""
186
- };
187
- var defaultSecureCookieConfig = {
188
- secure: true,
189
- prefix: "__Secure-"
190
- };
191
- var defaultHostCookieConfig = {
192
- secure: true,
193
- prefix: "__Host-",
194
- path: "/",
195
- domain: void 0
196
- };
197
- var expiredCookieOptions = {
198
- ...defaultCookieOptions,
199
- expires: /* @__PURE__ */ new Date(0),
200
- maxAge: 0
201
- };
202
- var defineDefaultCookieOptions = (options2) => {
203
- return {
204
- name: options2?.name ?? COOKIE_NAME,
205
- prefix: options2?.prefix ?? (options2?.secure ? "__Secure-" : ""),
206
- ...defaultCookieOptions,
207
- ...options2
208
- };
209
- };
210
- var setCookie = (cookieName, value, options2) => {
211
- const { prefix, name } = defineDefaultCookieOptions(options2);
212
- const cookieNameWithPrefix = `${prefix}${name}.${cookieName}`;
213
- return (0, import_cookie.serialize)(cookieNameWithPrefix, value, {
214
- ...defaultCookieOptions,
215
- ...options2
216
- });
161
+ // src/secure.ts
162
+ var generateSecure = (length = 32) => {
163
+ return import_crypto.default.randomBytes(length).toString("base64url");
217
164
  };
218
- var secureCookieOptions = (request, cookieOptions, trustedProxyHeaders) => {
219
- const name = cookieOptions.name ?? COOKIE_NAME;
220
- const isSecure = trustedProxyHeaders ? request.url.startsWith("https://") || request.headers.get("X-Forwarded-Proto") === "https" || request.headers.get("Forwarded")?.includes("proto=https") : request.url.startsWith("https://");
221
- if (!cookieOptions.options?.httpOnly) {
222
- console.warn(
223
- "[WARNING]: Cookie is configured without HttpOnly. This allows JavaScript access via document.cookie and increases XSS risk."
224
- );
225
- }
226
- if (cookieOptions.options?.domain === "*") {
227
- console.warn("[WARNING]: Cookie 'Domain' is set to '*', which is insecure. Avoid wildcard domains.");
228
- }
229
- if (!isSecure) {
230
- const options2 = cookieOptions.options;
231
- if (options2?.secure) {
232
- console.warn(
233
- "[WARNING]: The 'Secure' attribute will be disabled for this cookie. Serve over HTTPS to enforce Secure cookies."
234
- );
235
- }
236
- if (options2?.sameSite == "none") {
237
- console.warn("[WARNING]: SameSite=None without a secure connection can be blocked by browsers.");
238
- }
239
- if (process.env.NODE_ENV === "production") {
240
- console.warn("[WARNING]: In production, ensure cookies are served over HTTPS to maintain security.");
241
- }
242
- return {
243
- ...defaultCookieOptions,
244
- ...cookieOptions.options,
245
- sameSite: options2?.sameSite === "none" ? "lax" : options2?.sameSite ?? "lax",
246
- ...defaultStandardCookieConfig,
247
- name
248
- };
249
- }
250
- return cookieOptions.strategy === "host" ? {
251
- ...defaultCookieOptions,
252
- ...cookieOptions.options,
253
- ...defaultHostCookieConfig,
254
- name
255
- } : { ...defaultCookieOptions, ...cookieOptions.options, ...defaultSecureCookieConfig, name };
165
+ var createHash = (data, base = "hex") => {
166
+ return import_crypto.default.createHash("sha256").update(data).digest().toString(base);
256
167
  };
257
- var oauthCookie = (options2) => {
258
- return {
259
- ...options2,
260
- secure: options2.secure,
261
- httpOnly: options2.httpOnly,
262
- maxAge: 5 * 60,
263
- expires: new Date(Date.now() + 5 * 60 * 1e3)
264
- };
168
+ var createPKCE = async (verifier) => {
169
+ const codeVerifier = verifier ?? generateSecure(86);
170
+ const codeChallenge = createHash(codeVerifier, "base64url");
171
+ return { codeVerifier, codeChallenge, method: "S256" };
265
172
  };
266
173
 
267
174
  // src/schemas.ts
268
- var import_v4 = require("zod/v4");
269
- var OAuthProviderConfigSchema = (0, import_v4.object)({
270
- authorizeURL: (0, import_v4.url)(),
271
- accessToken: (0, import_v4.url)(),
272
- scope: (0, import_v4.string)().optional(),
273
- userInfo: (0, import_v4.url)(),
274
- responseType: (0, import_v4.enum)(["code", "token", "id_token"]),
275
- clientId: (0, import_v4.string)(),
276
- clientSecret: (0, import_v4.string)()
175
+ var import_zod = require("zod");
176
+ var OAuthProviderConfigSchema = (0, import_zod.object)({
177
+ authorizeURL: (0, import_zod.string)().url(),
178
+ accessToken: (0, import_zod.string)().url(),
179
+ scope: (0, import_zod.string)().optional(),
180
+ userInfo: (0, import_zod.string)().url(),
181
+ responseType: (0, import_zod.enum)(["code", "token", "id_token"]),
182
+ clientId: (0, import_zod.string)(),
183
+ clientSecret: (0, import_zod.string)()
277
184
  });
278
185
  var OAuthAuthorization = OAuthProviderConfigSchema.extend({
279
- redirectURI: (0, import_v4.string)(),
280
- state: (0, import_v4.string)(),
281
- codeChallenge: (0, import_v4.string)(),
282
- codeChallengeMethod: (0, import_v4.enum)(["plain", "S256"])
186
+ redirectURI: (0, import_zod.string)(),
187
+ state: (0, import_zod.string)(),
188
+ codeChallenge: (0, import_zod.string)(),
189
+ codeChallengeMethod: (0, import_zod.enum)(["plain", "S256"])
283
190
  });
284
- var OAuthAuthorizationResponse = (0, import_v4.object)({
285
- state: (0, import_v4.string)(),
286
- code: (0, import_v4.string)()
191
+ var OAuthAuthorizationResponse = (0, import_zod.object)({
192
+ state: (0, import_zod.string)({ message: "Missing state parameter in the OAuth authorization response." }),
193
+ code: (0, import_zod.string)({ message: "Missing code parameter in the OAuth authorization response." })
287
194
  });
288
- var OAuthAuthorizationErrorResponse = (0, import_v4.object)({
289
- error: (0, import_v4.enum)([
195
+ var OAuthAuthorizationErrorResponse = (0, import_zod.object)({
196
+ error: (0, import_zod.enum)([
290
197
  "invalid_request",
291
198
  "unauthorized_client",
292
199
  "access_denied",
@@ -295,24 +202,24 @@ var OAuthAuthorizationErrorResponse = (0, import_v4.object)({
295
202
  "server_error",
296
203
  "temporarily_unavailable"
297
204
  ]),
298
- error_description: (0, import_v4.string)().optional(),
299
- error_uri: (0, import_v4.string)().optional(),
300
- state: (0, import_v4.string)()
205
+ error_description: (0, import_zod.string)().optional(),
206
+ error_uri: (0, import_zod.string)().optional(),
207
+ state: (0, import_zod.string)()
301
208
  });
302
209
  var OAuthAccessToken = OAuthProviderConfigSchema.extend({
303
- redirectURI: (0, import_v4.string)(),
304
- code: (0, import_v4.string)(),
305
- codeVerifier: (0, import_v4.string)().min(43).max(128)
210
+ redirectURI: (0, import_zod.string)(),
211
+ code: (0, import_zod.string)(),
212
+ codeVerifier: (0, import_zod.string)().min(43).max(128)
306
213
  });
307
- var OAuthAccessTokenResponse = (0, import_v4.object)({
308
- access_token: (0, import_v4.string)(),
309
- token_type: (0, import_v4.string)(),
310
- expires_in: (0, import_v4.number)().optional(),
311
- refresh_token: (0, import_v4.string)().optional(),
312
- scope: (0, import_v4.string)().optional()
214
+ var OAuthAccessTokenResponse = (0, import_zod.object)({
215
+ access_token: (0, import_zod.string)(),
216
+ token_type: (0, import_zod.string)().optional(),
217
+ expires_in: (0, import_zod.number)().optional(),
218
+ refresh_token: (0, import_zod.string)().optional(),
219
+ scope: (0, import_zod.string)().optional().or((0, import_zod.null)())
313
220
  });
314
- var OAuthAccessTokenErrorResponse = (0, import_v4.object)({
315
- error: (0, import_v4.enum)([
221
+ var OAuthAccessTokenErrorResponse = (0, import_zod.object)({
222
+ error: (0, import_zod.enum)([
316
223
  "invalid_request",
317
224
  "invalid_client",
318
225
  "invalid_grant",
@@ -320,19 +227,24 @@ var OAuthAccessTokenErrorResponse = (0, import_v4.object)({
320
227
  "unsupported_grant_type",
321
228
  "invalid_scope"
322
229
  ]),
323
- error_description: (0, import_v4.string)().optional(),
324
- error_uri: (0, import_v4.string)().optional()
230
+ error_description: (0, import_zod.string)().optional(),
231
+ error_uri: (0, import_zod.string)().optional()
232
+ });
233
+ var OAuthErrorResponse = (0, import_zod.object)({
234
+ error: (0, import_zod.string)(),
235
+ error_description: (0, import_zod.string)().optional()
325
236
  });
326
- var OAuthErrorResponse = (0, import_v4.object)({
327
- error: (0, import_v4.string)(),
328
- error_description: (0, import_v4.string)().optional()
237
+ var OAuthEnvSchema = (0, import_zod.object)({
238
+ clientId: import_zod.z.string().min(1, "OAuth Client ID is required in the environment variables."),
239
+ clientSecret: import_zod.z.string().min(1, "OAuth Client Secret is required in the environment variables.")
329
240
  });
330
241
 
331
242
  // src/actions/signIn/authorization.ts
332
243
  var createAuthorizationURL = (oauthConfig, redirectURI, state, codeChallenge, codeChallengeMethod) => {
333
244
  const parsed = OAuthAuthorization.safeParse({ ...oauthConfig, redirectURI, state, codeChallenge, codeChallengeMethod });
334
245
  if (!parsed.success) {
335
- throw new AuthError(ERROR_RESPONSE.AUTHORIZATION.SERVER_ERROR, "Invalid OAuth configuration");
246
+ const msg = JSON.stringify(formatZodError(parsed.error), null, 2);
247
+ throw new AuthInternalError("INVALID_OAUTH_CONFIGURATION", msg);
336
248
  }
337
249
  const { authorizeURL, ...options2 } = parsed.data;
338
250
  const { userInfo, accessToken, clientSecret, ...required } = options2;
@@ -350,8 +262,8 @@ var getOriginURL = (request, trustedProxyHeaders) => {
350
262
  }
351
263
  };
352
264
  var createRedirectURI = (request, oauth, basePath, trustedProxyHeaders) => {
353
- const url2 = getOriginURL(request, trustedProxyHeaders);
354
- return `${url2.origin}${basePath}/callback/${oauth}`;
265
+ const url = getOriginURL(request, trustedProxyHeaders);
266
+ return `${url.origin}${basePath}/callback/${oauth}`;
355
267
  };
356
268
  var createRedirectTo = (request, redirectTo, trustedProxyHeaders) => {
357
269
  try {
@@ -365,15 +277,18 @@ var createRedirectTo = (request, redirectTo, trustedProxyHeaders) => {
365
277
  }
366
278
  const redirectToURL = new URL(sanitizeURL(getNormalizedOriginPath(redirectTo)));
367
279
  if (!isValidURL(redirectTo) || !equals(redirectToURL.origin, hostedURL.origin)) {
368
- throw new InvalidRedirectToError();
280
+ throw new AuthSecurityError(
281
+ "POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED",
282
+ "The redirectTo parameter does not match the hosted origin."
283
+ );
369
284
  }
370
285
  return sanitizeURL(redirectToURL.pathname);
371
286
  }
372
287
  if (referer) {
373
288
  const refererURL = new URL(sanitizeURL(referer));
374
289
  if (!isValidURL(referer) || !equals(refererURL.origin, hostedURL.origin)) {
375
- throw new AuthError(
376
- ERROR_RESPONSE.AUTHORIZATION.INVALID_REQUEST,
290
+ throw new AuthSecurityError(
291
+ "POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED",
377
292
  "The referer of the request does not match the hosted origin."
378
293
  );
379
294
  }
@@ -382,16 +297,16 @@ var createRedirectTo = (request, redirectTo, trustedProxyHeaders) => {
382
297
  if (origin) {
383
298
  const originURL = new URL(sanitizeURL(getNormalizedOriginPath(origin)));
384
299
  if (!isValidURL(origin) || !equals(originURL.origin, hostedURL.origin)) {
385
- throw new AuthError(ERROR_RESPONSE.AUTHORIZATION.INVALID_REQUEST, "Invalid origin (potential CSRF).");
300
+ throw new AuthSecurityError("POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED", "Invalid origin (potential CSRF).");
386
301
  }
387
302
  return sanitizeURL(originURL.pathname);
388
303
  }
389
304
  return "/";
390
305
  } catch (error) {
391
- if (isAuthError(error)) {
306
+ if (isAuthSecurityError(error)) {
392
307
  throw error;
393
308
  }
394
- throw new AuthError(ERROR_RESPONSE.AUTHORIZATION.INVALID_REQUEST, "Invalid origin (potential CSRF).");
309
+ throw new AuthSecurityError("POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED", "Invalid origin (potential CSRF).");
395
310
  }
396
311
  };
397
312
 
@@ -399,9 +314,14 @@ var createRedirectTo = (request, redirectTo, trustedProxyHeaders) => {
399
314
  var signInConfig = (oauth) => {
400
315
  return (0, import_router2.createEndpointConfig)("/signIn/:oauth", {
401
316
  schemas: {
402
- params: import_zod.default.object({
403
- oauth: import_zod.default.enum(Object.keys(oauth)),
404
- redirectTo: import_zod.default.string().optional()
317
+ params: import_zod2.z.object({
318
+ oauth: import_zod2.z.enum(
319
+ Object.keys(oauth),
320
+ "The OAuth provider is not supported or invalid."
321
+ )
322
+ }),
323
+ searchParams: import_zod2.z.object({
324
+ redirectTo: import_zod2.z.string().optional()
405
325
  })
406
326
  }
407
327
  });
@@ -413,52 +333,23 @@ var signInAction = (oauth) => {
413
333
  async (ctx) => {
414
334
  const {
415
335
  request,
416
- params: { oauth: oauth2, redirectTo },
336
+ params: { oauth: oauth2 },
337
+ searchParams: { redirectTo },
417
338
  context: { oauth: providers, cookies, trustedProxyHeaders, basePath }
418
339
  } = ctx;
419
- try {
420
- const cookieOptions = secureCookieOptions(request, cookies, trustedProxyHeaders);
421
- const state = generateSecure();
422
- const redirectURI = createRedirectURI(request, oauth2, basePath, trustedProxyHeaders);
423
- const stateCookie = setCookie("state", state, oauthCookie(cookieOptions));
424
- const redirectURICookie = setCookie("redirect_uri", redirectURI, oauthCookie(cookieOptions));
425
- const redirectToCookie = setCookie(
426
- "redirect_to",
427
- createRedirectTo(request, redirectTo, trustedProxyHeaders),
428
- oauthCookie(cookieOptions)
429
- );
430
- const { codeVerifier, codeChallenge, method } = await createPKCE();
431
- const codeVerifierCookie = setCookie("code_verifier", codeVerifier, oauthCookie(cookieOptions));
432
- const authorization = createAuthorizationURL(providers[oauth2], redirectURI, state, codeChallenge, method);
433
- const headers = new Headers();
434
- headers.set("Location", authorization);
435
- headers.append("Set-Cookie", stateCookie);
436
- headers.append("Set-Cookie", redirectURICookie);
437
- headers.append("Set-Cookie", redirectToCookie);
438
- headers.append("Set-Cookie", codeVerifierCookie);
439
- return Response.json(
440
- { oauth: oauth2 },
441
- {
442
- status: 302,
443
- headers
444
- }
445
- );
446
- } catch (error) {
447
- if (isAuthError(error)) {
448
- const { type, message } = error;
449
- return AuraResponse.json(
450
- { error: type, error_description: message },
451
- { status: import_router2.statusCode.BAD_REQUEST }
452
- );
340
+ const state = generateSecure();
341
+ const redirectURI = createRedirectURI(request, oauth2, basePath, trustedProxyHeaders);
342
+ const redirectToValue = createRedirectTo(request, redirectTo, trustedProxyHeaders);
343
+ const { codeVerifier, codeChallenge, method } = await createPKCE();
344
+ const authorization = createAuthorizationURL(providers[oauth2], redirectURI, state, codeChallenge, method);
345
+ const headers = new import_router2.HeadersBuilder(cacheControl).setHeader("Location", authorization).setCookie(cookies.state.name, state, cookies.state.attributes).setCookie(cookies.redirectURI.name, redirectURI, cookies.redirectURI.attributes).setCookie(cookies.redirectTo.name, redirectToValue, cookies.redirectTo.attributes).setCookie(cookies.codeVerifier.name, codeVerifier, cookies.codeVerifier.attributes).toHeaders();
346
+ return Response.json(
347
+ { oauth: oauth2 },
348
+ {
349
+ status: 302,
350
+ headers
453
351
  }
454
- return AuraResponse.json(
455
- {
456
- error: ERROR_RESPONSE.AUTHORIZATION.SERVER_ERROR,
457
- error_description: "An unexpected error occurred"
458
- },
459
- { status: import_router2.statusCode.INTERNAL_SERVER_ERROR }
460
- );
461
- }
352
+ );
462
353
  },
463
354
  signInConfig(oauth)
464
355
  );
@@ -1,12 +1,12 @@
1
1
  import * as _aura_stack_router from '@aura-stack/router';
2
- import { A as AuthRuntimeConfig } from '../../index-DpfbvTZ_.js';
3
- import 'zod/v4';
4
- import '@aura-stack/jose/jose';
2
+ import { j as OAuthProviderRecord } from '../../index-DkaLJFn8.js';
3
+ import 'zod';
5
4
  import '../../schemas.js';
6
- import 'zod/v4/core';
7
- import 'cookie';
5
+ import '@aura-stack/router/cookie';
6
+ import '@aura-stack/jose';
7
+ import '@aura-stack/jose/jose';
8
8
  import '../../@types/utility.js';
9
9
 
10
- declare const signInAction: (oauth: AuthRuntimeConfig["oauth"]) => _aura_stack_router.RouteEndpoint<"GET", "/signIn/:oauth", {}>;
10
+ declare const signInAction: (oauth: OAuthProviderRecord) => _aura_stack_router.RouteEndpoint<"GET", "/signIn/:oauth", {}>;
11
11
 
12
12
  export { signInAction };
@@ -1,14 +1,13 @@
1
1
  import {
2
2
  signInAction
3
- } from "../../chunk-LLR722CL.js";
4
- import "../../chunk-CAKJT3KS.js";
5
- import "../../chunk-ZV4BH47P.js";
6
- import "../../chunk-6SM22VVJ.js";
7
- import "../../chunk-GZU3RBTB.js";
8
- import "../../chunk-256KIVJL.js";
9
- import "../../chunk-FJUDBLCP.js";
10
- import "../../chunk-JAPMIE6S.js";
11
- import "../../chunk-HMRKN75I.js";
3
+ } from "../../chunk-3EUWD5BB.js";
4
+ import "../../chunk-N4SX7TZT.js";
5
+ import "../../chunk-STHEPPUZ.js";
6
+ import "../../chunk-N2APGLXA.js";
7
+ import "../../chunk-CXLATHS5.js";
8
+ import "../../chunk-EIL2FPSS.js";
9
+ import "../../chunk-RRLIF4PQ.js";
10
+ import "../../chunk-YRCB5FLE.js";
12
11
  export {
13
12
  signInAction
14
13
  };