@aura-stack/auth 0.1.0 → 0.2.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 (99) hide show
  1. package/dist/@types/index.d.ts +3 -4
  2. package/dist/@types/router.d.d.ts +3 -4
  3. package/dist/@types/utility.d.ts +1 -5
  4. package/dist/actions/callback/access-token.cjs +51 -41
  5. package/dist/actions/callback/access-token.d.ts +3 -4
  6. package/dist/actions/callback/access-token.js +4 -3
  7. package/dist/actions/callback/callback.cjs +115 -210
  8. package/dist/actions/callback/callback.d.ts +3 -4
  9. package/dist/actions/callback/callback.js +9 -10
  10. package/dist/actions/callback/userinfo.cjs +35 -22
  11. package/dist/actions/callback/userinfo.d.ts +3 -4
  12. package/dist/actions/callback/userinfo.js +6 -5
  13. package/dist/actions/csrfToken/csrfToken.cjs +34 -103
  14. package/dist/actions/csrfToken/csrfToken.js +6 -6
  15. package/dist/actions/index.cjs +234 -391
  16. package/dist/actions/index.d.ts +3 -4
  17. package/dist/actions/index.js +16 -17
  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 +64 -55
  21. package/dist/actions/signIn/authorization.d.ts +3 -4
  22. package/dist/actions/signIn/authorization.js +5 -5
  23. package/dist/actions/signIn/signIn.cjs +84 -206
  24. package/dist/actions/signIn/signIn.d.ts +3 -4
  25. package/dist/actions/signIn/signIn.js +7 -9
  26. package/dist/actions/signOut/signOut.cjs +88 -234
  27. package/dist/actions/signOut/signOut.js +8 -9
  28. package/dist/assert.cjs +5 -0
  29. package/dist/assert.d.ts +9 -1
  30. package/dist/assert.js +3 -1
  31. package/dist/chunk-2RXNXMCZ.js +55 -0
  32. package/dist/{chunk-UJJ7R56J.js → chunk-4V4JNXVF.js} +13 -10
  33. package/dist/chunk-6R2YZ4AC.js +22 -0
  34. package/dist/{chunk-VFTYH33W.js → chunk-7H3OR6UU.js} +29 -9
  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-IMICRJ5U.js +197 -0
  38. package/dist/{chunk-EBPE35JT.js → chunk-IUYZQTJV.js} +0 -1
  39. package/dist/{chunk-GZU3RBTB.js → chunk-N2APGLXA.js} +19 -10
  40. package/dist/chunk-NEVKX6K2.js +70 -0
  41. package/dist/{chunk-XXJKNKGQ.js → chunk-PTJUYB33.js} +9 -13
  42. package/dist/chunk-QDO2KSRJ.js +35 -0
  43. package/dist/{chunk-CAKJT3KS.js → chunk-QEZL7EYN.js} +21 -17
  44. package/dist/chunk-RRLIF4PQ.js +55 -0
  45. package/dist/chunk-TLE4PXY3.js +39 -0
  46. package/dist/chunk-UEH3LVON.js +97 -0
  47. package/dist/{chunk-HMRKN75I.js → chunk-WD7AUHQ5.js} +12 -7
  48. package/dist/{chunk-RLT4RFKV.js → chunk-ZLR3LI6X.js} +19 -9
  49. package/dist/cookie.cjs +140 -99
  50. package/dist/cookie.d.ts +33 -43
  51. package/dist/cookie.js +10 -17
  52. package/dist/errors.cjs +85 -0
  53. package/dist/errors.d.ts +48 -0
  54. package/dist/errors.js +18 -0
  55. package/dist/{index-DpfbvTZ_.d.ts → index-EqsoyjrF.d.ts} +139 -57
  56. package/dist/index.cjs +427 -389
  57. package/dist/index.d.ts +4 -5
  58. package/dist/index.js +37 -26
  59. package/dist/jose.cjs +23 -12
  60. package/dist/jose.d.ts +4 -1
  61. package/dist/jose.js +5 -4
  62. package/dist/oauth/bitbucket.d.ts +3 -4
  63. package/dist/oauth/discord.cjs +0 -1
  64. package/dist/oauth/discord.d.ts +3 -4
  65. package/dist/oauth/discord.js +1 -1
  66. package/dist/oauth/figma.d.ts +3 -4
  67. package/dist/oauth/github.d.ts +3 -4
  68. package/dist/oauth/gitlab.d.ts +3 -4
  69. package/dist/oauth/index.cjs +132 -6
  70. package/dist/oauth/index.d.ts +3 -4
  71. package/dist/oauth/index.js +12 -5
  72. package/dist/oauth/spotify.d.ts +3 -4
  73. package/dist/{response.cjs → oauth/strava.cjs} +21 -9
  74. package/dist/oauth/strava.d.ts +6 -0
  75. package/dist/oauth/strava.js +6 -0
  76. package/dist/oauth/x.d.ts +3 -4
  77. package/dist/schemas.cjs +11 -5
  78. package/dist/schemas.d.ts +70 -67
  79. package/dist/schemas.js +3 -1
  80. package/dist/secure.cjs +27 -19
  81. package/dist/secure.d.ts +3 -4
  82. package/dist/secure.js +4 -3
  83. package/dist/utils.cjs +90 -15
  84. package/dist/utils.d.ts +11 -2
  85. package/dist/utils.js +8 -4
  86. package/package.json +5 -6
  87. package/dist/chunk-FJUDBLCP.js +0 -59
  88. package/dist/chunk-HGJ4TXY4.js +0 -137
  89. package/dist/chunk-JAPMIE6S.js +0 -10
  90. package/dist/chunk-LLR722CL.js +0 -96
  91. package/dist/chunk-SJPDVKUS.js +0 -112
  92. package/dist/chunk-SMQO5WD7.js +0 -30
  93. package/dist/chunk-UTDLUEEG.js +0 -31
  94. package/dist/chunk-ZV4BH47P.js +0 -154
  95. package/dist/error.cjs +0 -88
  96. package/dist/error.d.ts +0 -62
  97. package/dist/error.js +0 -16
  98. package/dist/response.d.ts +0 -10
  99. package/dist/response.js +0 -6
