@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
@@ -4,10 +4,9 @@ export { sessionAction } from './session/session.js';
4
4
  export { signOutAction } from './signOut/signOut.js';
5
5
  export { csrfTokenAction } from './csrfToken/csrfToken.js';
6
6
  import '@aura-stack/router';
7
- import '../index-DpfbvTZ_.js';
7
+ import '../index-EqsoyjrF.js';
8
8
  import 'zod/v4';
9
- import '@aura-stack/jose/jose';
10
9
  import '../schemas.js';
11
- import 'zod/v4/core';
12
- import 'cookie';
10
+ import '@aura-stack/router/cookie';
11
+ import '@aura-stack/jose/jose';
13
12
  import '../@types/utility.js';
@@ -1,30 +1,29 @@
1
1
  import "../chunk-ITQ7352M.js";
2
2
  import {
3
3
  csrfTokenAction
4
- } from "../chunk-SMQO5WD7.js";
5
- import {
6
- sessionAction
7
- } from "../chunk-XXJKNKGQ.js";
4
+ } from "../chunk-QDO2KSRJ.js";
8
5
  import {
9
6
  signInAction
10
- } from "../chunk-LLR722CL.js";
7
+ } from "../chunk-2RXNXMCZ.js";
8
+ import {
9
+ sessionAction
10
+ } from "../chunk-PTJUYB33.js";
11
11
  import {
12
12
  signOutAction
13
- } from "../chunk-SJPDVKUS.js";
14
- import "../chunk-CAKJT3KS.js";
13
+ } from "../chunk-NEVKX6K2.js";
14
+ import "../chunk-QEZL7EYN.js";
15
15
  import {
16
16
  callbackAction
17
- } from "../chunk-HGJ4TXY4.js";
18
- import "../chunk-RLT4RFKV.js";
19
- import "../chunk-UJJ7R56J.js";
20
- import "../chunk-ZV4BH47P.js";
21
- import "../chunk-6SM22VVJ.js";
17
+ } from "../chunk-UEH3LVON.js";
18
+ import "../chunk-ZLR3LI6X.js";
19
+ import "../chunk-4V4JNXVF.js";
20
+ import "../chunk-IMICRJ5U.js";
22
21
  import "../chunk-STHEPPUZ.js";
