@aura-stack/auth 0.4.0 → 0.6.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 (179) hide show
  1. package/README.md +36 -1
  2. package/dist/@types/index.cjs +0 -18
  3. package/dist/@types/index.d.ts +2 -8
  4. package/dist/@types/index.js +0 -1
  5. package/dist/assert-B3iQSYlK.js +3 -0
  6. package/dist/assert-NJGroSJd.cjs +3 -0
  7. package/dist/client/index.cjs +1 -0
  8. package/dist/client/index.d.ts +11 -0
  9. package/dist/client/index.js +1 -0
  10. package/dist/crypto-Bz8nIciY.js +1 -0
  11. package/dist/crypto-CoXA5w_4.cjs +1 -0
  12. package/dist/env-bq387KyP.cjs +1 -0
  13. package/dist/env-nvh8QBNz.js +1 -0
  14. package/dist/errors-CCYPHuBO.cjs +1 -0
  15. package/dist/errors-DFWHOho6.js +1 -0
  16. package/dist/index-BkpwQ0l4.d.cts +2279 -0
  17. package/dist/index-nqLV2t91.d.ts +2279 -0
  18. package/dist/index.cjs +1 -1839
  19. package/dist/index.d.cts +2 -0
  20. package/dist/index.d.ts +2 -35
  21. package/dist/index.js +1 -132
  22. package/dist/logger-C59_CDMk.js +1 -0
  23. package/dist/logger-UnUhYL2V.cjs +1 -0
  24. package/dist/oauth/atlassian.cjs +1 -0
  25. package/dist/oauth/atlassian.d.ts +2 -0
  26. package/dist/oauth/atlassian.js +1 -0
  27. package/dist/oauth/bitbucket.cjs +1 -49
  28. package/dist/oauth/bitbucket.d.ts +2 -8
  29. package/dist/oauth/bitbucket.js +1 -6
  30. package/dist/oauth/discord.cjs +1 -57
  31. package/dist/oauth/discord.d.ts +2 -8
  32. package/dist/oauth/discord.js +1 -6
  33. package/dist/oauth/dropbox.cjs +1 -0
  34. package/dist/oauth/dropbox.d.ts +2 -0
  35. package/dist/oauth/dropbox.js +1 -0
  36. package/dist/oauth/figma.cjs +1 -49
  37. package/dist/oauth/figma.d.ts +2 -8
  38. package/dist/oauth/figma.js +1 -6
  39. package/dist/oauth/github.cjs +1 -49
  40. package/dist/oauth/github.d.ts +2 -8
  41. package/dist/oauth/github.js +1 -6
  42. package/dist/oauth/gitlab.cjs +1 -49
  43. package/dist/oauth/gitlab.d.ts +2 -8
  44. package/dist/oauth/gitlab.js +1 -6
  45. package/dist/oauth/index.cjs +1 -483
  46. package/dist/oauth/index.d.ts +2 -8
  47. package/dist/oauth/index.js +1 -52
  48. package/dist/oauth/mailchimp.cjs +1 -49
  49. package/dist/oauth/mailchimp.d.ts +2 -8
  50. package/dist/oauth/mailchimp.js +1 -6
  51. package/dist/oauth/notion.cjs +1 -0
  52. package/dist/oauth/notion.d.ts +2 -0
  53. package/dist/oauth/notion.js +1 -0
  54. package/dist/oauth/pinterest.cjs +1 -49
  55. package/dist/oauth/pinterest.d.ts +2 -8
  56. package/dist/oauth/pinterest.js +1 -6
  57. package/dist/oauth/spotify.cjs +1 -49
  58. package/dist/oauth/spotify.d.ts +2 -8
  59. package/dist/oauth/spotify.js +1 -6
  60. package/dist/oauth/strava.cjs +1 -49
  61. package/dist/oauth/strava.d.ts +2 -8
  62. package/dist/oauth/strava.js +1 -6
  63. package/dist/oauth/twitch.cjs +1 -0
  64. package/dist/oauth/twitch.d.ts +2 -0
  65. package/dist/oauth/twitch.js +1 -0
  66. package/dist/oauth/x.cjs +1 -49
  67. package/dist/oauth/x.d.ts +2 -8
  68. package/dist/oauth/x.js +1 -6
  69. package/dist/oauth-BntNm6aE.cjs +1 -0
  70. package/dist/oauth-DmHy9VrB.js +1 -0
  71. package/dist/shared/crypto.cjs +1 -0
  72. package/dist/shared/crypto.d.ts +47 -0
  73. package/dist/shared/crypto.js +1 -0
  74. package/dist/shared/identity.cjs +1 -0
  75. package/dist/shared/identity.d.ts +2 -0
  76. package/dist/shared/identity.js +1 -0
  77. package/dist/shared/index.cjs +1 -0
  78. package/dist/shared/index.d.ts +5 -0
  79. package/dist/shared/index.js +1 -0
  80. package/package.json +39 -12
  81. package/dist/@types/router.d.cjs +0 -1
  82. package/dist/@types/router.d.d.ts +0 -12
  83. package/dist/@types/router.d.js +0 -0
  84. package/dist/@types/utility.cjs +0 -18
  85. package/dist/@types/utility.d.ts +0 -6
  86. package/dist/@types/utility.js +0 -1
  87. package/dist/actions/callback/access-token.cjs +0 -206
  88. package/dist/actions/callback/access-token.d.ts +0 -29
  89. package/dist/actions/callback/access-token.js +0 -9
  90. package/dist/actions/callback/callback.cjs +0 -649
  91. package/dist/actions/callback/callback.d.ts +0 -13
  92. package/dist/actions/callback/callback.js +0 -19
  93. package/dist/actions/callback/userinfo.cjs +0 -250
  94. package/dist/actions/callback/userinfo.d.ts +0 -21
  95. package/dist/actions/callback/userinfo.js +0 -14
  96. package/dist/actions/csrfToken/csrfToken.cjs +0 -197
  97. package/dist/actions/csrfToken/csrfToken.d.ts +0 -5
  98. package/dist/actions/csrfToken/csrfToken.js +0 -14
  99. package/dist/actions/index.cjs +0 -954
  100. package/dist/actions/index.d.ts +0 -14
  101. package/dist/actions/index.js +0 -36
  102. package/dist/actions/session/session.cjs +0 -136
  103. package/dist/actions/session/session.d.ts +0 -5
  104. package/dist/actions/session/session.js +0 -10
  105. package/dist/actions/signIn/authorization.cjs +0 -322
  106. package/dist/actions/signIn/authorization.d.ts +0 -53
  107. package/dist/actions/signIn/authorization.js +0 -18
  108. package/dist/actions/signIn/signIn.cjs +0 -467
  109. package/dist/actions/signIn/signIn.d.ts +0 -13
  110. package/dist/actions/signIn/signIn.js +0 -15
  111. package/dist/actions/signOut/signOut.cjs +0 -493
  112. package/dist/actions/signOut/signOut.d.ts +0 -8
  113. package/dist/actions/signOut/signOut.js +0 -16
  114. package/dist/assert.cjs +0 -161
  115. package/dist/assert.d.ts +0 -33
  116. package/dist/assert.js +0 -26
  117. package/dist/chunk-4EKY7655.js +0 -123
  118. package/dist/chunk-4MYWAOLG.js +0 -31
  119. package/dist/chunk-4YHJ4IEQ.js +0 -25
  120. package/dist/chunk-54CZPKR4.js +0 -25
  121. package/dist/chunk-5LZ7TOM3.js +0 -25
  122. package/dist/chunk-5W4BRQYG.js +0 -201
  123. package/dist/chunk-6MXFPFR3.js +0 -143
  124. package/dist/chunk-7QF22LHP.js +0 -67
  125. package/dist/chunk-ALG3GIV4.js +0 -95
  126. package/dist/chunk-E6G5YCI6.js +0 -25
  127. package/dist/chunk-EBAMFRB7.js +0 -34
  128. package/dist/chunk-EEE7UM5T.js +0 -25
  129. package/dist/chunk-FRJFWTOY.js +0 -70
  130. package/dist/chunk-FW4W3REU.js +0 -25
  131. package/dist/chunk-ICAZ4OVS.js +0 -37
  132. package/dist/chunk-IPKO6UQN.js +0 -25
  133. package/dist/chunk-ITQ7352M.js +0 -0
  134. package/dist/chunk-KJBAQZX2.js +0 -92
  135. package/dist/chunk-KMMAZFSJ.js +0 -25
  136. package/dist/chunk-LDU7A2JE.js +0 -25
  137. package/dist/chunk-NUDITUKX.js +0 -73
  138. package/dist/chunk-OVHNRULD.js +0 -33
  139. package/dist/chunk-PG7UYFG5.js +0 -0
  140. package/dist/chunk-PHFH2MGS.js +0 -36
  141. package/dist/chunk-QQVSRXGX.js +0 -149
  142. package/dist/chunk-RRLIF4PQ.js +0 -55
  143. package/dist/chunk-TM5IPSNF.js +0 -113
  144. package/dist/chunk-TZB6MUXN.js +0 -78
  145. package/dist/chunk-VNCNJKS2.js +0 -267
  146. package/dist/chunk-XGLBNXL4.js +0 -75
  147. package/dist/chunk-XUP6KKNG.js +0 -106
  148. package/dist/chunk-ZNCZVF6U.js +0 -14
  149. package/dist/cookie.cjs +0 -246
  150. package/dist/cookie.d.ts +0 -85
  151. package/dist/cookie.js +0 -29
  152. package/dist/env.cjs +0 -56
  153. package/dist/env.d.ts +0 -7
  154. package/dist/env.js +0 -6
  155. package/dist/errors.cjs +0 -85
  156. package/dist/errors.d.ts +0 -50
  157. package/dist/errors.js +0 -18
  158. package/dist/headers.cjs +0 -61
  159. package/dist/headers.d.ts +0 -33
  160. package/dist/headers.js +0 -12
  161. package/dist/index-CSyIJmCM.d.ts +0 -1007
  162. package/dist/jose.cjs +0 -128
  163. package/dist/jose.d.ts +0 -25
  164. package/dist/jose.js +0 -12
  165. package/dist/logger.cjs +0 -292
  166. package/dist/logger.d.ts +0 -8
  167. package/dist/logger.js +0 -8
  168. package/dist/request.cjs +0 -38
  169. package/dist/request.d.ts +0 -13
  170. package/dist/request.js +0 -6
  171. package/dist/schemas.cjs +0 -125
  172. package/dist/schemas.d.ts +0 -149
  173. package/dist/schemas.js +0 -24
  174. package/dist/secure.cjs +0 -170
  175. package/dist/secure.d.ts +0 -35
  176. package/dist/secure.js +0 -19
  177. package/dist/utils.cjs +0 -223
  178. package/dist/utils.d.ts +0 -24
  179. package/dist/utils.js +0 -29
