@aura-stack/auth 0.5.0 → 0.7.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 (220) hide show
  1. package/README.md +36 -1
  2. package/dist/@types/index.cjs +0 -18
  3. package/dist/@types/index.d.ts +2 -12
  4. package/dist/@types/index.js +0 -1
  5. package/dist/assert-_fBNnaOk.js +3 -0
  6. package/dist/assert-hDwQ_SPO.cjs +3 -0
  7. package/dist/client/index.cjs +1 -135
  8. package/dist/client/index.d.ts +11 -14
  9. package/dist/client/index.js +1 -10
  10. package/dist/crypto-D6_SoGMH.cjs +1 -0
  11. package/dist/crypto-DyrRzBSQ.js +1 -0
  12. package/dist/env-7as-tgzO.cjs +1 -0
  13. package/dist/env-CJtSi1eX.js +1 -0
  14. package/dist/errors-Czt_w1t_.js +1 -0
  15. package/dist/errors-DcK2ELlk.cjs +1 -0
  16. package/dist/identity-b8FCr0Oa.cjs +1 -0
  17. package/dist/index-C9U6ICDT.d.ts +2796 -0
  18. package/dist/index.cjs +1 -2427
  19. package/dist/index.d.ts +2 -14
  20. package/dist/index.js +1 -59
  21. package/dist/logger-DjXkgSn5.js +1 -0
  22. package/dist/logger-G5PinyEc.cjs +1 -0
  23. package/dist/oauth/atlassian.cjs +1 -57
  24. package/dist/oauth/atlassian.d.ts +2 -12
  25. package/dist/oauth/atlassian.js +1 -6
  26. package/dist/oauth/bitbucket.cjs +1 -49
  27. package/dist/oauth/bitbucket.d.ts +2 -12
  28. package/dist/oauth/bitbucket.js +1 -6
  29. package/dist/oauth/click-up.cjs +1 -0
  30. package/dist/oauth/click-up.d.ts +2 -0
  31. package/dist/oauth/click-up.js +1 -0
  32. package/dist/oauth/discord.cjs +1 -57
  33. package/dist/oauth/discord.d.ts +2 -12
  34. package/dist/oauth/discord.js +1 -6
  35. package/dist/oauth/dribbble.cjs +1 -0
  36. package/dist/oauth/dribbble.d.ts +2 -0
  37. package/dist/oauth/dribbble.js +1 -0
  38. package/dist/oauth/dropbox.cjs +1 -53
  39. package/dist/oauth/dropbox.d.ts +2 -12
  40. package/dist/oauth/dropbox.js +1 -6
  41. package/dist/oauth/figma.cjs +1 -49
  42. package/dist/oauth/figma.d.ts +2 -12
  43. package/dist/oauth/figma.js +1 -6
  44. package/dist/oauth/github.cjs +1 -49
  45. package/dist/oauth/github.d.ts +2 -12
  46. package/dist/oauth/github.js +1 -6
  47. package/dist/oauth/gitlab.cjs +1 -49
  48. package/dist/oauth/gitlab.d.ts +2 -12
  49. package/dist/oauth/gitlab.js +1 -6
  50. package/dist/oauth/index.cjs +1 -673
  51. package/dist/oauth/index.d.ts +2 -12
  52. package/dist/oauth/index.js +1 -68
  53. package/dist/oauth/mailchimp.cjs +1 -49
  54. package/dist/oauth/mailchimp.d.ts +2 -12
  55. package/dist/oauth/mailchimp.js +1 -6
  56. package/dist/oauth/notion.cjs +1 -131
  57. package/dist/oauth/notion.d.ts +2 -12
  58. package/dist/oauth/notion.js +1 -9
  59. package/dist/oauth/pinterest.cjs +1 -49
  60. package/dist/oauth/pinterest.d.ts +2 -12
  61. package/dist/oauth/pinterest.js +1 -6
  62. package/dist/oauth/spotify.cjs +1 -49
  63. package/dist/oauth/spotify.d.ts +2 -12
  64. package/dist/oauth/spotify.js +1 -6
  65. package/dist/oauth/strava.cjs +1 -49
  66. package/dist/oauth/strava.d.ts +2 -12
  67. package/dist/oauth/strava.js +1 -6
  68. package/dist/oauth/twitch.cjs +1 -95
  69. package/dist/oauth/twitch.d.ts +2 -12
  70. package/dist/oauth/twitch.js +1 -7
  71. package/dist/oauth/x.cjs +1 -49
  72. package/dist/oauth/x.d.ts +2 -12
  73. package/dist/oauth/x.js +1 -6
  74. package/dist/oauth-D3_mnBOx.js +1 -0
  75. package/dist/oauth-gPiWxjBd.cjs +1 -0
  76. package/dist/shared/crypto.cjs +1 -0
  77. package/dist/shared/crypto.d.ts +71 -0
  78. package/dist/shared/crypto.js +1 -0
  79. package/dist/shared/identity.cjs +1 -0
  80. package/dist/shared/identity.d.ts +2 -0
  81. package/dist/shared/identity.js +1 -0
  82. package/dist/shared/index.cjs +1 -0
  83. package/dist/shared/index.d.ts +5 -0
  84. package/dist/shared/index.js +1 -0
  85. package/package.json +37 -11
  86. package/dist/@types/router.d.cjs +0 -1
  87. package/dist/@types/router.d.d.ts +0 -16
  88. package/dist/@types/router.d.js +0 -0
  89. package/dist/@types/utility.cjs +0 -18
  90. package/dist/@types/utility.d.ts +0 -6
  91. package/dist/@types/utility.js +0 -1
  92. package/dist/actions/callback/access-token.cjs +0 -250
  93. package/dist/actions/callback/access-token.d.ts +0 -33
  94. package/dist/actions/callback/access-token.js +0 -9
  95. package/dist/actions/callback/callback.cjs +0 -715
  96. package/dist/actions/callback/callback.d.ts +0 -42
  97. package/dist/actions/callback/callback.js +0 -18
  98. package/dist/actions/callback/userinfo.cjs +0 -283
  99. package/dist/actions/callback/userinfo.d.ts +0 -25
  100. package/dist/actions/callback/userinfo.js +0 -13
  101. package/dist/actions/csrfToken/csrfToken.cjs +0 -189
  102. package/dist/actions/csrfToken/csrfToken.d.ts +0 -7
  103. package/dist/actions/csrfToken/csrfToken.js +0 -13
  104. package/dist/actions/index.cjs +0 -1161
  105. package/dist/actions/index.d.ts +0 -17
  106. package/dist/actions/index.js +0 -39
  107. package/dist/actions/session/session.cjs +0 -188
  108. package/dist/actions/session/session.d.ts +0 -7
  109. package/dist/actions/session/session.js +0 -12
  110. package/dist/actions/signIn/authorization-url.cjs +0 -288
  111. package/dist/actions/signIn/authorization-url.d.ts +0 -31
  112. package/dist/actions/signIn/authorization-url.js +0 -16
  113. package/dist/actions/signIn/authorization.cjs +0 -281
  114. package/dist/actions/signIn/authorization.d.ts +0 -54
  115. package/dist/actions/signIn/authorization.js +0 -19
  116. package/dist/actions/signIn/signIn.cjs +0 -595
  117. package/dist/actions/signIn/signIn.d.ts +0 -42
  118. package/dist/actions/signIn/signIn.js +0 -16
  119. package/dist/actions/signOut/signOut.cjs +0 -492
  120. package/dist/actions/signOut/signOut.d.ts +0 -16
  121. package/dist/actions/signOut/signOut.js +0 -15
  122. package/dist/api/createApi.cjs +0 -750
  123. package/dist/api/createApi.d.ts +0 -12
  124. package/dist/api/createApi.js +0 -19
  125. package/dist/api/getSession.cjs +0 -141
  126. package/dist/api/getSession.d.ts +0 -16
  127. package/dist/api/getSession.js +0 -10
  128. package/dist/api/signIn.cjs +0 -549
  129. package/dist/api/signIn.d.ts +0 -26
  130. package/dist/api/signIn.js +0 -15
  131. package/dist/api/signOut.cjs +0 -279
  132. package/dist/api/signOut.d.ts +0 -16
  133. package/dist/api/signOut.js +0 -13
  134. package/dist/assert.cjs +0 -194
  135. package/dist/assert.d.ts +0 -37
  136. package/dist/assert.js +0 -26
  137. package/dist/chunk-2A5B7GWR.js +0 -125
  138. package/dist/chunk-2GQLSIJ2.js +0 -40
  139. package/dist/chunk-2IR674WX.js +0 -44
  140. package/dist/chunk-3J5TUH2I.js +0 -50
  141. package/dist/chunk-4RWSYUKX.js +0 -98
  142. package/dist/chunk-4YHJ4IEQ.js +0 -25
  143. package/dist/chunk-54CZPKR4.js +0 -25
  144. package/dist/chunk-5LZ7TOM3.js +0 -25
  145. package/dist/chunk-5X7JZMEF.js +0 -0
  146. package/dist/chunk-7BE46WWS.js +0 -88
  147. package/dist/chunk-7YYXFKLR.js +0 -35
  148. package/dist/chunk-C3A37LQC.js +0 -33
  149. package/dist/chunk-CITNGXDA.js +0 -31
  150. package/dist/chunk-CWX724AG.js +0 -78
  151. package/dist/chunk-D2CSIUKP.js +0 -74
  152. package/dist/chunk-E6G5YCI6.js +0 -25
  153. package/dist/chunk-EBAMFRB7.js +0 -34
  154. package/dist/chunk-EEE7UM5T.js +0 -25
  155. package/dist/chunk-FPCVZUVG.js +0 -37
  156. package/dist/chunk-FW4W3REU.js +0 -25
  157. package/dist/chunk-GNNBM2WJ.js +0 -83
  158. package/dist/chunk-IPKO6UQN.js +0 -25
  159. package/dist/chunk-ITQ7352M.js +0 -0
  160. package/dist/chunk-JOCGX3RP.js +0 -59
  161. package/dist/chunk-KBXWTD6E.js +0 -94
  162. package/dist/chunk-KMMAZFSJ.js +0 -25
  163. package/dist/chunk-LATR3NIV.js +0 -117
  164. package/dist/chunk-LAYPUDQF.js +0 -39
  165. package/dist/chunk-LDU7A2JE.js +0 -25
  166. package/dist/chunk-LX3TJ2TJ.js +0 -294
  167. package/dist/chunk-NHZBQNRR.js +0 -143
  168. package/dist/chunk-OVHNRULD.js +0 -33
  169. package/dist/chunk-PDP3PHB3.js +0 -127
  170. package/dist/chunk-PG7UYFG5.js +0 -0
  171. package/dist/chunk-PHYNROD4.js +0 -47
  172. package/dist/chunk-QQEKY4XP.js +0 -29
  173. package/dist/chunk-U4RK4LKJ.js +0 -348
  174. package/dist/chunk-U5663F2U.js +0 -70
  175. package/dist/chunk-UN7X6SU5.js +0 -53
  176. package/dist/chunk-UZQJJD6A.js +0 -100
  177. package/dist/chunk-V6LLEAR4.js +0 -80
  178. package/dist/chunk-WHNDRO3N.js +0 -50
  179. package/dist/chunk-XY5R3EHH.js +0 -204
  180. package/dist/chunk-ZNCZVF6U.js +0 -14
  181. package/dist/client/client.cjs +0 -135
  182. package/dist/client/client.d.ts +0 -85
  183. package/dist/client/client.js +0 -9
  184. package/dist/context.cjs +0 -1237
  185. package/dist/context.d.ts +0 -16
  186. package/dist/context.js +0 -28
  187. package/dist/cookie.cjs +0 -277
  188. package/dist/cookie.d.ts +0 -89
  189. package/dist/cookie.js +0 -30
  190. package/dist/createAuth.cjs +0 -2320
  191. package/dist/createAuth.d.ts +0 -12
  192. package/dist/createAuth.js +0 -48
  193. package/dist/env.cjs +0 -78
  194. package/dist/env.d.ts +0 -10
  195. package/dist/env.js +0 -12
  196. package/dist/errors.cjs +0 -102
  197. package/dist/errors.d.ts +0 -60
  198. package/dist/errors.js +0 -22
  199. package/dist/headers.cjs +0 -61
  200. package/dist/headers.d.ts +0 -33
  201. package/dist/headers.js +0 -12
  202. package/dist/index-_aXtxb_s.d.ts +0 -1377
  203. package/dist/jose.cjs +0 -166
  204. package/dist/jose.d.ts +0 -12
  205. package/dist/jose.js +0 -20
  206. package/dist/logger.cjs +0 -424
  207. package/dist/logger.d.ts +0 -12
  208. package/dist/logger.js +0 -17
  209. package/dist/request.cjs +0 -38
  210. package/dist/request.d.ts +0 -13
  211. package/dist/request.js +0 -6
  212. package/dist/schemas.cjs +0 -158
  213. package/dist/schemas.d.ts +0 -229
  214. package/dist/schemas.js +0 -24
  215. package/dist/secure.cjs +0 -170
  216. package/dist/secure.d.ts +0 -41
  217. package/dist/secure.js +0 -20
  218. package/dist/utils.cjs +0 -329
  219. package/dist/utils.d.ts +0 -35
  220. package/dist/utils.js +0 -36
