@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
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
 
30
20
  // src/actions/callback/callback.ts
@@ -33,12 +23,9 @@ __export(callback_exports, {
33
23
  callbackAction: () => callbackAction
34
24
  });
35
25
  module.exports = __toCommonJS(callback_exports);
36
- var import_zod2 = require("zod");
26
+ var import_v42 = require("zod/v4");
37
27
  var import_router2 = require("@aura-stack/router");
38
28
 
39
- // src/secure.ts
40
- var import_crypto = __toESM(require("crypto"), 1);
41
-
42
29
  // src/utils.ts
43
30
  var import_router = require("@aura-stack/router");
44
31
 
@@ -82,77 +69,164 @@ var isOAuthProtocolError = (error) => {
82
69
  return error instanceof OAuthProtocolError;
83
70
  };
84
71
 
85
- // src/utils.ts
86
- var equals = (a, b) => {
87
- if (a === null || b === null || a === void 0 || b === void 0) return false;
88
- return a === b;
89
- };
90
- var sanitizeURL = (url) => {
91
- try {
92
- let decodedURL = decodeURIComponent(url).trim();
93
- const protocolMatch = decodedURL.match(/^([a-zA-Z][a-zA-Z0-9+.-]*:\/\/)/);
94
- let protocol = "";
95
- let rest = decodedURL;
96
- if (protocolMatch) {
97
- protocol = protocolMatch[1];
98
- rest = decodedURL.slice(protocol.length);
99
- const slashIndex = rest.indexOf("/");
100
- if (slashIndex === -1) {
101
- return protocol + rest;
72
+ // src/env.ts
73
+ var import_meta = {};
74
+ var env = new Proxy({}, {
75
+ get(_, prop) {
76
+ if (typeof prop !== "string") return void 0;
77
+ const hasProperty = (process2) => {
78
+ return process2 && Object.prototype.hasOwnProperty.call(process2, prop);
79
+ };
80
+ try {
81
+ if (typeof process !== "undefined" && hasProperty(process.env)) {
82
+ return process.env[prop];
102
83
  }
103
- const domain = rest.slice(0, slashIndex);
104
- let path = rest.slice(slashIndex).replace(/\/\.\.\//g, "/").replace(/\/\.\.$/, "").replace(/\.{2,}/g, "").replace(/\/{2,}/g, "/");
105
- if (path !== "/" && path.endsWith("/")) {
106
- path = path.replace(/\/+$/, "/");
107
- } else if (path !== "/") {
108
- path = path.replace(/\/+$/, "");
84
+ if (typeof import_meta !== "undefined" && hasProperty(import_meta.env)) {
85
+ return import_meta.env[prop];
109
86
  }
110
- return protocol + domain + path;
87
+ if (typeof Deno !== "undefined" && Deno.env?.get) {
88
+ return Deno.env.get(prop);
89
+ }
90
+ if (typeof Bun !== "undefined" && hasProperty(Bun.env)) {
91
+ return Bun.env[prop];
92
+ }
93
+ const globalValue = globalThis[prop];
94
+ return typeof globalValue === "string" ? globalValue : void 0;
95
+ } catch {
96
+ return void 0;
111
97
  }
112
- let sanitized = decodedURL.replace(/\/\.\.\//g, "/").replace(/\/\.\.$/, "").replace(/\.{2,}/g, "").replace(/\/{2,}/g, "/");
113
- if (sanitized !== "/" && sanitized.endsWith("/")) {
114
- sanitized = sanitized.replace(/\/+$/, "/");
115
- } else if (sanitized !== "/") {
116
- sanitized = sanitized.replace(/\/+$/, "");
98
+ }
99
+ });
100
+ var getEnv = (key) => {
101
+ const keys = [`AURA_AUTH_${key.toUpperCase()}`, `AURA_${key.toUpperCase()}`, `AUTH_${key.toUpperCase()}`, key.toUpperCase()];
102
+ return env[keys.find((k) => env[k]) ?? ""];
103
+ };
104
+
105
+ // src/assert.ts
106
+ var import_crypto = require("@aura-stack/jose/crypto");
107
+ var unsafeChars = [
108
+ "<",
109
+ ">",
110
+ '"',
111
+ "`",
112
+ " ",
113
+ "\r",
114
+ "\n",
115
+ " ",
116
+ "\\",
117
+ "%2F",
118
+ "%5C",
119
+ "%2f",
120
+ "%5c",
121
+ "\r\n",
122
+ "%0A",
123
+ "%0D",
124
+ "%0a",
125
+ "%0d",
126
+ "..",
127
+ "//",
128
+ "///",
129
+ "...",
130
+ "%20",
131
+ "\0"
132
+ ];
133
+ var isValidURL = (value) => {
134
+ if (!new RegExp(/^https?:\/\/[^/]/).test(value)) {
135
+ return false;
136
+ }
137
+ const match = value.match(/^(https?:\/\/)(.*)$/);
138
+ if (!match) return false;
139
+ const rest = match[2];
140
+ for (const char of unsafeChars) {
141
+ if (rest.includes(char)) return false;
142
+ }
143
+ const regex = /^https?:\/\/(?:[a-zA-Z0-9._-]+|localhost|\[[0-9a-fA-F:]+\])(?::\d{1,5})?(?:\/[a-zA-Z0-9._~!$&'()?#*+,;=:@-]*)*\/?$/;
144
+ return regex.test(match[0]);
145
+ };
146
+ var isRelativeURL = (value) => {
147
+ if (value.length > 100) return false;
148
+ for (const char of unsafeChars) {
149
+ if (value.includes(char)) return false;
150
+ }
151
+ const regex = /^\/[a-zA-Z0-9\-_\/.?&=#]*\/?$/;
152
+ return regex.test(value);
153
+ };
154
+ var isSameOrigin = (origin, expected) => {
155
+ const originURL = new URL(origin);
156
+ const expectedURL = new URL(expected);
157
+ return equals(originURL.origin, expectedURL.origin);
158
+ };
159
+ var patternToRegex = (pattern) => {
160
+ try {
161
+ if (pattern.length > 2048) return null;
162
+ pattern = pattern.replace(/\\/g, "");
163
+ const match = pattern.match(/^(https?):\/\/([a-zA-Z0-9.*-]{1,253})(?::(\d{1,5}|\*))?(?:\/.*)?$/);
164
+ if (!match) return null;
165
+ const [, protocol, host, port] = match;
166
+ const hasWildcard = host.includes("*");
167
+ if (hasWildcard && !host.startsWith("*.")) return null;
168
+ if (hasWildcard && host.slice(2).includes("*")) return null;
169
+ const domain = hasWildcard ? host.slice(2) : host;
170
+ const escapedDomain = domain.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
171
+ const hostRegex = hasWildcard ? `[^.]+\\.${escapedDomain}` : escapedDomain;
172
+ const portRegex = port === "*" ? ":\\d{1,5}" : port ? `:${port}` : "";
173
+ return new RegExp(`^${protocol}:\\/\\/${hostRegex}${portRegex}$`);
174
+ } catch {
175
+ return null;
176
+ }
177
+ };
178
+ var isTrustedOrigin = (url, trustedOrigins) => {
179
+ if (!isValidURL(url) || trustedOrigins.length === 0) return false;
180
+ try {
181
+ const urlOrigin = new URL(url).origin;
182
+ for (const pattern of trustedOrigins) {
183
+ const regex = patternToRegex(pattern);
184
+ if (regex?.test(urlOrigin)) return true;
185
+ try {
186
+ if (isValidURL(pattern) && equals(new URL(pattern).origin, urlOrigin)) return true;
187
+ } catch {
188
+ }
117
189
  }
118
- return sanitized;
119
190
  } catch {
120
- return url.trim();
121
191
  }
192
+ return false;
122
193
  };
123
- var isValidRelativePath = (path) => {
124
- if (!path || typeof path !== "string") return false;
125
- if (!path.startsWith("/") || path.includes("://") || path.includes("\r") || path.includes("\n")) return false;
126
- if (/[\x00-\x1F\x7F]/.test(path) || path.includes("\0")) return false;
127
- const sanitized = sanitizeURL(path);
128
- if (sanitized.includes("..")) return false;
129
- return true;
130
- };
131
- var formatZodError = (error) => {
132
- if (!error.issues || error.issues.length === 0) {
133
- return {};
194
+ var timingSafeEqual = (a, b) => {
195
+ const bufferA = import_crypto.encoder.encode(a);
196
+ const bufferB = import_crypto.encoder.encode(b);
197
+ const len = Math.max(bufferA.length, bufferB.length);
198
+ let diff = 0;
199
+ for (let i = 0; i < len; i++) {
200
+ diff |= (bufferA[i] ?? 0) ^ (bufferB[i] ?? 0);
134
201
  }
135
- return error.issues.reduce((previous, issue) => {
136
- const key = issue.path.join(".");
137
- return {
138
- ...previous,
139
- [key]: {
140
- code: issue.code,
141
- message: issue.message
142
- }
143
- };
144
- }, {});
202
+ return diff === 0 && bufferA.length === bufferB.length;
203
+ };
204
+
205
+ // src/utils.ts
206
+ var AURA_AUTH_VERSION = "0.4.0";
207
+ var equals = (a, b) => {
208
+ if (a === null || b === null || a === void 0 || b === void 0) return false;
209
+ return a === b;
210
+ };
211
+
212
+ // src/jose.ts
213
+ var import_jose = require("@aura-stack/jose");
214
+ var import_jose2 = require("@aura-stack/jose/jose");
215
+ var import_crypto2 = require("@aura-stack/jose/crypto");
216
+ var jwtVerificationOptions = {
217
+ algorithms: ["HS256"],
218
+ typ: "JWT"
145
219
  };
146
220
 
147
221
  // src/secure.ts
148
222
  var generateSecure = (length = 32) => {
149
- return import_crypto.default.randomBytes(length).toString("base64url");
223
+ return import_jose2.base64url.encode((0, import_crypto2.getRandomBytes)(length));
150
224
  };
151
225
  var createCSRF = async (jose, csrfCookie) => {
152
226
  try {
153
227
  const token = generateSecure(32);
154
228
  if (csrfCookie) {
155
- await jose.verifyJWS(csrfCookie);
229
+ await jose.verifyJWS(csrfCookie, jwtVerificationOptions);
156
230
  return csrfCookie;
157
231
  }
158
232
  return jose.signJWS({ token });
@@ -169,6 +243,26 @@ var cacheControl = {
169
243
  Expires: "0",
170
244
  Vary: "Cookie"
171
245
  };
246
+ var contentSecurityPolicy = {
247
+ "Content-Security-Policy": [
248
+ "default-src 'none'",
249
+ "script-src 'self'",
250
+ "frame-src 'none'",
251
+ "object-src 'none'",
252
+ "frame-ancestors 'none'",
253
+ "base-uri 'none'"
254
+ ].join("; ")
255
+ };
256
+ var secureHeaders = {
257
+ "X-Content-Type-Options": "nosniff",
258
+ "X-Frame-Options": "DENY",
259
+ "Referrer-Policy": "strict-origin-when-cross-origin"
260
+ };
261
+ var secureApiHeaders = {
262
+ ...cacheControl,
263
+ ...contentSecurityPolicy,
264
+ ...secureHeaders
265
+ };
172
266
 
173
267
  // src/request.ts
174
268
  var fetchAsync = async (url, options2 = {}, timeout = 5e3) => {
@@ -182,28 +276,73 @@ var fetchAsync = async (url, options2 = {}, timeout = 5e3) => {
182
276
  };
183
277
 
184
278
  // src/schemas.ts
185
- var import_zod = require("zod");
186
- var OAuthProviderConfigSchema = (0, import_zod.object)({
187
- authorizeURL: (0, import_zod.string)().url(),
188
- accessToken: (0, import_zod.string)().url(),
189
- scope: (0, import_zod.string)().optional(),
190
- userInfo: (0, import_zod.string)().url(),
191
- responseType: (0, import_zod.enum)(["code", "token", "id_token"]),
192
- clientId: (0, import_zod.string)(),
193
- clientSecret: (0, import_zod.string)()
279
+ var import_v4 = require("zod/v4");
280
+ var AuthorizeConfigSchema = import_v4.z.union([
281
+ (0, import_v4.string)().url(),
282
+ (0, import_v4.object)({
283
+ url: (0, import_v4.string)().url(),
284
+ params: (0, import_v4.object)({
285
+ responseType: (0, import_v4.enum)(["code", "token", "id_token", "refresh_token"]).optional(),
286
+ scope: (0, import_v4.string)().optional()
287
+ })
288
+ })
289
+ ]);
290
+ var AccessTokenConfigSchema = import_v4.z.union([
291
+ (0, import_v4.string)().url(),
292
+ (0, import_v4.object)({
293
+ url: (0, import_v4.string)().url(),
294
+ headers: import_v4.z.record((0, import_v4.string)(), (0, import_v4.string)()).optional()
295
+ })
296
+ ]);
297
+ var UserInfoConfigSchema = import_v4.z.union([
298
+ (0, import_v4.string)().url(),
299
+ (0, import_v4.object)({
300
+ url: (0, import_v4.string)().url(),
301
+ headers: import_v4.z.record((0, import_v4.string)(), (0, import_v4.string)()).optional(),
302
+ method: (0, import_v4.string)().optional()
303
+ })
304
+ ]);
305
+ var OAuthProviderCredentialsSchema = (0, import_v4.object)({
306
+ id: (0, import_v4.string)(),
307
+ name: (0, import_v4.string)(),
308
+ authorize: AuthorizeConfigSchema.optional(),
309
+ /** @deprecated */
310
+ authorizeURL: (0, import_v4.string)().url().optional(),
311
+ accessToken: AccessTokenConfigSchema,
312
+ /** @deprecated */
313
+ scope: (0, import_v4.string)().optional(),
314
+ userInfo: UserInfoConfigSchema,
315
+ /** @deprecated */
316
+ responseType: (0, import_v4.enum)(["code", "token", "id_token", "refresh_token"]).optional(),
317
+ clientId: (0, import_v4.string)(),
318
+ clientSecret: (0, import_v4.string)(),
319
+ profile: import_v4.z.function().optional()
320
+ });
321
+ var OAuthProviderConfigSchema = (0, import_v4.object)({
322
+ authorize: AuthorizeConfigSchema.optional(),
323
+ /** @deprecated */
324
+ authorizeURL: (0, import_v4.string)().url().optional(),
325
+ accessToken: AccessTokenConfigSchema,
326
+ /** @deprecated */
327
+ scope: (0, import_v4.string)().optional(),
328
+ userInfo: UserInfoConfigSchema,
329
+ /** @deprecated */
330
+ responseType: (0, import_v4.enum)(["code", "token", "id_token", "refresh_token"]).optional(),
331
+ clientId: (0, import_v4.string)(),
332
+ clientSecret: (0, import_v4.string)()
194
333
  });
195
334
  var OAuthAuthorization = OAuthProviderConfigSchema.extend({
196
- redirectURI: (0, import_zod.string)(),
197
- state: (0, import_zod.string)(),
198
- codeChallenge: (0, import_zod.string)(),
199
- codeChallengeMethod: (0, import_zod.enum)(["plain", "S256"])
335
+ redirectURI: (0, import_v4.string)(),
336
+ state: (0, import_v4.string)(),
337
+ codeChallenge: (0, import_v4.string)(),
338
+ codeChallengeMethod: (0, import_v4.enum)(["plain", "S256"])
200
339
  });
201
- var OAuthAuthorizationResponse = (0, import_zod.object)({
202
- state: (0, import_zod.string)({ message: "Missing state parameter in the OAuth authorization response." }),
203
- code: (0, import_zod.string)({ message: "Missing code parameter in the OAuth authorization response." })
340
+ var OAuthAuthorizationResponse = (0, import_v4.object)({
341
+ state: (0, import_v4.string)({ message: "Missing state parameter in the OAuth authorization response." }),
342
+ code: (0, import_v4.string)({ message: "Missing code parameter in the OAuth authorization response." })
204
343
  });
205
- var OAuthAuthorizationErrorResponse = (0, import_zod.object)({
206
- error: (0, import_zod.enum)([
344
+ var OAuthAuthorizationErrorResponse = (0, import_v4.object)({
345
+ error: (0, import_v4.enum)([
207
346
  "invalid_request",
208
347
  "unauthorized_client",
209
348
  "access_denied",
@@ -212,24 +351,24 @@ var OAuthAuthorizationErrorResponse = (0, import_zod.object)({
212
351
  "server_error",
213
352
  "temporarily_unavailable"
214
353
  ]),
215
- error_description: (0, import_zod.string)().optional(),
216
- error_uri: (0, import_zod.string)().optional(),
217
- state: (0, import_zod.string)()
354
+ error_description: (0, import_v4.string)().optional(),
355
+ error_uri: (0, import_v4.string)().optional(),
356
+ state: (0, import_v4.string)()
218
357
  });
219
358
  var OAuthAccessToken = OAuthProviderConfigSchema.extend({
220
- redirectURI: (0, import_zod.string)(),
221
- code: (0, import_zod.string)(),
222
- codeVerifier: (0, import_zod.string)().min(43).max(128)
359
+ redirectURI: (0, import_v4.string)(),
360
+ code: (0, import_v4.string)(),
361
+ codeVerifier: (0, import_v4.string)().min(43).max(128)
223
362
  });
224
- var OAuthAccessTokenResponse = (0, import_zod.object)({
225
- access_token: (0, import_zod.string)(),
226
- token_type: (0, import_zod.string)().optional(),
227
- expires_in: (0, import_zod.number)().optional(),
228
- refresh_token: (0, import_zod.string)().optional(),
229
- scope: (0, import_zod.string)().optional().or((0, import_zod.null)())
363
+ var OAuthAccessTokenResponse = (0, import_v4.object)({
364
+ access_token: (0, import_v4.string)(),
365
+ token_type: (0, import_v4.string)().optional(),
366
+ expires_in: (0, import_v4.number)().optional(),
367
+ refresh_token: (0, import_v4.string)().optional(),
368
+ scope: (0, import_v4.union)([(0, import_v4.string)().optional().or((0, import_v4.null)()), (0, import_v4.array)((0, import_v4.string)()).optional()])
230
369
  });
231
- var OAuthAccessTokenErrorResponse = (0, import_zod.object)({
232
- error: (0, import_zod.enum)([
370
+ var OAuthAccessTokenErrorResponse = (0, import_v4.object)({
371
+ error: (0, import_v4.enum)([
233
372
  "invalid_request",
234
373
  "invalid_client",
235
374
  "invalid_grant",
@@ -237,16 +376,16 @@ var OAuthAccessTokenErrorResponse = (0, import_zod.object)({
237
376
  "unsupported_grant_type",
238
377
  "invalid_scope"
239
378
  ]),
240
- error_description: (0, import_zod.string)().optional(),
241
- error_uri: (0, import_zod.string)().optional()
379
+ error_description: (0, import_v4.string)().optional(),
380
+ error_uri: (0, import_v4.string)().optional()
242
381
  });
243
- var OAuthErrorResponse = (0, import_zod.object)({
244
- error: (0, import_zod.string)(),
245
- error_description: (0, import_zod.string)().optional()
382
+ var OAuthErrorResponse = (0, import_v4.object)({
383
+ error: (0, import_v4.string)(),
384
+ error_description: (0, import_v4.string)().optional()
246
385
  });
247
- var OAuthEnvSchema = (0, import_zod.object)({
248
- clientId: import_zod.z.string().min(1, "OAuth Client ID is required in the environment variables."),
249
- clientSecret: import_zod.z.string().min(1, "OAuth Client Secret is required in the environment variables.")
386
+ var OAuthEnvSchema = (0, import_v4.object)({
387
+ clientId: import_v4.z.string().min(1, "OAuth Client ID is required in the environment variables."),
388
+ clientSecret: import_v4.z.string().min(1, "OAuth Client Secret is required in the environment variables.")
250
389
  });
251
390
 
252
391
  // src/actions/callback/userinfo.ts
@@ -259,71 +398,171 @@ var getDefaultUserInfo = (profile) => {
259
398
  image: profile?.image ?? profile?.picture
260
399
  };
261
400
  };
262
- var getUserInfo = async (oauthConfig, accessToken) => {
263
- const userinfoEndpoint = oauthConfig.userInfo;
401
+ var getUserInfo = async (oauthConfig, accessToken, logger) => {
402
+ const userInfoConfig = oauthConfig.userInfo;
403
+ const userinfoURL = typeof userInfoConfig === "string" ? userInfoConfig : userInfoConfig.url;
404
+ const extraHeaders = typeof userInfoConfig === "string" ? void 0 : userInfoConfig.headers;
405
+ const method = typeof userInfoConfig === "string" ? "GET" : (userInfoConfig.method ?? "GET").toUpperCase();
264
406
  try {
265
- const response = await fetchAsync(userinfoEndpoint, {
266
- method: "GET",
407
+ logger?.log("OAUTH_USERINFO_REQUEST_INITIATED", {
408
+ structuredData: {
409
+ endpoint: userinfoURL
410
+ }
411
+ });
412
+ const response = await fetchAsync(userinfoURL, {
413
+ method,
267
414
  headers: {
415
+ "User-Agent": `Aura Auth/${AURA_AUTH_VERSION}`,
268
416
  Accept: "application/json",
269
- Authorization: `Bearer ${accessToken}`
417
+ Authorization: `Bearer ${accessToken}`,
418
+ ...extraHeaders ?? {}
270
419
  }
271
420
  });
421
+ if (!response.ok) {
422
+ logger?.log("OAUTH_USERINFO_INVALID_RESPONSE");
423
+ throw new OAuthProtocolError("INVALID_REQUEST", "Invalid userinfo response format");
424
+ }
272
425
  const json = await response.json();
273
426
  const { success, data } = OAuthErrorResponse.safeParse(json);
274
427
  if (success) {
275
- throw new OAuthProtocolError(
276
- data.error,
277
- data?.error_description ?? "An error occurred while fetching user information."
278
- );
428
+ logger?.log("OAUTH_USERINFO_ERROR", {
429
+ message: "Error response received from OAuth userinfo endpoint",
430
+ structuredData: {
431
+ error: data.error,
432
+ error_description: data.error_description ?? ""
433
+ }
434
+ });
435
+ throw new OAuthProtocolError("INVALID_REQUEST", "An error was received from the OAuth userinfo endpoint.");
279
436
  }
437
+ logger?.log("OAUTH_USERINFO_SUCCESS");
280
438
  return oauthConfig?.profile ? oauthConfig.profile(json) : getDefaultUserInfo(json);
281
439
  } catch (error) {
282
440
  if (isOAuthProtocolError(error)) {
283
441
  throw error;
284
442
  }
443
+ logger?.log("OAUTH_USERINFO_REQUEST_FAILED");
285
444
  if (isNativeError(error)) {
286
- throw new OAuthProtocolError("invalid_request", error.message, "", { cause: error });
445
+ throw new OAuthProtocolError("SERVER_ERROR", "Failed to fetch user information from OAuth provider", "", {
446
+ cause: error
447
+ });
287
448
  }
288
- throw new OAuthProtocolError("invalid_request", "Failed to fetch user information.", "", { cause: error });
449
+ throw new OAuthProtocolError("SERVER_ERROR", "Failed to fetch user information", "", { cause: error });
289
450
  }
290
451
  };
291
452
 
453
+ // src/actions/signIn/authorization.ts
454
+ var getTrustedOrigins = async (request, trustedOrigins) => {
455
+ if (!trustedOrigins) return [];
456
+ const raw = typeof trustedOrigins === "function" ? await trustedOrigins(request) : trustedOrigins;
457
+ return Array.isArray(raw) ? raw : typeof raw === "string" ? [raw] : [];
458
+ };
459
+ var getBaseURL = async ({
460
+ ctx,
461
+ request,
462
+ headers: headersInit
463
+ }) => {
464
+ const origin = getEnv("BASE_URL") || ctx?.baseURL;
465
+ if (origin && origin !== "/") return origin;
466
+ if (ctx?.trustedProxyHeaders) {
467
+ const headers = headersInit && new Headers(headersInit) || request?.headers;
468
+ const protocol = headers?.get("Forwarded")?.match(/proto=([^;]+)/i)?.[1] ?? headers?.get("X-Forwarded-Proto") ?? "http";
469
+ const host = headers?.get("Host") ?? headers?.get("Forwarded")?.match(/host=([^;]+)/i)?.[1] ?? headers?.get("X-Forwarded-Host") ?? null;
470
+ if (host) return `${protocol}://${host}`;
471
+ throw new AuthInternalError(
472
+ "INVALID_OAUTH_CONFIGURATION",
473
+ "The URL cannot be constructed. Please set the BASE_URL environment variable or provide trusted proxy host headers."
474
+ );
475
+ }
476
+ try {
477
+ return new URL(request?.url ?? "not-found").origin;
478
+ } catch (error) {
479
+ throw new AuthInternalError(
480
+ "INVALID_OAUTH_CONFIGURATION",
481
+ "The URL cannot be constructed. Please set the BASE_URL environment variable or enable trustedProxyHeaders.",
482
+ { cause: error }
483
+ );
484
+ }
485
+ };
486
+ var getOriginURL = async (request, context) => {
487
+ const trustedOrigins = await getTrustedOrigins(request, context?.trustedOrigins);
488
+ trustedOrigins.push(new URL(request.url).origin);
489
+ const origin = await getBaseURL({ request, ctx: context });
490
+ if (!isTrustedOrigin(origin, trustedOrigins)) {
491
+ context?.logger?.log("UNTRUSTED_ORIGIN", { structuredData: { origin } });
492
+ throw new AuthInternalError("UNTRUSTED_ORIGIN", "The constructed origin URL is not trusted.");
493
+ }
494
+ return origin;
495
+ };
496
+
292
497
  // src/actions/callback/access-token.ts
293
- var createAccessToken = async (oauthConfig, redirectURI, code, codeVerifier) => {
294
- const parsed = OAuthAccessToken.safeParse({ ...oauthConfig, redirectURI, code, codeVerifier });
295
- if (!parsed.success) {
296
- const msg = JSON.stringify(formatZodError(parsed.error), null, 2);
297
- throw new AuthInternalError("INVALID_OAUTH_CONFIGURATION", msg);
498
+ var createAccessToken = async (oauthConfig, redirectURI, code, codeVerifier, logger) => {
499
+ const { accessToken, clientId, clientSecret } = oauthConfig;
500
+ if (!clientId || !clientSecret || !redirectURI || !code || !codeVerifier || !accessToken) {
501
+ logger?.log("INVALID_OAUTH_CONFIGURATION", {
502
+ structuredData: {
503
+ has_client_id: Boolean(clientId),
504
+ has_client_secret: Boolean(clientSecret),
505
+ has_access_token: Boolean(accessToken),
506
+ has_redirect_uri: Boolean(redirectURI),
507
+ has_code: Boolean(code),
508
+ has_code_verifier: Boolean(codeVerifier)
509
+ }
510
+ });
511
+ throw new AuthInternalError("INVALID_OAUTH_CONFIGURATION", "The OAuth provider configuration is invalid.");
298
512
  }
299
- const { accessToken, clientId, clientSecret, code: codeParsed, redirectURI: redirectParsed } = parsed.data;
513
+ const tokenURL = typeof accessToken === "string" ? accessToken : accessToken.url;
514
+ const extraHeaders = typeof accessToken === "string" ? void 0 : accessToken.headers;
300
515
  try {
301
- const response = await fetchAsync(accessToken, {
516
+ logger?.log("OAUTH_ACCESS_TOKEN_REQUEST_INITIATED", {
517
+ structuredData: {
518
+ has_client_id: Boolean(clientId),
519
+ redirect_uri: redirectURI,
520
+ grant_type: "authorization_code"
521
+ }
522
+ });
523
+ const response = await fetchAsync(tokenURL, {
302
524
  method: "POST",
303
525
  headers: {
526
+ ...extraHeaders ?? {},
304
527
  Accept: "application/json",
305
528
  "Content-Type": "application/x-www-form-urlencoded"
306
529
  },
307
530
  body: new URLSearchParams({
308
531
  client_id: clientId,
309
532
  client_secret: clientSecret,
310
- code: codeParsed,
311
- redirect_uri: redirectParsed,
533
+ code,
534
+ redirect_uri: redirectURI,
312
535
  grant_type: "authorization_code",
313
536
  code_verifier: codeVerifier
314
537
  }).toString()
315
538
  });
539
+ if (!response.ok) {
540
+ logger?.log("INVALID_OAUTH_ACCESS_TOKEN_RESPONSE");
541
+ throw new OAuthProtocolError("invalid_request", "Invalid access token response");
542
+ }
316
543
  const json = await response.json();
317
544
  const token = OAuthAccessTokenResponse.safeParse(json);
318
545
  if (!token.success) {
319
546
  const { success, data } = OAuthAccessTokenErrorResponse.safeParse(json);
320
547
  if (!success) {
321
- throw new OAuthProtocolError("INVALID_REQUEST", "Invalid access token response format");
548
+ logger?.log("INVALID_OAUTH_ACCESS_TOKEN_RESPONSE");
549
+ throw new OAuthProtocolError("invalid_request", "Invalid access token response format");
322
550
  }
323
- throw new OAuthProtocolError(data.error, data?.error_description ?? "Failed to retrieve access token");
551
+ logger?.log("OAUTH_ACCESS_TOKEN_ERROR", {
552
+ structuredData: {
553
+ error: data.error,
554
+ error_description: data.error_description ?? ""
555
+ }
556
+ });
557
+ throw new OAuthProtocolError("INVALID_ACCESS_TOKEN", "Failed to retrieve access token");
324
558
  }
559
+ logger?.log("OAUTH_ACCESS_TOKEN_SUCCESS");
325
560
  return token.data;
326
561
  } catch (error) {
562
+ logger?.log("OAUTH_ACCESS_TOKEN_REQUEST_FAILED");
563
+ if (error instanceof Error) {
564
+ throw new OAuthProtocolError("server_error", "Failed to communicate with OAuth provider", "", { cause: error });
565
+ }
327
566
  throw error;
328
567
  }
329
568
  };
@@ -345,10 +584,11 @@ var oauthCookieOptions = {
345
584
  var expiredCookieAttributes = {
346
585
  ...defaultCookieOptions,
347
586
  expires: /* @__PURE__ */ new Date(0),
348
- maxAge: 0
587
+ maxAge: 0,
588
+ secure: true
349
589
  };
350
590
  var getCookie = (request, cookieName) => {
351
- const cookies = request.headers.get("Cookie");
591
+ const cookies = request instanceof Request ? request.headers.get("Cookie") : request.get("Cookie");
352
592
  if (!cookies) {
353
593
  throw new AuthInternalError("COOKIE_NOT_FOUND", "No cookies found. There is no active session");
354
594
  }
@@ -371,23 +611,36 @@ var createSessionCookie = async (jose, session) => {
371
611
  var callbackConfig = (oauth) => {
372
612
  return (0, import_router2.createEndpointConfig)("/callback/:oauth", {
373
613
  schemas: {
374
- params: import_zod2.z.object({
375
- oauth: import_zod2.z.enum(
614
+ params: import_v42.z.object({
615
+ oauth: import_v42.z.enum(
376
616
  Object.keys(oauth),
377
617
  "The OAuth provider is not supported or invalid."
378
618
  )
379
619
  }),
380
- searchParams: import_zod2.z.object({
381
- code: import_zod2.z.string("Missing code parameter in the OAuth authorization response."),
382
- state: import_zod2.z.string("Missing state parameter in the OAuth authorization response.")
620
+ searchParams: import_v42.z.object({
621
+ code: import_v42.z.string("Missing code parameter in the OAuth authorization response."),
622
+ state: import_v42.z.string("Missing state parameter in the OAuth authorization response.")
383
623
  })
384
624
  },
385
- middlewares: [
625
+ use: [
386
626
  (ctx) => {
387
- const response = OAuthAuthorizationErrorResponse.safeParse(ctx.searchParams);
627
+ const {
628
+ searchParams,
629
+ context: { logger }
630
+ } = ctx;
631
+ const response = OAuthAuthorizationErrorResponse.safeParse(searchParams);
388
632
  if (response.success) {
389
633
  const { error, error_description } = response.data;
390
- throw new OAuthProtocolError(error, error_description ?? "OAuth Authorization Error");
634
+ const criticalAuthErrors = ["access_denied", "server_error"];
635
+ const severity = criticalAuthErrors.includes(error.toLowerCase()) ? "critical" : "warning";
636
+ logger?.log("OAUTH_AUTHORIZATION_ERROR", {
637
+ severity,
638
+ structuredData: {
639
+ error,
640
+ error_description: error_description ?? ""
641
+ }
642
+ });
643
+ throw new OAuthProtocolError(error, error_description || "OAuth Authorization Error");
391
644
  }
392
645
  return ctx;
393
646
  }
@@ -403,31 +656,54 @@ var callbackAction = (oauth) => {
403
656
  request,
404
657
  params: { oauth: oauth2 },
405
658
  searchParams: { code, state },
406
- context: { oauth: providers, cookies, jose }
659
+ context
407
660
  } = ctx;
661
+ const { oauth: providers, cookies, jose, logger, trustedOrigins } = context;
408
662
  const oauthConfig = providers[oauth2];
409
663
  const cookieState = getCookie(request, cookies.state.name);
664
+ const codeVerifier = getCookie(request, cookies.codeVerifier.name);
410
665
  const cookieRedirectTo = getCookie(request, cookies.redirectTo.name);
411
666
  const cookieRedirectURI = getCookie(request, cookies.redirectURI.name);
412
- const codeVerifier = getCookie(request, cookies.codeVerifier.name);
413
- if (!equals(cookieState, state)) {
667
+ if (!timingSafeEqual(cookieState, state)) {
668
+ logger?.log("MISMATCHING_STATE", {
669
+ structuredData: {
670
+ oauth_provider: oauth2
671
+ }
672
+ });
414
673
  throw new AuthSecurityError(
415
674
  "MISMATCHING_STATE",
416
675
  "The provided state passed in the OAuth response does not match the stored state."
417
676
  );
418
677
  }
419
- const accessToken = await createAccessToken(oauthConfig, cookieRedirectURI, code, codeVerifier);
420
- const sanitized = sanitizeURL(cookieRedirectTo);
421
- if (!isValidRelativePath(sanitized)) {
422
- throw new AuthSecurityError(
423
- "POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED",
424
- "Invalid redirect path. Potential open redirect attack detected."
425
- );
678
+ const accessToken = await createAccessToken(oauthConfig, cookieRedirectURI, code, codeVerifier, logger);
679
+ const origins = await getTrustedOrigins(request, trustedOrigins);
680
+ const requestOrigin = await getOriginURL(request, context);
681
+ if (!isRelativeURL(cookieRedirectTo)) {
682
+ const isValid = origins.length > 0 ? isTrustedOrigin(cookieRedirectTo, origins) : isSameOrigin(cookieRedirectTo, requestOrigin);
683
+ if (!isValid) {
684
+ logger?.log("POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED", {
685
+ structuredData: {
686
+ redirect_path: cookieRedirectTo,
687
+ provider: oauth2,
688
+ has_trusted_origins: origins.length > 0,
689
+ request_origin: requestOrigin
690
+ }
691
+ });
692
+ throw new AuthSecurityError(
693
+ "POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED",
694
+ "Invalid redirect path. Potential open redirect attack detected."
695
+ );
696
+ }
426
697
  }
427
- const userInfo = await getUserInfo(oauthConfig, accessToken.access_token);
698
+ const userInfo = await getUserInfo(oauthConfig, accessToken.access_token, logger);
428
699
  const sessionCookie = await createSessionCookie(jose, userInfo);
429
700
  const csrfToken = await createCSRF(jose);
430
- const headers = new import_router2.HeadersBuilder(cacheControl).setHeader("Location", sanitized).setCookie(cookies.sessionToken.name, sessionCookie, cookies.sessionToken.attributes).setCookie(cookies.csrfToken.name, csrfToken, cookies.csrfToken.attributes).setCookie(cookies.state.name, "", expiredCookieAttributes).setCookie(cookies.redirectURI.name, "", expiredCookieAttributes).setCookie(cookies.redirectTo.name, "", expiredCookieAttributes).setCookie(cookies.codeVerifier.name, "", expiredCookieAttributes).toHeaders();
701
+ logger?.log("OAUTH_CALLBACK_SUCCESS", {
702
+ structuredData: {
703
+ provider: oauth2
704
+ }
705
+ });
706
+ const headers = new import_router2.HeadersBuilder(cacheControl).setHeader("Location", cookieRedirectTo).setCookie(cookies.sessionToken.name, sessionCookie, cookies.sessionToken.attributes).setCookie(cookies.csrfToken.name, csrfToken, cookies.csrfToken.attributes).setCookie(cookies.state.name, "", expiredCookieAttributes).setCookie(cookies.redirectURI.name, "", expiredCookieAttributes).setCookie(cookies.redirectTo.name, "", expiredCookieAttributes).setCookie(cookies.codeVerifier.name, "", expiredCookieAttributes).toHeaders();
431
707
  return Response.json({ oauth: oauth2 }, { status: 302, headers });
432
708
  },
433
709
  callbackConfig(oauth)