23
- import "../chunk-GZU3RBTB.js";
24
- import "../chunk-256KIVJL.js";
25
- import "../chunk-FJUDBLCP.js";
26
- import "../chunk-JAPMIE6S.js";
27
- import "../chunk-HMRKN75I.js";
22
+ import "../chunk-WD7AUHQ5.js";
23
+ import "../chunk-N2APGLXA.js";
24
+ import "../chunk-CXLATHS5.js";
25
+ import "../chunk-EIL2FPSS.js";
26
+ import "../chunk-RRLIF4PQ.js";
28
27
  export {
29
28
  callbackAction,
30
29
  csrfTokenAction,
@@ -28,12 +28,15 @@ var import_router2 = require("@aura-stack/router");
28
28
  // src/utils.ts
29
29
  var import_router = require("@aura-stack/router");
30
30
 
31
- // src/error.ts
32
- var AuthError = class extends Error {
33
- constructor(type, message) {
34
- super(message);
35
- this.type = type;
36
- this.name = "AuthError";
31
+ // src/errors.ts
32
+ var AuthInternalError = class extends Error {
33
+ type = "AUTH_INTERNAL_ERROR";
34
+ code;
35
+ constructor(code, message, options) {
36
+ super(message, options);
37
+ this.code = code;
38
+ this.name = new.target.name;
39
+ Error.captureStackTrace(this, new.target);
37
40
  }
38
41
  };
39
42
 
@@ -51,137 +54,50 @@ var cacheControl = {
51
54
  };
52
55
 
53
56
  // src/cookie.ts
54
- var import_cookie = require("cookie");
55
-
56
- // src/assert.ts
57
- var isRequest = (value) => {
58
- return typeof Request !== "undefined" && value instanceof Request;
59
- };
60
-
61
- // src/cookie.ts
62
- var import_cookie2 = require("cookie");
63
- var COOKIE_NAME = "aura-auth";
57
+ var import_cookie = require("@aura-stack/router/cookie");
64
58
  var defaultCookieOptions = {
65
59
  httpOnly: true,
66
60
  sameSite: "lax",
67
61
  path: "/",
68
62
  maxAge: 60 * 60 * 24 * 15
69
63
  };
70
- var defaultStandardCookieConfig = {
71
- secure: false,
64
+ var oauthCookieOptions = {
72
65
  httpOnly: true,
73
- prefix: ""
74
- };
75
- var defaultSecureCookieConfig = {
76
- secure: true,
77
- prefix: "__Secure-"
78
- };
79
- var defaultHostCookieConfig = {
80
- secure: true,
81
- prefix: "__Host-",
82
- path: "/",
83
- domain: void 0
66
+ maxAge: 5 * 60,
67
+ sameSite: "lax",
68
+ expires: new Date(Date.now() + 5 * 60 * 1e3)
84
69
  };
85
- var expiredCookieOptions = {
70
+ var expiredCookieAttributes = {
86
71
  ...defaultCookieOptions,
87
72
  expires: /* @__PURE__ */ new Date(0),
88
73
  maxAge: 0
89
74
  };
90
- var defineDefaultCookieOptions = (options) => {
91
- return {
92
- name: options?.name ?? COOKIE_NAME,
93
- prefix: options?.prefix ?? (options?.secure ? "__Secure-" : ""),
94
- ...defaultCookieOptions,
95
- ...options
96
- };
97
- };
98
- var setCookie = (cookieName, value, options) => {
99
- const { prefix, name } = defineDefaultCookieOptions(options);
100
- const cookieNameWithPrefix = `${prefix}${name}.${cookieName}`;
101
- return (0, import_cookie.serialize)(cookieNameWithPrefix, value, {
102
- ...defaultCookieOptions,
103
- ...options
104
- });
105
- };
106
- var getCookie = (petition, cookie, options, optional = false) => {
107
- const cookies = isRequest(petition) ? petition.headers.get("Cookie") : petition.headers.getSetCookie().join("; ");
75
+ var getCookie = (request, cookieName) => {
76
+ const cookies = request.headers.get("Cookie");
108
77
  if (!cookies) {
109
- if (optional) {
110
- return "";
111
- }
112
- throw new AuthError("invalid_request", "No cookies found. There is no active session");
78
+ throw new AuthInternalError("COOKIE_NOT_FOUND", "No cookies found. There is no active session");
113
79
  }
114
- const { name, prefix } = defineDefaultCookieOptions(options);
115
- const parsedCookies = (0, import_cookie.parse)(cookies);
116
- const value = parsedCookies[`${prefix}${name}.${cookie}`];
117
- if (value === void 0) {
118
- if (optional) {
119
- return "";
120
- }
121
- throw new AuthError("invalid_request", `Cookie "${cookie}" not found. There is no active session`);
80
+ const value = (0, import_cookie.parse)(cookies)[cookieName];
81
+ if (!value) {
82
+ throw new AuthInternalError("COOKIE_NOT_FOUND", `Cookie "${cookieName}" not found. There is no active session`);
122
83
  }
123
84
  return value;
124
85
  };
125
- var secureCookieOptions = (request, cookieOptions, trustedProxyHeaders) => {
126
- const name = cookieOptions.name ?? COOKIE_NAME;
127
- 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://");
128
- if (!cookieOptions.options?.httpOnly) {
129
- console.warn(
130
- "[WARNING]: Cookie is configured without HttpOnly. This allows JavaScript access via document.cookie and increases XSS risk."
131
- );
132
- }
133
- if (cookieOptions.options?.domain === "*") {
134
- console.warn("[WARNING]: Cookie 'Domain' is set to '*', which is insecure. Avoid wildcard domains.");
135
- }
136
- if (!isSecure) {
137
- const options = cookieOptions.options;
138
- if (options?.secure) {
139
- console.warn(
140
- "[WARNING]: The 'Secure' attribute will be disabled for this cookie. Serve over HTTPS to enforce Secure cookies."
141
- );
142
- }
143
- if (options?.sameSite == "none") {
144
- console.warn("[WARNING]: SameSite=None without a secure connection can be blocked by browsers.");
145
- }
146
- if (process.env.NODE_ENV === "production") {
147
- console.warn("[WARNING]: In production, ensure cookies are served over HTTPS to maintain security.");
148
- }
149
- return {
150
- ...defaultCookieOptions,
151
- ...cookieOptions.options,
152
- sameSite: options?.sameSite === "none" ? "lax" : options?.sameSite ?? "lax",
153
- ...defaultStandardCookieConfig,
154
- name
155
- };
156
- }
157
- return cookieOptions.strategy === "host" ? {
158
- ...defaultCookieOptions,
159
- ...cookieOptions.options,
160
- ...defaultHostCookieConfig,
161
- name
162
- } : { ...defaultCookieOptions, ...cookieOptions.options, ...defaultSecureCookieConfig, name };
163
- };
164
- var expireCookie = (name, options) => {
165
- return setCookie(name, "", { ...options, ...expiredCookieOptions });
166
- };
167
86
 
168
87
  // src/actions/session/session.ts
169
88
  var sessionAction = (0, import_router2.createEndpoint)("GET", "/session", async (ctx) => {
170
89
  const {
171
90
  request,
172
- context: { cookies, jose, trustedProxyHeaders }
91
+ context: { jose, cookies }
173
92
  } = ctx;
174
- const cookieOptions = secureCookieOptions(request, cookies, trustedProxyHeaders);
175
93
  try {
176
- const session = getCookie(request, "sessionToken", cookieOptions);
94
+ const session = getCookie(request, cookies.sessionToken.name);
177
95
  const decoded = await jose.decodeJWT(session);
178
96
  const { exp, iat, jti, nbf, ...user } = decoded;
179
97
  const headers = new Headers(cacheControl);
180
98
  return Response.json({ user, expires: toISOString(exp * 1e3) }, { headers });
181
- } catch {
182
- const headers = new Headers(cacheControl);
183
- const sessionCookie = expireCookie("sessionToken", cookieOptions);
184
- headers.set("Set-Cookie", sessionCookie);
99
+ } catch (error) {
100
+ const headers = new import_router2.HeadersBuilder(cacheControl).setCookie(cookies.sessionToken.name, "", expiredCookieAttributes).toHeaders();
185
101
  return Response.json({ authenticated: false, message: "Unauthorized" }, { status: 401, headers });
186
102
  }
187
103
  });
@@ -1,11 +1,10 @@
1
1
  import {
2
2
  sessionAction
3
- } from "../../chunk-XXJKNKGQ.js";
4
- import "../../chunk-ZV4BH47P.js";
5
- import "../../chunk-6SM22VVJ.js";
3
+ } from "../../chunk-PTJUYB33.js";
4
+ import "../../chunk-IMICRJ5U.js";
6
5
  import "../../chunk-STHEPPUZ.js";
7
- import "../../chunk-256KIVJL.js";
8
- import "../../chunk-FJUDBLCP.js";
6
+ import "../../chunk-CXLATHS5.js";
7
+ import "../../chunk-RRLIF4PQ.js";
9
8
  export {
10
9
  sessionAction
11
10
  };
@@ -37,10 +37,10 @@ var isValidURL = (value) => {
37
37
  // src/schemas.ts
38
38
  var import_v4 = require("zod/v4");
39
39
  var OAuthProviderConfigSchema = (0, import_v4.object)({
40
- authorizeURL: (0, import_v4.url)(),
41
- accessToken: (0, import_v4.url)(),
40
+ authorizeURL: (0, import_v4.httpUrl)(),
41
+ accessToken: (0, import_v4.httpUrl)(),
42
42
  scope: (0, import_v4.string)().optional(),
43
- userInfo: (0, import_v4.url)(),
43
+ userInfo: (0, import_v4.httpUrl)(),
44
44
  responseType: (0, import_v4.enum)(["code", "token", "id_token"]),
45
45
  clientId: (0, import_v4.string)(),
46
46
  clientSecret: (0, import_v4.string)()
@@ -52,8 +52,8 @@ var OAuthAuthorization = OAuthProviderConfigSchema.extend({
52
52
  codeChallengeMethod: (0, import_v4.enum)(["plain", "S256"])
53
53
  });
54
54
  var OAuthAuthorizationResponse = (0, import_v4.object)({
55
- state: (0, import_v4.string)(),
56
- code: (0, import_v4.string)()
55
+ state: (0, import_v4.string)("Missing state parameter in the OAuth authorization response."),
56
+ code: (0, import_v4.string)("Missing code parameter in the OAuth authorization response.")
57
57
  });
58
58
  var OAuthAuthorizationErrorResponse = (0, import_v4.object)({
59
59
  error: (0, import_v4.enum)([
@@ -97,48 +97,38 @@ var OAuthErrorResponse = (0, import_v4.object)({
97
97
  error: (0, import_v4.string)(),
98
98
  error_description: (0, import_v4.string)().optional()
99
99
  });
100
+ var OAuthEnvSchema = (0, import_v4.object)({
101
+ clientId: import_v4.z.string().min(1, "OAuth Client ID is required in the environment variables."),
102
+ clientSecret: import_v4.z.string().min(1, "OAuth Client Secret is required in the environment variables.")
103
+ });
100
104
 
101
- // src/utils.ts
102
- var import_router = require("@aura-stack/router");
103
-
104
- // src/error.ts
105
- var AuthError = class extends Error {
106
- constructor(type, message) {
107
- super(message);
108
- this.type = type;
109
- this.name = "AuthError";
105
+ // src/errors.ts
106
+ var AuthInternalError = class extends Error {
107
+ type = "AUTH_INTERNAL_ERROR";
108
+ code;
109
+ constructor(code, message, options2) {
110
+ super(message, options2);
111
+ this.code = code;
112
+ this.name = new.target.name;
113
+ Error.captureStackTrace(this, new.target);
110
114
  }
111
115
  };
112
- var InvalidRedirectToError = class extends AuthError {
113
- constructor(message = "The redirectTo parameter does not match the hosted origin.") {
114
- super("invalid_redirect_to", message);
115
- this.name = "InvalidRedirectToError";
116
+ var AuthSecurityError = class extends Error {
117
+ type = "AUTH_SECURITY_ERROR";
118
+ code;
119
+ constructor(code, message, options2) {
120
+ super(message, options2);
121
+ this.code = code;
122
+ this.name = new.target.name;
123
+ Error.captureStackTrace(this, new.target);
116
124
  }
117
125
  };
118
- var isAuthError = (error) => {
119
- return error instanceof AuthError;
120
- };
121
- var ERROR_RESPONSE = {
122
- AUTHORIZATION: {
123
- INVALID_REQUEST: "invalid_request",
124
- UNAUTHORIZED_CLIENT: "unauthorized_client",
125
- ACCESS_DENIED: "access_denied",
126
- UNSUPPORTED_RESPONSE_TYPE: "unsupported_response_type",
127
- INVALID_SCOPE: "invalid_scope",
128
- SERVER_ERROR: "server_error",
129
- TEMPORARILY_UNAVAILABLE: "temporarily_unavailable"
130
- },
131
- ACCESS_TOKEN: {
132
- INVALID_REQUEST: "invalid_request",
133
- INVALID_CLIENT: "invalid_client",
134
- INVALID_GRANT: "invalid_grant",
135
- UNAUTHORIZED_CLIENT: "unauthorized_client",
136
- UNSUPPORTED_GRANT_TYPE: "unsupported_grant_type",
137
- INVALID_SCOPE: "invalid_scope"
138
- }
126
+ var isAuthSecurityError = (error) => {
127
+ return error instanceof AuthSecurityError;
139
128
  };
140
129
 
141
130
  // src/utils.ts
131
+ var import_router = require("@aura-stack/router");
142
132
  var toSnakeCase = (str) => {
143
133
  return str.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2").toLowerCase().replace(/^_+/, "");
144
134
  };
@@ -155,9 +145,9 @@ var equals = (a, b) => {
155
145
  if (a === null || b === null || a === void 0 || b === void 0) return false;
156
146
  return a === b;
157
147
  };
158
- var sanitizeURL = (url2) => {
148
+ var sanitizeURL = (url) => {
159
149
  try {
160
- let decodedURL = decodeURIComponent(url2).trim();
150
+ let decodedURL = decodeURIComponent(url).trim();
161
151
  const protocolMatch = decodedURL.match(/^([a-zA-Z][a-zA-Z0-9+.-]*:\/\/)/);
162
152
  let protocol = "";
163
153
  let rest = decodedURL;
@@ -185,25 +175,41 @@ var sanitizeURL = (url2) => {
185
175
  }
186
176
  return sanitized;
187
177
  } catch {
188
- return url2.trim();
178
+ return url.trim();
189
179
  }
190
180
  };
191
181
  var getNormalizedOriginPath = (path) => {
192
182
  try {
193
- const url2 = new URL(path);
194
- url2.hash = "";
195
- url2.search = "";
196
- return `${url2.origin}${url2.pathname}`;
183
+ const url = new URL(path);
184
+ url.hash = "";
185
+ url.search = "";
186
+ return `${url.origin}${url.pathname}`;
197
187
  } catch {
198
188
  return sanitizeURL(path);
199
189
  }
200
190
  };
191
+ var formatZodError = (error) => {
192
+ if (!error.issues || error.issues.length === 0) {
193
+ return {};
194
+ }
195
+ return error.issues.reduce((previous, issue) => {
196
+ const key = issue.path.join(".");
197
+ return {
198
+ ...previous,
199
+ [key]: {
200
+ code: issue.code,
201
+ message: issue.message
202
+ }
203
+ };
204
+ }, {});
205
+ };
201
206
 
202
207
  // src/actions/signIn/authorization.ts
203
208
  var createAuthorizationURL = (oauthConfig, redirectURI, state, codeChallenge, codeChallengeMethod) => {
204
209
  const parsed = OAuthAuthorization.safeParse({ ...oauthConfig, redirectURI, state, codeChallenge, codeChallengeMethod });
205
210
  if (!parsed.success) {
206
- throw new AuthError(ERROR_RESPONSE.AUTHORIZATION.SERVER_ERROR, "Invalid OAuth configuration");
211
+ const msg = JSON.stringify(formatZodError(parsed.error), null, 2);
212
+ throw new AuthInternalError("INVALID_OAUTH_CONFIGURATION", msg);
207
213
  }
208
214
  const { authorizeURL, ...options2 } = parsed.data;
209
215
  const { userInfo, accessToken, clientSecret, ...required } = options2;
@@ -221,8 +227,8 @@ var getOriginURL = (request, trustedProxyHeaders) => {
221
227
  }
222
228
  };
223
229
  var createRedirectURI = (request, oauth, basePath, trustedProxyHeaders) => {
224
- const url2 = getOriginURL(request, trustedProxyHeaders);
225
- return `${url2.origin}${basePath}/callback/${oauth}`;
230
+ const url = getOriginURL(request, trustedProxyHeaders);
231
+ return `${url.origin}${basePath}/callback/${oauth}`;
226
232
  };
227
233
  var createRedirectTo = (request, redirectTo, trustedProxyHeaders) => {
228
234
  try {
@@ -236,15 +242,18 @@ var createRedirectTo = (request, redirectTo, trustedProxyHeaders) => {
236
242
  }
237
243
  const redirectToURL = new URL(sanitizeURL(getNormalizedOriginPath(redirectTo)));
238
244
  if (!isValidURL(redirectTo) || !equals(redirectToURL.origin, hostedURL.origin)) {
239
- throw new InvalidRedirectToError();
245
+ throw new AuthSecurityError(
246
+ "POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED",
247
+ "The redirectTo parameter does not match the hosted origin."
248
+ );
240
249
  }
241
250
  return sanitizeURL(redirectToURL.pathname);
242
251
  }
243
252
  if (referer) {
244
253
  const refererURL = new URL(sanitizeURL(referer));
245
254
  if (!isValidURL(referer) || !equals(refererURL.origin, hostedURL.origin)) {
246
- throw new AuthError(
247
- ERROR_RESPONSE.AUTHORIZATION.INVALID_REQUEST,
255
+ throw new AuthSecurityError(
256
+ "POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED",
248
257
  "The referer of the request does not match the hosted origin."
249
258
  );
250
259
  }
@@ -253,16 +262,16 @@ var createRedirectTo = (request, redirectTo, trustedProxyHeaders) => {
253
262
  if (origin) {
254
263
  const originURL = new URL(sanitizeURL(getNormalizedOriginPath(origin)));
255
264
  if (!isValidURL(origin) || !equals(originURL.origin, hostedURL.origin)) {
256
- throw new AuthError(ERROR_RESPONSE.AUTHORIZATION.INVALID_REQUEST, "Invalid origin (potential CSRF).");
265
+ throw new AuthSecurityError("POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED", "Invalid origin (potential CSRF).");
257
266
  }
258
267
  return sanitizeURL(originURL.pathname);
259
268
  }
260
269
  return "/";
261
270
  } catch (error) {
262
- if (isAuthError(error)) {
271
+ if (isAuthSecurityError(error)) {
263
272
  throw error;
264
273
  }
265
- throw new AuthError(ERROR_RESPONSE.AUTHORIZATION.INVALID_REQUEST, "Invalid origin (potential CSRF).");
274
+ throw new AuthSecurityError("POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED", "Invalid origin (potential CSRF).");
266
275
  }
267
276
  };
268
277
  // Annotate the CommonJS export names for ESM import in node:
@@ -1,9 +1,8 @@
1
- import { f as OAuthProviderCredentials } from '../../index-DpfbvTZ_.js';
1
+ import { h as OAuthProviderCredentials } from '../../index-EqsoyjrF.js';
2
2
  import 'zod/v4';
3
- import '@aura-stack/jose/jose';
4
3
  import '../../schemas.js';
5
- import 'zod/v4/core';
6
- import 'cookie';
4
+ import '@aura-stack/router/cookie';
5
+ import '@aura-stack/jose/jose';
7
6
  import '../../@types/utility.js';
8
7
 
9
8
  /**
@@ -3,11 +3,11 @@ import {
3
3
  createRedirectTo,
4
4
  createRedirectURI,
5
5
  getOriginURL
6
- } from "../../chunk-CAKJT3KS.js";
7
- import "../../chunk-6SM22VVJ.js";
8
- import "../../chunk-256KIVJL.js";
9
- import "../../chunk-FJUDBLCP.js";
10
- import "../../chunk-HMRKN75I.js";
6
+ } from "../../chunk-QEZL7EYN.js";
7
+ import "../../chunk-WD7AUHQ5.js";
8
+ import "../../chunk-CXLATHS5.js";
9
+ import "../../chunk-EIL2FPSS.js";
10
+ import "../../chunk-RRLIF4PQ.js";
11
11
  export {
12
12
  createAuthorizationURL,
13
13
  createRedirectTo,