@@ -1,493 +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_zod2 = require("zod");
27
- var import_router2 = 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, options2) {
37
- super(message, options2);
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, options2) {
47
- super(message, options2);
48
- this.code = code;
49
- this.name = new.target.name;
50
- Error.captureStackTrace(this, new.target);
51
- }
52
- };
53
-
54
- // src/utils.ts
55
- var equals = (a, b) => {
56
- if (a === null || b === null || a === void 0 || b === void 0) return false;
57
- return a === b;
58
- };
59
- var getBaseURL = (request) => {
60
- const url = new URL(request.url);
61
- return `${url.origin}${url.pathname}`;
62
- };
63
- var extractPath = (url) => {
64
- const pathRegex = /^https?:\/\/[a-zA-Z0-9_\-\.]+(:\d+)?(\/.*)$/;
65
- const match = url.match(pathRegex);
66
- return match && match[2] ? match[2] : "/";
67
- };
68
- var getErrorName = (error) => {
69
- if (error instanceof Error) {
70
- return error.name;
71
- }
72
- return typeof error === "string" ? error : "UnknownError";
73
- };
74
-
75
- // src/assert.ts
76
- var import_crypto = require("crypto");
77
- var unsafeChars = [
78
- "<",
79
- ">",
80
- '"',
81
- "`",
82
- " ",
83
- "\r",
84
- "\n",
85
- " ",
86
- "\\",
87
- "%2F",
88
- "%5C",
89
- "%2f",
90
- "%5c",
91
- "\r\n",
92
- "%0A",
93
- "%0D",
94
- "%0a",
95
- "%0d",
96
- "..",
97
- "//",
98
- "///",
99
- "...",
100
- "%20",
101
- "\0"
102
- ];
103
- var isValidURL = (value) => {
104
- if (!new RegExp(/^https?:\/\/[^/]/).test(value)) {
105
- return false;
106
- }
107
- const match = value.match(/^(https?:\/\/)(.*)$/);
108
- if (!match) return false;
109
- const rest = match[2];
110
- for (const char of unsafeChars) {
111
- if (rest.includes(char)) return false;
112
- }
113
- const regex = /^https?:\/\/(?:[a-zA-Z0-9._-]+|localhost|\[[0-9a-fA-F:]+\])(?::\d{1,5})?(?:\/[a-zA-Z0-9._~!$&'()?#*+,;=:@-]*)*\/?$/;
114
- return regex.test(match[0]);
115
- };
116
- var isJWTPayloadWithToken = (payload) => {
117
- return typeof payload === "object" && payload !== null && "token" in payload && typeof payload?.token === "string";
118
- };
119
- var isRelativeURL = (value) => {
120
- if (value.length > 100) return false;
121
- for (const char of unsafeChars) {
122
- if (value.includes(char)) return false;
123
- }
124
- const regex = /^\/[a-zA-Z0-9\-_\/.?&=#]*\/?$/;
125
- return regex.test(value);
126
- };
127
- var isSameOrigin = (origin, expected) => {
128
- const originURL = new URL(origin);
129
- const expectedURL = new URL(expected);
130
- return equals(originURL.origin, expectedURL.origin);
131
- };
132
- var patternToRegex = (pattern) => {
133
- try {
134
- if (pattern.length > 2048) return null;
135
- pattern = pattern.replace(/\\/g, "");
136
- const match = pattern.match(/^(https?):\/\/([a-zA-Z0-9.*-]{1,253})(?::(\d{1,5}|\*))?(?:\/.*)?$/);
137
- if (!match) return null;
138
- const [, protocol, host, port] = match;
139
- const hasWildcard = host.includes("*");
140
- if (hasWildcard && !host.startsWith("*.")) return null;
141
- if (hasWildcard && host.slice(2).includes("*")) return null;
142
- const domain = hasWildcard ? host.slice(2) : host;
143
- const escapedDomain = domain.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
144
- const hostRegex = hasWildcard ? `[^.]+\\.${escapedDomain}` : escapedDomain;
145
- const portRegex = port === "*" ? ":\\d{1,5}" : port ? `:${port}` : "";
146
- return new RegExp(`^${protocol}:\\/\\/${hostRegex}${portRegex}$`);
147
- } catch {
148
- return null;
149
- }
150
- };
151
- var isTrustedOrigin = (url, trustedOrigins) => {
152
- if (!isValidURL(url) || trustedOrigins.length === 0) return false;
153
- try {
154
- const urlOrigin = new URL(url).origin;
155
- for (const pattern of trustedOrigins) {
156
- const regex = patternToRegex(pattern);
157
- if (regex?.test(urlOrigin)) return true;
158
- try {
159
- if (isValidURL(pattern) && equals(new URL(pattern).origin, urlOrigin)) return true;
160
- } catch {
161
- }
162
- }
163
- } catch {
164
- }
165
- return false;
166
- };
167
- var safeEquals = (a, b) => {
168
- const bufferA = Buffer.from(a);
169
- const bufferB = Buffer.from(b);
170
- if (bufferA.length !== bufferB.length) {
171
- return false;
172
- }
173
- return (0, import_crypto.timingSafeEqual)(bufferA, bufferB);
174
- };
175
-
176
- // src/env.ts
177
- var import_meta = {};
178
- var env = new Proxy({}, {
179
- get(_, prop) {
180
- if (typeof prop !== "string") return void 0;
181
- const hasProperty = (process2) => {
182
- return process2 && Object.prototype.hasOwnProperty.call(process2, prop);
183
- };
184
- try {
185
- if (typeof process !== "undefined" && hasProperty(process.env)) {
186
- return process.env[prop];
187
- }
188
- if (typeof import_meta !== "undefined" && hasProperty(import_meta.env)) {
189
- return import_meta.env[prop];
190
- }
191
- if (typeof Deno !== "undefined" && Deno.env?.get) {
192
- return Deno.env.get(prop);
193
- }
194
- if (typeof Bun !== "undefined" && hasProperty(Bun.env)) {
195
- return Bun.env[prop];
196
- }
197
- const globalValue = globalThis[prop];
198
- return typeof globalValue === "string" ? globalValue : void 0;
199
- } catch {
200
- return void 0;
201
- }
202
- }
203
- });
204
-
205
- // src/jose.ts
206
- var import_jose = require("@aura-stack/jose");
207
- var jwtVerificationOptions = {
208
- algorithms: ["HS256"],
209
- typ: "JWT"
210
- };
211
-
212
- // src/secure.ts
213
- var verifyCSRF = async (jose, cookie, header) => {
214
- try {
215
- const cookiePayload = await jose.verifyJWS(cookie, jwtVerificationOptions);
216
- const headerPayload = await jose.verifyJWS(header, jwtVerificationOptions);
217
- if (!isJWTPayloadWithToken(cookiePayload)) {
218
- throw new AuthSecurityError("CSRF_TOKEN_INVALID", "Cookie payload missing token field.");
219
- }
220
- if (!isJWTPayloadWithToken(headerPayload)) {
221
- throw new AuthSecurityError("CSRF_TOKEN_INVALID", "Header payload missing token field.");
222
- }
223
- if (!equals(cookiePayload.token.length, headerPayload.token.length)) {
224
- throw new AuthSecurityError("CSRF_TOKEN_INVALID", "The CSRF tokens do not match.");
225
- }
226
- if (!safeEquals(cookiePayload.token, headerPayload.token)) {
227
- throw new AuthSecurityError("CSRF_TOKEN_INVALID", "The CSRF tokens do not match.");
228
- }
229
- return true;
230
- } catch {
231
- throw new AuthSecurityError("CSRF_TOKEN_INVALID", "The CSRF tokens do not match.");
232
- }
233
- };
234
-
235
- // src/headers.ts
236
- var cacheControl = {
237
- "Cache-Control": "no-store",
238
- Pragma: "no-cache",
239
- Expires: "0",
240
- Vary: "Cookie"
241
- };
242
- var contentSecurityPolicy = {
243
- "Content-Security-Policy": [
244
- "default-src 'none'",
245
- "script-src 'self'",
246
- "frame-src 'none'",
247
- "object-src 'none'",
248
- "frame-ancestors 'none'",
249
- "base-uri 'none'"
250
- ].join("; ")
251
- };
252
- var secureHeaders = {
253
- "X-Content-Type-Options": "nosniff",
254
- "X-Frame-Options": "DENY",
255
- "Referrer-Policy": "strict-origin-when-cross-origin"
256
- };
257
- var secureApiHeaders = {
258
- ...cacheControl,
259
- ...contentSecurityPolicy,
260
- ...secureHeaders
261
- };
262
-
263
- // src/cookie.ts
264
- var import_cookie = require("@aura-stack/router/cookie");
265
- var defaultCookieOptions = {
266
- httpOnly: true,
267
- sameSite: "lax",
268
- path: "/",
269
- maxAge: 60 * 60 * 24 * 15
270
- };
271
- var oauthCookieOptions = {
272
- httpOnly: true,
273
- maxAge: 5 * 60,
274
- sameSite: "lax",
275
- expires: new Date(Date.now() + 5 * 60 * 1e3)
276
- };
277
- var expiredCookieAttributes = {
278
- ...defaultCookieOptions,
279
- expires: /* @__PURE__ */ new Date(0),
280
- maxAge: 0,
281
- secure: true
282
- };
283
-
284
- // src/schemas.ts
285
- var import_zod = require("zod");
286
- var OAuthProviderCredentialsSchema = (0, import_zod.object)({
287
- id: (0, import_zod.string)(),
288
- name: (0, import_zod.string)(),
289
- authorizeURL: (0, import_zod.string)().url(),
290
- accessToken: (0, import_zod.string)().url(),
291
- scope: (0, import_zod.string)(),
292
- userInfo: (0, import_zod.string)().url(),
293
- responseType: (0, import_zod.enum)(["code", "token", "id_token"]),
294
- clientId: (0, import_zod.string)(),
295
- clientSecret: (0, import_zod.string)(),
296
- profile: import_zod.z.function().optional()
297
- });
298
- var OAuthProviderConfigSchema = (0, import_zod.object)({
299
- authorizeURL: (0, import_zod.string)().url(),
300
- accessToken: (0, import_zod.string)().url(),
301
- scope: (0, import_zod.string)().optional(),
302
- userInfo: (0, import_zod.string)().url(),
303
- responseType: (0, import_zod.enum)(["code", "token", "id_token"]),
304
- clientId: (0, import_zod.string)(),
305
- clientSecret: (0, import_zod.string)()
306
- });
307
- var OAuthAuthorization = OAuthProviderConfigSchema.extend({
308
- redirectURI: (0, import_zod.string)(),
309
- state: (0, import_zod.string)(),
310
- codeChallenge: (0, import_zod.string)(),
311
- codeChallengeMethod: (0, import_zod.enum)(["plain", "S256"])
312
- });
313
- var OAuthAuthorizationResponse = (0, import_zod.object)({
314
- state: (0, import_zod.string)({ message: "Missing state parameter in the OAuth authorization response." }),
315
- code: (0, import_zod.string)({ message: "Missing code parameter in the OAuth authorization response." })
316
- });
317
- var OAuthAuthorizationErrorResponse = (0, import_zod.object)({
318
- error: (0, import_zod.enum)([
319
- "invalid_request",
320
- "unauthorized_client",
321
- "access_denied",
322
- "unsupported_response_type",
323
- "invalid_scope",
324
- "server_error",
325
- "temporarily_unavailable"
326
- ]),
327
- error_description: (0, import_zod.string)().optional(),
328
- error_uri: (0, import_zod.string)().optional(),
329
- state: (0, import_zod.string)()
330
- });
331
- var OAuthAccessToken = OAuthProviderConfigSchema.extend({
332
- redirectURI: (0, import_zod.string)(),
333
- code: (0, import_zod.string)(),
334
- codeVerifier: (0, import_zod.string)().min(43).max(128)
335
- });
336
- var OAuthAccessTokenResponse = (0, import_zod.object)({
337
- access_token: (0, import_zod.string)(),
338
- token_type: (0, import_zod.string)().optional(),
339
- expires_in: (0, import_zod.number)().optional(),
340
- refresh_token: (0, import_zod.string)().optional(),
341
- scope: (0, import_zod.string)().optional().or((0, import_zod.null)())
342
- });
343
- var OAuthAccessTokenErrorResponse = (0, import_zod.object)({
344
- error: (0, import_zod.enum)([
345
- "invalid_request",
346
- "invalid_client",
347
- "invalid_grant",
348
- "unauthorized_client",
349
- "unsupported_grant_type",
350
- "invalid_scope"
351
- ]),
352
- error_description: (0, import_zod.string)().optional(),
353
- error_uri: (0, import_zod.string)().optional()
354
- });
355
- var OAuthErrorResponse = (0, import_zod.object)({
356
- error: (0, import_zod.string)(),
357
- error_description: (0, import_zod.string)().optional()
358
- });
359
- var OAuthEnvSchema = (0, import_zod.object)({
360
- clientId: import_zod.z.string().min(1, "OAuth Client ID is required in the environment variables."),
361
- clientSecret: import_zod.z.string().min(1, "OAuth Client Secret is required in the environment variables.")
362
- });
363
-
364
- // src/actions/signIn/authorization.ts
365
- var getTrustedOrigins = async (request, trustedOrigins) => {
366
- if (!trustedOrigins) return [];
367
- const raw = typeof trustedOrigins === "function" ? await trustedOrigins(request) : trustedOrigins;
368
- return Array.isArray(raw) ? raw : typeof raw === "string" ? [raw] : [];
369
- };
370
- var getOriginURL = async (request, context) => {
371
- const headers = request.headers;
372
- let origin = new URL(request.url).origin;
373
- const trustedOrigins = await getTrustedOrigins(request, context?.trustedOrigins);
374
- trustedOrigins.push(origin);
375
- if (context?.trustedProxyHeaders) {
376
- const protocol = headers.get("Forwarded")?.match(/proto=([^;]+)/i)?.[1] ?? headers.get("X-Forwarded-Proto") ?? "http";
377
- const host = headers.get("Host") ?? headers.get("Forwarded")?.match(/host=([^;]+)/i)?.[1] ?? headers.get("X-Forwarded-Host") ?? null;
378
- origin = `${protocol}://${host}`;
379
- }
380
- if (!isTrustedOrigin(origin, trustedOrigins)) {
381
- context?.logger?.log("UNTRUSTED_ORIGIN", { structuredData: { origin } });
382
- throw new AuthInternalError("UNTRUSTED_ORIGIN", "The constructed origin URL is not trusted.");
383
- }
384
- return origin;
385
- };
386
- var createRedirectTo = async (request, redirectTo, context) => {
387
- try {
388
- const headers = request.headers;
389
- const requestOrigin = await getOriginURL(request, context);
390
- const origins = await getTrustedOrigins(request, context?.trustedOrigins);
391
- const validateURL = (url) => {
392
- if (!isRelativeURL(url) && !isValidURL(url)) return "/";
393
- if (isRelativeURL(url)) return url;
394
- if (origins.length > 0) {
395
- if (isTrustedOrigin(url, origins)) {
396
- const urlOrigin = new URL(url).origin;
397
- for (const pattern of origins) {
398
- const regex = patternToRegex(pattern);
399
- if (regex?.test(urlOrigin)) {
400
- return isSameOrigin(url, request.url) ? extractPath(url) : url;
401
- }
402
- if (isValidURL(pattern) && equals(new URL(pattern).origin, urlOrigin)) return url;
403
- }
404
- }
405
- context?.logger?.log("OPEN_REDIRECT_ATTACK");
406
- return "/";
407
- }
408
- if (isSameOrigin(url, requestOrigin)) {
409
- return extractPath(url);
410
- }
411
- context?.logger?.log("OPEN_REDIRECT_ATTACK");
412
- return "/";
413
- };
414
- return validateURL(redirectTo ?? headers.get("Referer") ?? headers.get("Origin") ?? "/");
415
- } catch (error) {
416
- context?.logger?.log("POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED");
417
- return "/";
418
- }
419
- };
420
-
421
- // src/actions/signOut/signOut.ts
422
- var config = (0, import_router2.createEndpointConfig)({
423
- schemas: {
424
- searchParams: import_zod2.z.object({
425
- token_type_hint: import_zod2.z.literal("session_token"),
426
- redirectTo: import_zod2.z.string().optional()
427
- })
428
- }
429
- });
430
- var signOutAction = (0, import_router2.createEndpoint)(
431
- "POST",
432
- "/signOut",
433
- async (ctx) => {
434
- const {
435
- request,
436
- headers,
437
- searchParams: { redirectTo },
438
- context
439
- } = ctx;
440
- const { jose, cookies, logger } = context;
441
- const session = headers.getCookie(cookies.sessionToken.name);
442
- const csrfToken = headers.getCookie(cookies.csrfToken.name);
443
- const header = headers.getHeader("X-CSRF-Token");
444
- logger?.log("SIGN_OUT_ATTEMPT", {
445
- structuredData: {
446
- has_session: Boolean(session),
447
- has_csrf_token: Boolean(csrfToken),
448
- has_csrf_header: Boolean(header)
449
- }
450
- });
451
- if (!session) {
452
- logger?.log("SESSION_TOKEN_MISSING");
453
- throw new AuthSecurityError("SESSION_TOKEN_MISSING", "The sessionToken is missing.");
454
- }
455
- if (!csrfToken) {
456
- logger?.log("CSRF_TOKEN_MISSING");
457
- throw new AuthSecurityError("CSRF_TOKEN_MISSING", "The CSRF token is missing.");
458
- }
459
- if (!header) {
460
- logger?.log("CSRF_HEADER_MISSING");
461
- throw new AuthSecurityError("CSRF_HEADER_MISSING", "The CSRF header is missing.");
462
- }
463
- try {
464
- await verifyCSRF(jose, csrfToken, header);
465
- } catch (error) {
466
- logger?.log("CSRF_TOKEN_INVALID", { structuredData: { error_type: getErrorName(error) } });
467
- throw new AuthSecurityError("CSRF_TOKEN_INVALID", "CSRF token verification failed");
468
- }
469
- logger?.log("SIGN_OUT_CSRF_VERIFIED");
470
- try {
471
- await jose.decodeJWT(session);
472
- logger?.log("SIGN_OUT_SUCCESS");
473
- } catch (error) {
474
- logger?.log("INVALID_JWT_TOKEN", { structuredData: { error_type: getErrorName(error) } });
475
- }
476
- const baseURL = getBaseURL(request);
477
- const location = await createRedirectTo(
478
- new Request(baseURL, {
479
- headers: headers.toHeaders()
480
- }),
481
- redirectTo,
482
- context
483
- );
484
- logger?.log("SIGN_OUT_REDIRECT", { structuredData: { location } });
485
- const headersList = new import_router2.HeadersBuilder(secureApiHeaders).setHeader("Location", location).setCookie(cookies.csrfToken.name, "", expiredCookieAttributes).setCookie(cookies.sessionToken.name, "", expiredCookieAttributes).toHeaders();
486
- return Response.json({ message: "Signed out successfully" }, { status: import_router2.statusCode.ACCEPTED, headers: headersList });
487
- },
488
- config
489
- );
490
- // Annotate the CommonJS export names for ESM import in node:
491
- 0 && (module.exports = {
492
- signOutAction
493
- });
@@ -1,8 +0,0 @@
1
- import * as _aura_stack_router from '@aura-stack/router';
2
-
3
- /**
4
- * @see https://datatracker.ietf.org/doc/html/rfc7009
5
- */
6
- declare const signOutAction: _aura_stack_router.RouteEndpoint<"POST", "/signOut", {}>;
7
-
8
- export { signOutAction };
@@ -1,16 +0,0 @@
1
- import {
2
- signOutAction
3
- } from "../../chunk-ALG3GIV4.js";
4
- import "../../chunk-XUP6KKNG.js";
5
- import "../../chunk-KJBAQZX2.js";
6
- import "../../chunk-NUDITUKX.js";
7
- import "../../chunk-4EKY7655.js";
8
- import "../../chunk-QQVSRXGX.js";
9
- import "../../chunk-5W4BRQYG.js";
10
- import "../../chunk-EBAMFRB7.js";
11
- import "../../chunk-FRJFWTOY.js";
12
- import "../../chunk-4MYWAOLG.js";
13
- import "../../chunk-RRLIF4PQ.js";
14
- export {
15
- signOutAction
16
- };
package/dist/assert.cjs DELETED
@@ -1,161 +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/assert.ts
21
- var assert_exports = {};
22
- __export(assert_exports, {
23
- isFalsy: () => isFalsy,
24
- isJWTPayloadWithToken: () => isJWTPayloadWithToken,
25
- isRelativeURL: () => isRelativeURL,
26
- isRequest: () => isRequest,
27
- isSameOrigin: () => isSameOrigin,
28
- isTrustedOrigin: () => isTrustedOrigin,
29
- isValidURL: () => isValidURL,
30
- patternToRegex: () => patternToRegex,
31
- safeEquals: () => safeEquals,
32
- unsafeChars: () => unsafeChars
33
- });
34
- module.exports = __toCommonJS(assert_exports);
35
-
36
- // src/utils.ts
37
- var import_router = require("@aura-stack/router");
38
- var equals = (a, b) => {
39
- if (a === null || b === null || a === void 0 || b === void 0) return false;
40
- return a === b;
41
- };
42
-
43
- // src/assert.ts
44
- var import_crypto = require("crypto");
45
- var isFalsy = (value) => {
46
- return value === false || value === 0 || value === "" || value === null || value === void 0 || Number.isNaN(value);
47
- };
48
- var isRequest = (value) => {
49
- return typeof Request !== "undefined" && value instanceof Request;
50
- };
51
- var unsafeChars = [
52
- "<",
53
- ">",
54
- '"',
55
- "`",
56
- " ",
57
- "\r",
58
- "\n",
59
- " ",
60
- "\\",
61
- "%2F",
62
- "%5C",
63
- "%2f",
64
- "%5c",
65
- "\r\n",
66
- "%0A",
67
- "%0D",
68
- "%0a",
69
- "%0d",
70
- "..",
71
- "//",
72
- "///",
73
- "...",
74
- "%20",
75
- "\0"
76
- ];
77
- var isValidURL = (value) => {
78
- if (!new RegExp(/^https?:\/\/[^/]/).test(value)) {
79
- return false;
80
- }
81
- const match = value.match(/^(https?:\/\/)(.*)$/);
82
- if (!match) return false;
83
- const rest = match[2];
84
- for (const char of unsafeChars) {
85
- if (rest.includes(char)) return false;
86
- }
87
- const regex = /^https?:\/\/(?:[a-zA-Z0-9._-]+|localhost|\[[0-9a-fA-F:]+\])(?::\d{1,5})?(?:\/[a-zA-Z0-9._~!$&'()?#*+,;=:@-]*)*\/?$/;
88
- return regex.test(match[0]);
89
- };
90
- var isJWTPayloadWithToken = (payload) => {
91
- return typeof payload === "object" && payload !== null && "token" in payload && typeof payload?.token === "string";
92
- };
93
- var isRelativeURL = (value) => {
94
- if (value.length > 100) return false;
95
- for (const char of unsafeChars) {
96
- if (value.includes(char)) return false;
97
- }
98
- const regex = /^\/[a-zA-Z0-9\-_\/.?&=#]*\/?$/;
99
- return regex.test(value);
100
- };
101
- var isSameOrigin = (origin, expected) => {
102
- const originURL = new URL(origin);
103
- const expectedURL = new URL(expected);
104
- return equals(originURL.origin, expectedURL.origin);
105
- };
106
- var patternToRegex = (pattern) => {
107
- try {
108
- if (pattern.length > 2048) return null;
109
- pattern = pattern.replace(/\\/g, "");
110
- const match = pattern.match(/^(https?):\/\/([a-zA-Z0-9.*-]{1,253})(?::(\d{1,5}|\*))?(?:\/.*)?$/);
111
- if (!match) return null;
112
- const [, protocol, host, port] = match;
113
- const hasWildcard = host.includes("*");
114
- if (hasWildcard && !host.startsWith("*.")) return null;
115
- if (hasWildcard && host.slice(2).includes("*")) return null;
116
- const domain = hasWildcard ? host.slice(2) : host;
117
- const escapedDomain = domain.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
118
- const hostRegex = hasWildcard ? `[^.]+\\.${escapedDomain}` : escapedDomain;
119
- const portRegex = port === "*" ? ":\\d{1,5}" : port ? `:${port}` : "";
120
- return new RegExp(`^${protocol}:\\/\\/${hostRegex}${portRegex}$`);
121
- } catch {
122
- return null;
123
- }
124
- };
125
- var isTrustedOrigin = (url, trustedOrigins) => {
126
- if (!isValidURL(url) || trustedOrigins.length === 0) return false;
127
- try {
128
- const urlOrigin = new URL(url).origin;
129
- for (const pattern of trustedOrigins) {
130
- const regex = patternToRegex(pattern);
131
- if (regex?.test(urlOrigin)) return true;
132
- try {
133
- if (isValidURL(pattern) && equals(new URL(pattern).origin, urlOrigin)) return true;
134
- } catch {
135
- }
136
- }
137
- } catch {
138
- }
139
- return false;
140
- };
141
- var safeEquals = (a, b) => {
142
- const bufferA = Buffer.from(a);
143
- const bufferB = Buffer.from(b);
144
- if (bufferA.length !== bufferB.length) {
145
- return false;
146
- }
147
- return (0, import_crypto.timingSafeEqual)(bufferA, bufferB);
148
- };
149
- // Annotate the CommonJS export names for ESM import in node:
150
- 0 && (module.exports = {
151
- isFalsy,
152
- isJWTPayloadWithToken,
153
- isRelativeURL,
154
- isRequest,
155
- isSameOrigin,
156
- isTrustedOrigin,
157
- isValidURL,
158
- patternToRegex,
159
- safeEquals,
160
- unsafeChars
161
- });