@@ -36,54 +36,35 @@ module.exports = __toCommonJS(signIn_exports);
36
36
  var import_zod = __toESM(require("zod"), 1);
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
- }
44
- };
45
-
46
39
  // src/secure.ts
47
40
  var import_node_crypto = __toESM(require("crypto"), 1);
48
41
 
49
42
  // src/utils.ts
50
43
  var import_router = require("@aura-stack/router");
51
44
 
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";
45
+ // src/errors.ts
46
+ var AuthInternalError = class extends Error {
47
+ type = "AUTH_INTERNAL_ERROR";
48
+ code;
49
+ constructor(code, message, options2) {
50
+ super(message, options2);
51
+ this.code = code;
52
+ this.name = new.target.name;
53
+ Error.captureStackTrace(this, new.target);
58
54
  }
59
55
  };
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";
56
+ var AuthSecurityError = class extends Error {
57
+ type = "AUTH_SECURITY_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
64
  }
65
65
  };
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
- }
66
+ var isAuthSecurityError = (error) => {
67
+ return error instanceof AuthSecurityError;
87
68
  };
88
69
 
89
70
  // src/utils.ts
@@ -103,9 +84,9 @@ var equals = (a, b) => {
103
84
  if (a === null || b === null || a === void 0 || b === void 0) return false;
104
85
  return a === b;
105
86
  };