@@ -1,492 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/actions/signOut/signOut.ts
21
- var signOut_exports = {};
22
- __export(signOut_exports, {
23
- signOutAction: () => signOutAction
24
- });
25
- module.exports = __toCommonJS(signOut_exports);
26
- var import_v4 = require("zod/v4");
27
- var import_router3 = require("@aura-stack/router");
28
-
29
- // src/utils.ts
30
- var import_router = require("@aura-stack/router");
31
-
32
- // src/errors.ts
33
- var AuthInternalError = class extends Error {
34
- type = "AUTH_INTERNAL_ERROR";
35
- code;
36
- constructor(code, message, options) {
37
- super(message, options);
38
- this.code = code;
39
- this.name = new.target.name;
40
- Error.captureStackTrace(this, new.target);
41
- }
42
- };
43
- var AuthSecurityError = class extends Error {
44
- type = "AUTH_SECURITY_ERROR";
45
- code;
46
- constructor(code, message, options) {
47
- super(message, options);
48
- this.code = code;
49
- this.name = new.target.name;
50
- Error.captureStackTrace(this, new.target);
51
- }
52
- };
53
-
54
- // src/env.ts
55
- var import_meta = {};
56
- var env = new Proxy({}, {
57
- get(_, prop) {
58
- if (typeof prop !== "string") return void 0;
59
- const hasProperty = (process2) => {
60
- return process2 && Object.prototype.hasOwnProperty.call(process2, prop);
61
- };
62
- try {
63
- if (typeof process !== "undefined" && hasProperty(process.env)) {
64
- return process.env[prop];
65
- }
66
- if (typeof import_meta !== "undefined" && hasProperty(import_meta.env)) {
67
- return import_meta.env[prop];
68
- }
69
- if (typeof Deno !== "undefined" && Deno.env?.get) {
70
- return Deno.env.get(prop);
71
- }
72
- if (typeof Bun !== "undefined" && hasProperty(Bun.env)) {
73
- return Bun.env[prop];
74
- }
75
- const globalValue = globalThis[prop];
76
- return typeof globalValue === "string" ? globalValue : void 0;
77
- } catch {
78
- return void 0;
79
- }
80
- }
81
- });
82
- var getEnv = (key) => {
83
- const keys = [`AURA_AUTH_${key.toUpperCase()}`, `AURA_${key.toUpperCase()}`, `AUTH_${key.toUpperCase()}`, key.toUpperCase()];
84
- return env[keys.find((k) => env[k]) ?? ""];
85
- };
86
-
87
- // src/assert.ts
88
- var import_crypto = require("@aura-stack/jose/crypto");
89
- var unsafeChars = [
90
- "<",
91
- ">",
92
- '"',
93
- "`",
94
- " ",
95
- "\r",
96
- "\n",
97
- " ",
98
- "\\",
99
- "%2F",
100
- "%5C",
101
- "%2f",
102
- "%5c",
103
- "\r\n",
104
- "%0A",
105
- "%0D",
106
- "%0a",
107
- "%0d",
108
- "..",
109
- "//",
110
- "///",
111
- "...",
112
- "%20",
113
- "\0"
114
- ];
115
- var isValidURL = (value) => {
116
- if (!new RegExp(/^https?:\/\/[^/]/).test(value)) {
117
- return false;
118
- }
119
- const match = value.match(/^(https?:\/\/)(.*)$/);
120
- if (!match) return false;
121
- const rest = match[2];
122
- for (const char of unsafeChars) {
123
- if (rest.includes(char)) return false;
124
- }
125
- const regex = /^https?:\/\/(?:[a-zA-Z0-9._-]+|localhost|\[[0-9a-fA-F:]+\])(?::\d{1,5})?(?:\/[a-zA-Z0-9._~!$&'()?#*+,;=:@-]*)*\/?$/;
126
- return regex.test(match[0]);
127
- };
128
- var isJWTPayloadWithToken = (payload) => {
129
- return typeof payload === "object" && payload !== null && "token" in payload && typeof payload?.token === "string";
130
- };
131
- var isRelativeURL = (value) => {
132
- if (value.length > 100) return false;
133
- for (const char of unsafeChars) {
134
- if (value.includes(char)) return false;
135
- }
136
- const regex = /^\/[a-zA-Z0-9\-_\/.?&=#]*\/?$/;
137
- return regex.test(value);
138
- };
139
- var isSameOrigin = (origin, expected) => {
140
- const originURL = new URL(origin);
141
- const expectedURL = new URL(expected);
142
- return equals(originURL.origin, expectedURL.origin);
143
- };
144
- var patternToRegex = (pattern) => {
145
- try {
146
- if (pattern.length > 2048) return null;
147
- pattern = pattern.replace(/\\/g, "");
148
- const match = pattern.match(/^(https?):\/\/([a-zA-Z0-9.*-]{1,253})(?::(\d{1,5}|\*))?(?:\/.*)?$/);
149
- if (!match) return null;
150
- const [, protocol, host, port] = match;
151
- const hasWildcard = host.includes("*");
152
- if (hasWildcard && !host.startsWith("*.")) return null;
153
- if (hasWildcard && host.slice(2).includes("*")) return null;
154
- const domain = hasWildcard ? host.slice(2) : host;
155
- const escapedDomain = domain.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
156
- const hostRegex = hasWildcard ? `[^.]+\\.${escapedDomain}` : escapedDomain;
157
- const portRegex = port === "*" ? ":\\d{1,5}" : port ? `:${port}` : "";
158
- return new RegExp(`^${protocol}:\\/\\/${hostRegex}${portRegex}$`);
159
- } catch {
160
- return null;
161
- }
162
- };
163
- var isTrustedOrigin = (url, trustedOrigins) => {
164
- if (!isValidURL(url) || trustedOrigins.length === 0) return false;
165
- try {
166
- const urlOrigin = new URL(url).origin;
167
- for (const pattern of trustedOrigins) {
168
- const regex = patternToRegex(pattern);
169
- if (regex?.test(urlOrigin)) return true;
170
- try {
171
- if (isValidURL(pattern) && equals(new URL(pattern).origin, urlOrigin)) return true;
172
- } catch {
173
- }
174
- }
175
- } catch {
176
- }
177
- return false;
178
- };
179
- var timingSafeEqual = (a, b) => {
180
- const bufferA = import_crypto.encoder.encode(a);
181
- const bufferB = import_crypto.encoder.encode(b);
182
- const len = Math.max(bufferA.length, bufferB.length);
183
- let diff = 0;
184
- for (let i = 0; i < len; i++) {
185
- diff |= (bufferA[i] ?? 0) ^ (bufferB[i] ?? 0);
186
- }
187
- return diff === 0 && bufferA.length === bufferB.length;
188
- };
189
-
190
- // src/utils.ts
191
- var equals = (a, b) => {
192
- if (a === null || b === null || a === void 0 || b === void 0) return false;
193
- return a === b;
194
- };
195
- var getBaseURL = (request) => {
196
- const url = new URL(request.url);
197
- return `${url.origin}${url.pathname}`;
198
- };
199
- var extractPath = (url) => {
200
- const pathRegex = /^https?:\/\/[a-zA-Z0-9_\-\.]+(:\d+)?(\/.*)$/;
201
- const match = url.match(pathRegex);
202
- return match && match[2] ? match[2] : "/";
203
- };
204
- var getErrorName = (error) => {
205
- if (error instanceof Error) {
206
- return error.name;
207
- }
208
- return typeof error === "string" ? error : "UnknownError";
209
- };
210
-
211
- // src/cookie.ts
212
- var import_cookie = require("@aura-stack/router/cookie");
213
- var defaultCookieOptions = {
214
- httpOnly: true,
215
- sameSite: "lax",
216
- path: "/",
217
- maxAge: 60 * 60 * 24 * 15
218
- };
219
- var oauthCookieOptions = {
220
- httpOnly: true,
221
- maxAge: 5 * 60,
222
- sameSite: "lax",
223
- expires: new Date(Date.now() + 5 * 60 * 1e3)
224
- };
225
- var expiredCookieAttributes = {
226
- ...defaultCookieOptions,
227
- expires: /* @__PURE__ */ new Date(0),
228
- maxAge: 0,
229
- secure: true
230
- };
231
- var getCookie = (request, cookieName) => {
232
- const cookies = request instanceof Request ? request.headers.get("Cookie") : request.get("Cookie");
233
- if (!cookies) {
234
- throw new AuthInternalError("COOKIE_NOT_FOUND", "No cookies found. There is no active session");
235
- }
236
- const value = (0, import_cookie.parse)(cookies)[cookieName];
237
- if (!value) {
238
- throw new AuthInternalError("COOKIE_NOT_FOUND", `Cookie "${cookieName}" not found. There is no active session`);
239
- }
240
- return value;
241
- };
242
-
243
- // src/jose.ts
244
- var import_jose = require("@aura-stack/jose");
245
- var import_jose2 = require("@aura-stack/jose/jose");
246
- var import_crypto2 = require("@aura-stack/jose/crypto");
247
- var jwtVerificationOptions = {
248
- algorithms: ["HS256"],
249
- typ: "JWT"
250
- };
251
-
252
- // src/secure.ts
253
- var verifyCSRF = async (jose, cookie, header) => {
254
- try {
255
- const cookiePayload = await jose.verifyJWS(cookie, jwtVerificationOptions);
256
- const headerPayload = await jose.verifyJWS(header, jwtVerificationOptions);
257
- if (!isJWTPayloadWithToken(cookiePayload)) {
258
- throw new AuthSecurityError("CSRF_TOKEN_INVALID", "Cookie payload missing token field.");
259
- }
260
- if (!isJWTPayloadWithToken(headerPayload)) {
261
- throw new AuthSecurityError("CSRF_TOKEN_INVALID", "Header payload missing token field.");
262
- }
263
- if (!equals(cookiePayload.token.length, headerPayload.token.length)) {
264
- throw new AuthSecurityError("CSRF_TOKEN_INVALID", "The CSRF tokens do not match.");
265
- }
266
- if (!timingSafeEqual(cookiePayload.token, headerPayload.token)) {
267
- throw new AuthSecurityError("CSRF_TOKEN_INVALID", "The CSRF tokens do not match.");
268
- }
269
- return true;
270
- } catch {
271
- throw new AuthSecurityError("CSRF_TOKEN_INVALID", "The CSRF tokens do not match.");
272
- }
273
- };
274
-
275
- // src/headers.ts
276
- var cacheControl = {
277
- "Cache-Control": "no-store",
278
- Pragma: "no-cache",
279
- Expires: "0",
280
- Vary: "Cookie"
281
- };
282
- var contentSecurityPolicy = {
283
- "Content-Security-Policy": [
284
- "default-src 'none'",
285
- "script-src 'self'",
286
- "frame-src 'none'",
287
- "object-src 'none'",
288
- "frame-ancestors 'none'",
289
- "base-uri 'none'"
290
- ].join("; ")
291
- };
292
- var secureHeaders = {
293
- "X-Content-Type-Options": "nosniff",
294
- "X-Frame-Options": "DENY",
295
- "Referrer-Policy": "strict-origin-when-cross-origin"
296
- };
297
- var secureApiHeaders = {
298
- ...cacheControl,
299
- ...contentSecurityPolicy,
300
- ...secureHeaders
301
- };
302
-
303
- // src/api/signOut.ts
304
- var import_router2 = require("@aura-stack/router");
305
- var signOut = async ({
306
- ctx,
307
- headers: headersInit,
308
- redirectTo = "/",
309
- skipCSRFCheck = false
310
- }) => {
311
- const headers = new Headers(headersInit);
312
- const header = headers.get("X-CSRF-Token");
313
- let session = null;
314
- let csrfToken = null;
315
- try {
316
- session = getCookie(headers, ctx.cookies.sessionToken.name);
317
- } catch {
318
- throw new AuthSecurityError("SESSION_TOKEN_MISSING", "The sessionToken is missing.");
319
- }
320
- try {
321
- csrfToken = getCookie(headers, ctx.cookies.csrfToken.name);
322
- } catch {
323
- throw new AuthSecurityError("CSRF_TOKEN_MISSING", "The CSRF token is missing.");
324
- }
325
- ctx?.logger?.log("SIGN_OUT_ATTEMPT", {
326
- structuredData: {
327
- has_session: Boolean(session),
328
- has_csrf_token: Boolean(csrfToken),
329
- has_csrf_header: Boolean(header),
330
- skip_csrf_check: skipCSRFCheck
331
- }
332
- });
333
- if (!session) {
334
- ctx?.logger?.log("SESSION_TOKEN_MISSING");
335
- throw new AuthSecurityError("SESSION_TOKEN_MISSING", "The sessionToken is missing.");
336
- }
337
- if (!skipCSRFCheck) {
338
- if (!csrfToken) {
339
- ctx?.logger?.log("CSRF_TOKEN_MISSING");
340
- throw new AuthSecurityError("CSRF_TOKEN_MISSING", "The CSRF token is missing.");
341
- }
342
- if (!header) {
343
- ctx?.logger?.log("CSRF_HEADER_MISSING");
344
- throw new AuthSecurityError("CSRF_HEADER_MISSING", "The CSRF header is missing.");
345
- }
346
- try {
347
- await verifyCSRF(ctx.jose, csrfToken, header);
348
- } catch (error) {
349
- ctx?.logger?.log("CSRF_TOKEN_INVALID", { structuredData: { error_type: getErrorName(error) } });
350
- throw new AuthSecurityError("CSRF_TOKEN_INVALID", "CSRF token verification failed");
351
- }
352
- ctx?.logger?.log("SIGN_OUT_CSRF_VERIFIED");
353
- } else {
354
- try {
355
- await ctx.jose.verifyJWS(csrfToken);
356
- } catch (error) {
357
- ctx?.logger?.log("CSRF_TOKEN_INVALID", { structuredData: { error_type: getErrorName(error) } });
358
- throw new AuthSecurityError("CSRF_TOKEN_INVALID", "CSRF token verification failed");
359
- }
360
- }
361
- try {
362
- await ctx.jose.decodeJWT(session);
363
- ctx?.logger?.log("SIGN_OUT_SUCCESS");
364
- } catch (error) {
365
- ctx?.logger?.log("INVALID_JWT_TOKEN", { structuredData: { error_type: getErrorName(error) } });
366
- }
367
- const headersList = new import_router2.HeadersBuilder(secureApiHeaders).setHeader("Location", redirectTo).setCookie(ctx.cookies.csrfToken.name, "", expiredCookieAttributes).setCookie(ctx.cookies.sessionToken.name, "", expiredCookieAttributes).toHeaders();
368
- return Response.json(
369
- { redirect: Boolean(redirectTo), url: redirectTo },
370
- {
371
- status: 202,
372
- headers: headersList
373
- }
374
- );
375
- };
376
-
377
- // src/actions/signIn/authorization.ts
378
- var getTrustedOrigins = async (request, trustedOrigins) => {
379
- if (!trustedOrigins) return [];
380
- const raw = typeof trustedOrigins === "function" ? await trustedOrigins(request) : trustedOrigins;
381
- return Array.isArray(raw) ? raw : typeof raw === "string" ? [raw] : [];
382
- };
383
- var getBaseURL2 = async ({
384
- ctx,
385
- request,
386
- headers: headersInit
387
- }) => {
388
- const origin = getEnv("BASE_URL") || ctx?.baseURL;
389
- if (origin && origin !== "/") return origin;
390
- if (ctx?.trustedProxyHeaders) {
391
- const headers = headersInit && new Headers(headersInit) || request?.headers;
392
- const protocol = headers?.get("Forwarded")?.match(/proto=([^;]+)/i)?.[1] ?? headers?.get("X-Forwarded-Proto") ?? "http";
393
- const host = headers?.get("Host") ?? headers?.get("Forwarded")?.match(/host=([^;]+)/i)?.[1] ?? headers?.get("X-Forwarded-Host") ?? null;
394
- if (host) return `${protocol}://${host}`;
395
- throw new AuthInternalError(
396
- "INVALID_OAUTH_CONFIGURATION",
397
- "The URL cannot be constructed. Please set the BASE_URL environment variable or provide trusted proxy host headers."
398
- );
399
- }
400
- try {
401
- return new URL(request?.url ?? "not-found").origin;
402
- } catch (error) {
403
- throw new AuthInternalError(
404
- "INVALID_OAUTH_CONFIGURATION",
405
- "The URL cannot be constructed. Please set the BASE_URL environment variable or enable trustedProxyHeaders.",
406
- { cause: error }
407
- );
408
- }
409
- };
410
- var getOriginURL = async (request, context) => {
411
- const trustedOrigins = await getTrustedOrigins(request, context?.trustedOrigins);
412
- trustedOrigins.push(new URL(request.url).origin);
413
- const origin = await getBaseURL2({ request, ctx: context });
414
- if (!isTrustedOrigin(origin, trustedOrigins)) {
415
- context?.logger?.log("UNTRUSTED_ORIGIN", { structuredData: { origin } });
416
- throw new AuthInternalError("UNTRUSTED_ORIGIN", "The constructed origin URL is not trusted.");
417
- }
418
- return origin;
419
- };
420
- var createRedirectTo = async (request, redirectTo, context) => {
421
- try {
422
- const headers = request.headers;
423
- const requestOrigin = await getOriginURL(request, context);
424
- const origins = await getTrustedOrigins(request, context?.trustedOrigins);
425
- const validateURL = (url) => {
426
- if (!isRelativeURL(url) && !isValidURL(url)) return "/";
427
- if (isRelativeURL(url)) return url;
428
- if (origins.length > 0) {
429
- if (isTrustedOrigin(url, origins)) {
430
- const urlOrigin = new URL(url).origin;
431
- for (const pattern of origins) {
432
- const regex = patternToRegex(pattern);
433
- if (regex?.test(urlOrigin)) {
434
- return isSameOrigin(url, request.url) ? extractPath(url) : url;
435
- }
436
- if (isValidURL(pattern) && equals(new URL(pattern).origin, urlOrigin)) return url;
437
- }
438
- }
439
- context?.logger?.log("OPEN_REDIRECT_ATTACK");
440
- return "/";
441
- }
442
- if (isSameOrigin(url, requestOrigin)) {
443
- return extractPath(url);
444
- }
445
- context?.logger?.log("OPEN_REDIRECT_ATTACK");
446
- return "/";
447
- };
448
- return validateURL(redirectTo ?? headers.get("Referer") ?? headers.get("Origin") ?? "/");
449
- } catch (error) {
450
- context?.logger?.log("POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED");
451
- return "/";
452
- }
453
- };
454
-
455
- // src/actions/signOut/signOut.ts
456
- var config = (0, import_router3.createEndpointConfig)({
457
- schemas: {
458
- searchParams: import_v4.z.object({
459
- token_type_hint: import_v4.z.literal("session_token"),
460
- redirectTo: import_v4.z.string().optional()
461
- })
462
- }
463
- });
464
- var signOutAction = (0, import_router3.createEndpoint)(
465
- "POST",
466
- "/signOut",
467
- async (ctx) => {
468
- const {
469
- request,
470
- searchParams: { redirectTo },
471
- context
472
- } = ctx;
473
- const baseURL = getBaseURL(request);
474
- const location = await createRedirectTo(
475
- new Request(baseURL, {
476
- headers: request.headers
477
- }),
478
- redirectTo,
479
- context
480
- );
481
- return await signOut({
482
- ctx: context,
483
- headers: request.headers,
484
- redirectTo: location
485
- });
486
- },
487
- config
488
- );
489
- // Annotate the CommonJS export names for ESM import in node:
490
- 0 && (module.exports = {
491
- signOutAction
492
- });
@@ -1,16 +0,0 @@
1
- import * as _aura_stack_router from '@aura-stack/router';
2
- import { z } from 'zod/v4';
3
-
4
- /**
5
- * @see https://datatracker.ietf.org/doc/html/rfc7009
6
- */
7
- declare const signOutAction: _aura_stack_router.RouteEndpoint<"POST", "/signOut", {
8
- schemas?: {
9
- searchParams: z.ZodObject<{
10
- token_type_hint: z.ZodLiteral<"session_token">;
11
- redirectTo: z.ZodOptional<z.ZodString>;
12
- }, z.core.$strip>;
13
- } | undefined;
14
- }>;
15
-
16
- export { signOutAction };
@@ -1,15 +0,0 @@
1
- import {
2
- signOutAction
3
- } from "../../chunk-3J5TUH2I.js";
4
- import "../../chunk-LATR3NIV.js";
5
- import "../../chunk-KBXWTD6E.js";
6
- import "../../chunk-V6LLEAR4.js";
7
- import "../../chunk-UZQJJD6A.js";
8
- import "../../chunk-LX3TJ2TJ.js";
9
- import "../../chunk-XY5R3EHH.js";
10
- import "../../chunk-WHNDRO3N.js";
11
- import "../../chunk-U5663F2U.js";
12
- import "../../chunk-EBAMFRB7.js";
13
- export {
14
- signOutAction
15
- };