@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
package/dist/assert.d.ts DELETED
@@ -1,33 +0,0 @@
1
- import { J as JWTPayloadWithToken } from './index-CSyIJmCM.js';
2
- import 'zod';
3
- import './schemas.js';
4
- import './jose.js';
5
- import '@aura-stack/jose';
6
- import '@aura-stack/jose/jose';
7
- import '@aura-stack/router/cookie';
8
- import './@types/utility.js';
9
-
10
- declare const isFalsy: (value: unknown) => boolean;
11
- declare const isRequest: (value: unknown) => value is Request;
12
- declare const unsafeChars: string[];
13
- declare const isValidURL: (value: string) => boolean;
14
- declare const isJWTPayloadWithToken: (payload: unknown) => payload is JWTPayloadWithToken;
15
- declare const isRelativeURL: (value: string) => boolean;
16
- declare const isSameOrigin: (origin: string, expected: string) => boolean;
17
- /**
18
- * Converts a trusted origin pattern to a regex for matching.
19
- * Supports `*` as subdomain wildcard: `https://*.example.com` matches `https://app.example.com`
20
- * @todo: add support to Custom URI Schemes (e.g. `myapp://*`).
21
- */
22
- declare const patternToRegex: (pattern: string) => RegExp | null;
23
- /**
24
- * Checks if a URL matches any of the trusted origin patterns.
25
- * A URL is trusted if its origin matches any pattern (exact or wildcard).
26
- *
27
- * @param url - The URL to validate (e.g. from Referer, Origin, redirectTo)
28
- * @param trustedOrigins - Array of exact URLs or patterns (e.g. `https://*.example.com`)
29
- */
30
- declare const isTrustedOrigin: (url: string, trustedOrigins: string[]) => boolean;
31
- declare const safeEquals: (a: string, b: string) => boolean;
32
-
33
- export { isFalsy, isJWTPayloadWithToken, isRelativeURL, isRequest, isSameOrigin, isTrustedOrigin, isValidURL, patternToRegex, safeEquals, unsafeChars };
package/dist/assert.js DELETED
@@ -1,26 +0,0 @@
1
- import {
2
- isFalsy,
3
- isJWTPayloadWithToken,
4
- isRelativeURL,
5
- isRequest,
6
- isSameOrigin,
7
- isTrustedOrigin,
8
- isValidURL,
9
- patternToRegex,
10
- safeEquals,
11
- unsafeChars
12
- } from "./chunk-4EKY7655.js";
13
- import "./chunk-QQVSRXGX.js";
14
- import "./chunk-RRLIF4PQ.js";
15
- export {
16
- isFalsy,
17
- isJWTPayloadWithToken,
18
- isRelativeURL,
19
- isRequest,
20
- isSameOrigin,
21
- isTrustedOrigin,
22
- isValidURL,
23
- patternToRegex,
24
- safeEquals,
25
- unsafeChars
26
- };
@@ -1,123 +0,0 @@
1
- import {
2
- equals
3
- } from "./chunk-QQVSRXGX.js";
4
-
5
- // src/assert.ts
6
- import { timingSafeEqual } from "crypto";
7
- var isFalsy = (value) => {
8
- return value === false || value === 0 || value === "" || value === null || value === void 0 || Number.isNaN(value);
9
- };
10
- var isRequest = (value) => {
11
- return typeof Request !== "undefined" && value instanceof Request;
12
- };
13
- var unsafeChars = [
14
- "<",
15
- ">",
16
- '"',
17
- "`",
18
- " ",
19
- "\r",
20
- "\n",
21
- " ",
22
- "\\",
23
- "%2F",
24
- "%5C",
25
- "%2f",
26
- "%5c",
27
- "\r\n",
28
- "%0A",
29
- "%0D",
30
- "%0a",
31
- "%0d",
32
- "..",
33
- "//",
34
- "///",
35
- "...",
36
- "%20",
37
- "\0"
38
- ];
39
- var isValidURL = (value) => {
40
- if (!new RegExp(/^https?:\/\/[^/]/).test(value)) {
41
- return false;
42
- }
43
- const match = value.match(/^(https?:\/\/)(.*)$/);
44
- if (!match) return false;
45
- const rest = match[2];
46
- for (const char of unsafeChars) {
47
- if (rest.includes(char)) return false;
48
- }
49
- const regex = /^https?:\/\/(?:[a-zA-Z0-9._-]+|localhost|\[[0-9a-fA-F:]+\])(?::\d{1,5})?(?:\/[a-zA-Z0-9._~!$&'()?#*+,;=:@-]*)*\/?$/;
50
- return regex.test(match[0]);
51
- };
52
- var isJWTPayloadWithToken = (payload) => {
53
- return typeof payload === "object" && payload !== null && "token" in payload && typeof payload?.token === "string";
54
- };
55
- var isRelativeURL = (value) => {
56
- if (value.length > 100) return false;
57
- for (const char of unsafeChars) {
58
- if (value.includes(char)) return false;
59
- }
60
- const regex = /^\/[a-zA-Z0-9\-_\/.?&=#]*\/?$/;
61
- return regex.test(value);
62
- };
63
- var isSameOrigin = (origin, expected) => {
64
- const originURL = new URL(origin);
65
- const expectedURL = new URL(expected);
66
- return equals(originURL.origin, expectedURL.origin);
67
- };
68
- var patternToRegex = (pattern) => {
69
- try {
70
- if (pattern.length > 2048) return null;
71
- pattern = pattern.replace(/\\/g, "");
72
- const match = pattern.match(/^(https?):\/\/([a-zA-Z0-9.*-]{1,253})(?::(\d{1,5}|\*))?(?:\/.*)?$/);
73
- if (!match) return null;
74
- const [, protocol, host, port] = match;
75
- const hasWildcard = host.includes("*");
76
- if (hasWildcard && !host.startsWith("*.")) return null;
77
- if (hasWildcard && host.slice(2).includes("*")) return null;
78
- const domain = hasWildcard ? host.slice(2) : host;
79
- const escapedDomain = domain.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
80
- const hostRegex = hasWildcard ? `[^.]+\\.${escapedDomain}` : escapedDomain;
81
- const portRegex = port === "*" ? ":\\d{1,5}" : port ? `:${port}` : "";
82
- return new RegExp(`^${protocol}:\\/\\/${hostRegex}${portRegex}$`);
83
- } catch {
84
- return null;
85
- }
86
- };
87
- var isTrustedOrigin = (url, trustedOrigins) => {
88
- if (!isValidURL(url) || trustedOrigins.length === 0) return false;
89
- try {
90
- const urlOrigin = new URL(url).origin;
91
- for (const pattern of trustedOrigins) {
92
- const regex = patternToRegex(pattern);
93
- if (regex?.test(urlOrigin)) return true;
94
- try {
95
- if (isValidURL(pattern) && equals(new URL(pattern).origin, urlOrigin)) return true;
96
- } catch {
97
- }
98
- }
99
- } catch {
100
- }
101
- return false;
102
- };
103
- var safeEquals = (a, b) => {
104
- const bufferA = Buffer.from(a);
105
- const bufferB = Buffer.from(b);
106
- if (bufferA.length !== bufferB.length) {
107
- return false;
108
- }
109
- return timingSafeEqual(bufferA, bufferB);
110
- };
111
-
112
- export {
113
- isFalsy,
114
- isRequest,
115
- unsafeChars,
116
- isValidURL,
117
- isJWTPayloadWithToken,
118
- isRelativeURL,
119
- isSameOrigin,
120
- patternToRegex,
121
- isTrustedOrigin,
122
- safeEquals
123
- };
@@ -1,31 +0,0 @@
1
- // src/env.ts
2
- var env = new Proxy({}, {
3
- get(_, prop) {
4
- if (typeof prop !== "string") return void 0;
5
- const hasProperty = (process2) => {
6
- return process2 && Object.prototype.hasOwnProperty.call(process2, prop);
7
- };
8
- try {
9
- if (typeof process !== "undefined" && hasProperty(process.env)) {
10
- return process.env[prop];
11
- }
12
- if (typeof import.meta !== "undefined" && hasProperty(import.meta.env)) {
13
- return import.meta.env[prop];
14
- }
15
- if (typeof Deno !== "undefined" && Deno.env?.get) {
16
- return Deno.env.get(prop);
17
- }
18
- if (typeof Bun !== "undefined" && hasProperty(Bun.env)) {
19
- return Bun.env[prop];
20
- }
21
- const globalValue = globalThis[prop];
22
- return typeof globalValue === "string" ? globalValue : void 0;
23
- } catch {
24
- return void 0;
25
- }
26
- }
27
- });
28
-
29
- export {
30
- env
31
- };
@@ -1,25 +0,0 @@
1
- // src/oauth/bitbucket.ts
2
- var bitbucket = (options) => {
3
- return {
4
- id: "bitbucket",
5
- name: "Bitbucket",
6
- authorizeURL: "https://bitbucket.org/site/oauth2/authorize",
7
- accessToken: "https://bitbucket.org/site/oauth2/access_token",
8
- userInfo: "https://api.bitbucket.org/2.0/user",
9
- scope: "account email",
10
- responseType: "code",
11
- profile(profile) {
12
- return {
13
- sub: profile.uuid ?? profile.account_id,
14
- name: profile.display_name ?? profile.nickname,
15
- image: profile.links.avatar?.href,
16
- email: void 0
17
- };
18
- },
19
- ...options
20
- };
21
- };
22
-
23
- export {
24
- bitbucket
25
- };
@@ -1,25 +0,0 @@
1
- // src/oauth/strava.ts
2
- var strava = (options) => {
3
- return {
4
- id: "strava",
5
- name: "Strava",
6
- authorizeURL: "https://www.strava.com/oauth/authorize",
7
- accessToken: "https://www.strava.com/oauth/token",
8
- userInfo: "https://www.strava.com/api/v3/athlete",
9
- scope: "read",
10
- responseType: "code",
11
- profile(profile) {
12
- return {
13
- sub: profile.id.toString(),
14
- name: `${profile.firstname} ${profile.lastname}`,
15
- image: profile.profile,
16
- email: void 0
17
- };
18
- },
19
- ...options
20
- };
21
- };
22
-
23
- export {
24
- strava
25
- };
@@ -1,25 +0,0 @@
1
- // src/oauth/gitlab.ts
2
- var gitlab = (options) => {
3
- return {
4
- id: "gitlab",
5
- name: "GitLab",
6
- authorizeURL: "https://gitlab.com/oauth/authorize",
7
- accessToken: "https://gitlab.com/oauth/token",
8
- userInfo: "https://gitlab.com/api/v4/user",
9
- scope: "read_user",
10
- responseType: "code",
11
- profile(profile) {
12
- return {
13
- sub: profile.id.toString(),
14
- name: profile.name ?? profile.username,
15
- email: profile.email,
16
- image: profile.avatar_url
17
- };
18
- },
19
- ...options
20
- };
21
- };
22
-
23
- export {
24
- gitlab
25
- };
@@ -1,201 +0,0 @@
1
- import {
2
- AuthInternalError
3
- } from "./chunk-RRLIF4PQ.js";
4
-
5
- // src/cookie.ts
6
- import { parse, parseSetCookie, serialize } from "@aura-stack/router/cookie";
7
- var COOKIE_NAME = "aura-auth";
8
- var defaultCookieOptions = {
9
- httpOnly: true,
10
- sameSite: "lax",
11
- path: "/",
12
- maxAge: 60 * 60 * 24 * 15
13
- };
14
- var defaultStandardCookieConfig = {
15
- secure: false,
16
- httpOnly: true
17
- };
18
- var defaultSecureCookieConfig = {
19
- secure: true,
20
- httpOnly: true
21
- };
22
- var defaultHostCookieConfig = {
23
- secure: true,
24
- httpOnly: true,
25
- path: "/",
26
- domain: void 0
27
- };
28
- var oauthCookieOptions = {
29
- httpOnly: true,
30
- maxAge: 5 * 60,
31
- sameSite: "lax",
32
- expires: new Date(Date.now() + 5 * 60 * 1e3)
33
- };
34
- var setCookie = (cookieName, value, options) => {
35
- return serialize(cookieName, value, options);
36
- };
37
- var expiredCookieAttributes = {
38
- ...defaultCookieOptions,
39
- expires: /* @__PURE__ */ new Date(0),
40
- maxAge: 0,
41
- secure: true
42
- };
43
- var getCookie = (request, cookieName) => {
44
- const cookies = request.headers.get("Cookie");
45
- if (!cookies) {
46
- throw new AuthInternalError("COOKIE_NOT_FOUND", "No cookies found. There is no active session");
47
- }
48
- const value = parse(cookies)[cookieName];
49
- if (!value) {
50
- throw new AuthInternalError("COOKIE_NOT_FOUND", `Cookie "${cookieName}" not found. There is no active session`);
51
- }
52
- return value;
53
- };
54
- var getSetCookie = (response, cookieName) => {
55
- const cookies = response.headers.getSetCookie();
56
- if (!cookies) {
57
- throw new AuthInternalError("COOKIE_NOT_FOUND", "No cookies found in response.");
58
- }
59
- const strCookie = cookies.find((cookie) => cookie.startsWith(`${cookieName}=`));
60
- if (!strCookie) {
61
- throw new AuthInternalError("COOKIE_NOT_FOUND", `Cookie "${cookieName}" not found in response.`);
62
- }
63
- return parseSetCookie(strCookie).value;
64
- };
65
- var createSessionCookie = async (jose, session) => {
66
- try {
67
- const encoded = await jose.encodeJWT(session);
68
- return encoded;
69
- } catch (error) {
70
- throw new AuthInternalError("INVALID_JWT_TOKEN", "Failed to create session cookie", { cause: error });
71
- }
72
- };
73
- var defineSecureCookieOptions = (useSecure, attributes, strategy, logger) => {
74
- if (!attributes.httpOnly) {
75
- logger?.log("COOKIE_HTTPONLY_DISABLED");
76
- }
77
- if (attributes.domain === "*") {
78
- attributes.domain = void 0;
79
- logger?.log("COOKIE_WILDCARD_DOMAIN");
80
- }
81
- if (!useSecure) {
82
- if (attributes.secure) {
83
- logger?.log("COOKIE_SECURE_DISABLED");
84
- }
85
- if (attributes.sameSite == "none") {
86
- attributes.sameSite = "lax";
87
- logger?.log("COOKIE_SAMESITE_NONE_WITHOUT_SECURE");
88
- }
89
- if (process.env.NODE_ENV === "production") {
90
- logger?.log("COOKIE_INSECURE_IN_PRODUCTION");
91
- }
92
- if (strategy === "host") {
93
- logger?.log("COOKIE_HOST_STRATEGY_INSECURE");
94
- }
95
- return {
96
- ...defaultCookieOptions,
97
- ...attributes,
98
- ...defaultStandardCookieConfig
99
- };
100
- }
101
- return strategy === "host" ? {
102
- ...defaultCookieOptions,
103
- ...attributes,
104
- ...defaultHostCookieConfig
105
- } : { ...defaultCookieOptions, ...attributes, ...defaultSecureCookieConfig };
106
- };
107
- var createCookieStore = (useSecure, prefix, overrides, logger) => {
108
- prefix ??= COOKIE_NAME;
109
- const securePrefix = useSecure ? "__Secure-" : "";
110
- const hostPrefix = useSecure ? "__Host-" : "";
111
- return {
112
- sessionToken: {
113
- name: `${securePrefix}${prefix}.${overrides?.sessionToken?.name ?? "session_token"}`,
114
- attributes: defineSecureCookieOptions(
115
- useSecure,
116
- {
117
- ...defaultCookieOptions,
118
- ...overrides?.sessionToken?.attributes
119
- },
120
- overrides?.sessionToken?.attributes?.strategy ?? "secure",
121
- logger
122
- )
123
- },
124
- state: {
125
- name: `${securePrefix}${prefix}.${overrides?.state?.name ?? "state"}`,
126
- attributes: defineSecureCookieOptions(
127
- useSecure,
128
- {
129
- ...oauthCookieOptions,
130
- ...overrides?.state?.attributes
131
- },
132
- overrides?.state?.attributes?.strategy ?? "secure",
133
- logger
134
- )
135
- },
136
- csrfToken: {
137
- name: `${hostPrefix}${prefix}.${overrides?.csrfToken?.name ?? "csrf_token"}`,
138
- attributes: defineSecureCookieOptions(
139
- useSecure,
140
- {
141
- ...overrides?.csrfToken?.attributes,
142
- ...defaultHostCookieConfig,
143
- sameSite: "strict"
144
- },
145
- overrides?.csrfToken?.attributes?.strategy ?? "host",
146
- logger
147
- )
148
- },
149
- redirectTo: {
150
- name: `${securePrefix}${prefix}.${overrides?.redirectTo?.name ?? "redirect_to"}`,
151
- attributes: defineSecureCookieOptions(
152
- useSecure,
153
- {
154
- ...oauthCookieOptions,
155
- ...overrides?.redirectTo?.attributes
156
- },
157
- overrides?.redirectTo?.attributes?.strategy ?? "secure",
158
- logger
159
- )
160
- },
161
- redirectURI: {
162
- name: `${securePrefix}${prefix}.${overrides?.redirectURI?.name ?? "redirect_uri"}`,
163
- attributes: defineSecureCookieOptions(
164
- useSecure,
165
- {
166
- ...oauthCookieOptions,
167
- ...overrides?.redirectURI?.attributes
168
- },
169
- overrides?.redirectURI?.attributes?.strategy ?? "secure",
170
- logger
171
- )
172
- },
173
- codeVerifier: {
174
- name: `${securePrefix}${prefix}.${overrides?.codeVerifier?.name ?? "code_verifier"}`,
175
- attributes: defineSecureCookieOptions(
176
- useSecure,
177
- {
178
- ...oauthCookieOptions,
179
- ...overrides?.codeVerifier?.attributes
180
- },
181
- overrides?.codeVerifier?.attributes?.strategy ?? "secure",
182
- logger
183
- )
184
- }
185
- };
186
- };
187
-
188
- export {
189
- COOKIE_NAME,
190
- defaultCookieOptions,
191
- defaultStandardCookieConfig,
192
- defaultSecureCookieConfig,
193
- defaultHostCookieConfig,
194
- setCookie,
195
- expiredCookieAttributes,
196
- getCookie,
197
- getSetCookie,
198
- createSessionCookie,
199
- defineSecureCookieOptions,
200
- createCookieStore
201
- };
@@ -1,143 +0,0 @@
1
- import {
2
- createAccessToken
3
- } from "./chunk-TZB6MUXN.js";
4
- import {
5
- getUserInfo
6
- } from "./chunk-XGLBNXL4.js";
7
- import {
8
- getOriginURL,
9
- getTrustedOrigins
10
- } from "./chunk-XUP6KKNG.js";
11
- import {
12
- OAuthAuthorizationErrorResponse
13
- } from "./chunk-KJBAQZX2.js";
14
- import {
15
- createCSRF
16
- } from "./chunk-NUDITUKX.js";
17
- import {
18
- isRelativeURL,
19
- isSameOrigin,
20
- isTrustedOrigin,
21
- safeEquals
22
- } from "./chunk-4EKY7655.js";
23
- import {
24
- createSessionCookie,
25
- expiredCookieAttributes,
26
- getCookie
27
- } from "./chunk-5W4BRQYG.js";
28
- import {
29
- cacheControl
30
- } from "./chunk-EBAMFRB7.js";
31
- import {
32
- AuthSecurityError,
33
- OAuthProtocolError
34
- } from "./chunk-RRLIF4PQ.js";
35
-
36
- // src/actions/callback/callback.ts
37
- import { z } from "zod";
38
- import { createEndpoint, createEndpointConfig, HeadersBuilder } from "@aura-stack/router";
39
- var callbackConfig = (oauth) => {
40
- return createEndpointConfig("/callback/:oauth", {
41
- schemas: {
42
- params: z.object({
43
- oauth: z.enum(
44
- Object.keys(oauth),
45
- "The OAuth provider is not supported or invalid."
46
- )
47
- }),
48
- searchParams: z.object({
49
- code: z.string("Missing code parameter in the OAuth authorization response."),
50
- state: z.string("Missing state parameter in the OAuth authorization response.")
51
- })
52
- },
53
- middlewares: [
54
- (ctx) => {
55
- const {
56
- searchParams,
57
- context: { logger }
58
- } = ctx;
59
- const response = OAuthAuthorizationErrorResponse.safeParse(searchParams);
60
- if (response.success) {
61
- const { error, error_description } = response.data;
62
- const criticalAuthErrors = ["access_denied", "server_error"];
63
- const severity = criticalAuthErrors.includes(error.toLowerCase()) ? "critical" : "warning";
64
- logger?.log("OAUTH_AUTHORIZATION_ERROR", {
65
- severity,
66
- structuredData: {
67
- error,
68
- error_description: error_description ?? ""
69
- }
70
- });
71
- throw new OAuthProtocolError(error, error_description || "OAuth Authorization Error");
72
- }
73
- return ctx;
74
- }
75
- ]
76
- });
77
- };
78
- var callbackAction = (oauth) => {
79
- return createEndpoint(
80
- "GET",
81
- "/callback/:oauth",
82
- async (ctx) => {
83
- const {
84
- request,
85
- params: { oauth: oauth2 },
86
- searchParams: { code, state },
87
- context
88
- } = ctx;
89
- const { oauth: providers, cookies, jose, logger, trustedOrigins } = context;
90
- const oauthConfig = providers[oauth2];
91
- const cookieState = getCookie(request, cookies.state.name);
92
- const codeVerifier = getCookie(request, cookies.codeVerifier.name);
93
- const cookieRedirectTo = getCookie(request, cookies.redirectTo.name);
94
- const cookieRedirectURI = getCookie(request, cookies.redirectURI.name);
95
- if (!safeEquals(cookieState, state)) {
96
- logger?.log("MISMATCHING_STATE", {
97
- structuredData: {
98
- oauth_provider: oauth2
99
- }
100
- });
101
- throw new AuthSecurityError(
102
- "MISMATCHING_STATE",
103
- "The provided state passed in the OAuth response does not match the stored state."
104
- );
105
- }
106
- const accessToken = await createAccessToken(oauthConfig, cookieRedirectURI, code, codeVerifier, logger);
107
- const origins = await getTrustedOrigins(request, trustedOrigins);
108
- const requestOrigin = await getOriginURL(request, context);
109
- if (!isRelativeURL(cookieRedirectTo)) {
110
- const isValid = origins.length > 0 ? isTrustedOrigin(cookieRedirectTo, origins) : isSameOrigin(cookieRedirectTo, requestOrigin);
111
- if (!isValid) {
112
- logger?.log("POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED", {
113
- structuredData: {
114
- redirect_path: cookieRedirectTo,
115
- provider: oauth2,
116
- has_trusted_origins: origins.length > 0,
117
- request_origin: requestOrigin
118
- }
119
- });
120
- throw new AuthSecurityError(
121
- "POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED",
122
- "Invalid redirect path. Potential open redirect attack detected."
123
- );
124
- }
125
- }
126
- const userInfo = await getUserInfo(oauthConfig, accessToken.access_token, logger);
127
- const sessionCookie = await createSessionCookie(jose, userInfo);
128
- const csrfToken = await createCSRF(jose);
129
- logger?.log("OAUTH_CALLBACK_SUCCESS", {
130
- structuredData: {
131
- provider: oauth2
132
- }
133
- });
134
- const headers = new 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();
135
- return Response.json({ oauth: oauth2 }, { status: 302, headers });
136
- },
137
- callbackConfig(oauth)
138
- );
139
- };
140
-
141
- export {
142
- callbackAction
143
- };