106
- var sanitizeURL = (url2) => {
87
+ var sanitizeURL = (url) => {
107
88
  try {
108
- let decodedURL = decodeURIComponent(url2).trim();
89
+ let decodedURL = decodeURIComponent(url).trim();
109
90
  const protocolMatch = decodedURL.match(/^([a-zA-Z][a-zA-Z0-9+.-]*:\/\/)/);
110
91
  let protocol = "";
111
92
  let rest = decodedURL;
@@ -133,19 +114,41 @@ var sanitizeURL = (url2) => {
133
114
  }
134
115
  return sanitized;
135
116
  } catch {
136
- return url2.trim();
117
+ return url.trim();
137
118
  }
138
119
  };
139
120
  var getNormalizedOriginPath = (path) => {
140
121
  try {
141
- const url2 = new URL(path);
142
- url2.hash = "";
143
- url2.search = "";
144
- return `${url2.origin}${url2.pathname}`;
122
+ const url = new URL(path);
123
+ url.hash = "";
124
+ url.search = "";
125
+ return `${url.origin}${url.pathname}`;
145
126
  } catch {
146
127
  return sanitizeURL(path);
147
128
  }
148
129
  };
130
+ var formatZodError = (error) => {
131
+ if (!error.issues || error.issues.length === 0) {
132
+ return {};
133
+ }
134
+ return error.issues.reduce((previous, issue) => {
135
+ const key = issue.path.join(".");
136
+ return {
137
+ ...previous,
138
+ [key]: {
139
+ code: issue.code,
140
+ message: issue.message
141
+ }
142
+ };
143
+ }, {});
144
+ };
145
+
146
+ // src/assert.ts
147
+ var isValidURL = (value) => {
148
+ if (value.includes("\r\n") || value.includes("\n") || value.includes("\r")) return false;
149
+ const regex = /^https?:\/\/(?:[a-zA-Z0-9._-]+|localhost|\[[0-9a-fA-F:]+\])(?::\d{1,5})?(?:\/[a-zA-Z0-9._~!$&'()*+,;=:@-]*)*\/?$/;
150
+ return regex.test(value);
151
+ };
149
152
 
150
153
  // src/secure.ts
151
154
  var generateSecure = (length = 32) => {
@@ -160,117 +163,13 @@ var createPKCE = async (verifier) => {
160
163
  return { codeVerifier, codeChallenge, method: "S256" };
161
164
  };
162
165
 
163
- // src/cookie.ts
164
- var import_cookie = require("cookie");
165
-
166
- // src/assert.ts
167
- var isValidURL = (value) => {
168
- if (value.includes("\r\n") || value.includes("\n") || value.includes("\r")) return false;
169
- const regex = /^https?:\/\/(?:[a-zA-Z0-9._-]+|localhost|\[[0-9a-fA-F:]+\])(?::\d{1,5})?(?:\/[a-zA-Z0-9._~!$&'()*+,;=:@-]*)*\/?$/;
170
- return regex.test(value);
171
- };
172
-
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
- });
217
- };
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 };
256
- };
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
- };
265
- };
266
-
267
166
  // src/schemas.ts
268
167
  var import_v4 = require("zod/v4");
269
168
  var OAuthProviderConfigSchema = (0, import_v4.object)({
270
- authorizeURL: (0, import_v4.url)(),
271
- accessToken: (0, import_v4.url)(),
169
+ authorizeURL: (0, import_v4.httpUrl)(),
170
+ accessToken: (0, import_v4.httpUrl)(),
272
171
  scope: (0, import_v4.string)().optional(),
273
- userInfo: (0, import_v4.url)(),
172
+ userInfo: (0, import_v4.httpUrl)(),
274
173
  responseType: (0, import_v4.enum)(["code", "token", "id_token"]),
275
174
  clientId: (0, import_v4.string)(),
276
175
  clientSecret: (0, import_v4.string)()
@@ -282,8 +181,8 @@ var OAuthAuthorization = OAuthProviderConfigSchema.extend({
282
181
  codeChallengeMethod: (0, import_v4.enum)(["plain", "S256"])
283
182
  });
284
183
  var OAuthAuthorizationResponse = (0, import_v4.object)({
285
- state: (0, import_v4.string)(),
286
- code: (0, import_v4.string)()
184
+ state: (0, import_v4.string)("Missing state parameter in the OAuth authorization response."),
185
+ code: (0, import_v4.string)("Missing code parameter in the OAuth authorization response.")
287
186
  });
288
187
  var OAuthAuthorizationErrorResponse = (0, import_v4.object)({
289
188
  error: (0, import_v4.enum)([
@@ -327,12 +226,17 @@ var OAuthErrorResponse = (0, import_v4.object)({
327
226
  error: (0, import_v4.string)(),
328
227
  error_description: (0, import_v4.string)().optional()
329
228
  });
229
+ var OAuthEnvSchema = (0, import_v4.object)({
230
+ clientId: import_v4.z.string().min(1, "OAuth Client ID is required in the environment variables."),
231
+ clientSecret: import_v4.z.string().min(1, "OAuth Client Secret is required in the environment variables.")
232
+ });
330
233
 
331
234
  // src/actions/signIn/authorization.ts
332
235
  var createAuthorizationURL = (oauthConfig, redirectURI, state, codeChallenge, codeChallengeMethod) => {
333
236
  const parsed = OAuthAuthorization.safeParse({ ...oauthConfig, redirectURI, state, codeChallenge, codeChallengeMethod });
334
237
  if (!parsed.success) {
335
- throw new AuthError(ERROR_RESPONSE.AUTHORIZATION.SERVER_ERROR, "Invalid OAuth configuration");
238
+ const msg = JSON.stringify(formatZodError(parsed.error), null, 2);
239
+ throw new AuthInternalError("INVALID_OAUTH_CONFIGURATION", msg);
336
240
  }
337
241
  const { authorizeURL, ...options2 } = parsed.data;
338
242
  const { userInfo, accessToken, clientSecret, ...required } = options2;
@@ -350,8 +254,8 @@ var getOriginURL = (request, trustedProxyHeaders) => {
350
254
  }
351
255
  };
352
256
  var createRedirectURI = (request, oauth, basePath, trustedProxyHeaders) => {
353
- const url2 = getOriginURL(request, trustedProxyHeaders);
354
- return `${url2.origin}${basePath}/callback/${oauth}`;
257
+ const url = getOriginURL(request, trustedProxyHeaders);
258
+ return `${url.origin}${basePath}/callback/${oauth}`;
355
259
  };
356
260
  var createRedirectTo = (request, redirectTo, trustedProxyHeaders) => {
357
261
  try {
@@ -365,15 +269,18 @@ var createRedirectTo = (request, redirectTo, trustedProxyHeaders) => {
365
269
  }
366
270
  const redirectToURL = new URL(sanitizeURL(getNormalizedOriginPath(redirectTo)));
367
271
  if (!isValidURL(redirectTo) || !equals(redirectToURL.origin, hostedURL.origin)) {
368
- throw new InvalidRedirectToError();
272
+ throw new AuthSecurityError(
273
+ "POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED",
274
+ "The redirectTo parameter does not match the hosted origin."
275
+ );
369
276
  }
370
277
  return sanitizeURL(redirectToURL.pathname);
371
278
  }
372
279
  if (referer) {
373
280
  const refererURL = new URL(sanitizeURL(referer));
374
281
  if (!isValidURL(referer) || !equals(refererURL.origin, hostedURL.origin)) {
375
- throw new AuthError(
376
- ERROR_RESPONSE.AUTHORIZATION.INVALID_REQUEST,
282
+ throw new AuthSecurityError(
283
+ "POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED",
377
284
  "The referer of the request does not match the hosted origin."
378
285
  );
379
286
  }
@@ -382,16 +289,16 @@ var createRedirectTo = (request, redirectTo, trustedProxyHeaders) => {
382
289
  if (origin) {
383
290
  const originURL = new URL(sanitizeURL(getNormalizedOriginPath(origin)));
384
291
  if (!isValidURL(origin) || !equals(originURL.origin, hostedURL.origin)) {
385
- throw new AuthError(ERROR_RESPONSE.AUTHORIZATION.INVALID_REQUEST, "Invalid origin (potential CSRF).");
292
+ throw new AuthSecurityError("POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED", "Invalid origin (potential CSRF).");
386
293
  }
387
294
  return sanitizeURL(originURL.pathname);
388
295
  }
389
296
  return "/";
390
297
  } catch (error) {
391
- if (isAuthError(error)) {
298
+ if (isAuthSecurityError(error)) {
392
299
  throw error;
393
300
  }
394
- throw new AuthError(ERROR_RESPONSE.AUTHORIZATION.INVALID_REQUEST, "Invalid origin (potential CSRF).");
301
+ throw new AuthSecurityError("POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED", "Invalid origin (potential CSRF).");
395
302
  }
396
303
  };
397
304
 
@@ -400,7 +307,7 @@ var signInConfig = (oauth) => {
400
307
  return (0, import_router2.createEndpointConfig)("/signIn/:oauth", {
401
308
  schemas: {
402
309
  params: import_zod.default.object({
403
- oauth: import_zod.default.enum(Object.keys(oauth)),
310
+ oauth: import_zod.default.enum(Object.keys(oauth), "The OAuth provider is not supported or invalid."),
404
311
  redirectTo: import_zod.default.string().optional()
405
312
  })
406
313
  }
@@ -413,52 +320,23 @@ var signInAction = (oauth) => {
413
320
  async (ctx) => {
414
321
  const {
415
322
  request,
323
+ headers: headersBuilder,
416
324
  params: { oauth: oauth2, redirectTo },
417
325
  context: { oauth: providers, cookies, trustedProxyHeaders, basePath }
418
326
  } = 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
- );
327
+ const state = generateSecure();
328
+ const redirectURI = createRedirectURI(request, oauth2, basePath, trustedProxyHeaders);
329
+ const redirectToValue = createRedirectTo(request, redirectTo, trustedProxyHeaders);
330
+ const { codeVerifier, codeChallenge, method } = await createPKCE();
331
+ const authorization = createAuthorizationURL(providers[oauth2], redirectURI, state, codeChallenge, method);
332
+ const headers = headersBuilder.setHeader("Location", authorization).setCookie(cookies.state.name, state, cookies.state.attributes).setCookie(cookies.redirect_uri.name, redirectURI, cookies.redirect_uri.attributes).setCookie(cookies.redirect_to.name, redirectToValue, cookies.redirect_to.attributes).setCookie(cookies.code_verifier.name, codeVerifier, cookies.code_verifier.attributes).toHeaders();
333
+ return Response.json(
334
+ { oauth: oauth2 },
335
+ {
336
+ status: 302,
337
+ headers
453
338
  }
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
- }
339
+ );
462
340
  },
463
341
  signInConfig(oauth)
464
342
  );
@@ -1,10 +1,9 @@
1
1
  import * as _aura_stack_router from '@aura-stack/router';
2
- import { A as AuthRuntimeConfig } from '../../index-DpfbvTZ_.js';
2
+ import { A as AuthRuntimeConfig } from '../../index-EqsoyjrF.js';
3
3
  import 'zod/v4';
4
- import '@aura-stack/jose/jose';
5
4
  import '../../schemas.js';
6
- import 'zod/v4/core';
7
- import 'cookie';
5
+ import '@aura-stack/router/cookie';
6
+ import '@aura-stack/jose/jose';
8
7
  import '../../@types/utility.js';
9
8
 
10
9
  declare const signInAction: (oauth: AuthRuntimeConfig["oauth"]) => _aura_stack_router.RouteEndpoint<"GET", "/signIn/:oauth", {}>;
@@ -1,14 +1,12 @@
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-2RXNXMCZ.js";
4
+ import "../../chunk-QEZL7EYN.js";
5
+ import "../../chunk-WD7AUHQ5.js";
6
+ import "../../chunk-N2APGLXA.js";
7
+ import "../../chunk-CXLATHS5.js";
8
+ import "../../chunk-EIL2FPSS.js";
9
+ import "../../chunk-RRLIF4PQ.js";
12
10
  export {
13
11
  signInAction
14
12
  };