@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/signIn/signIn.ts
@@ -33,8 +23,7 @@ __export(signIn_exports, {
33
23
  signInAction: () => signInAction
34
24
  });
35
25
  module.exports = __toCommonJS(signIn_exports);
36
- var import_zod2 = require("zod");
37
- var import_router2 = require("@aura-stack/router");
26
+ var import_v42 = require("zod/v4");
38
27
 
39
28
  // src/headers.ts
40
29
  var cacheControl = {
@@ -43,12 +32,26 @@ var cacheControl = {
43
32
  Expires: "0",
44
33
  Vary: "Cookie"
45
34
  };
46
-
47
- // src/secure.ts
48
- var import_crypto = __toESM(require("crypto"), 1);
49
-
50
- // src/utils.ts
51
- var import_router = require("@aura-stack/router");
35
+ var contentSecurityPolicy = {
36
+ "Content-Security-Policy": [
37
+ "default-src 'none'",
38
+ "script-src 'self'",
39
+ "frame-src 'none'",
40
+ "object-src 'none'",
41
+ "frame-ancestors 'none'",
42
+ "base-uri 'none'"
43
+ ].join("; ")
44
+ };
45
+ var secureHeaders = {
46
+ "X-Content-Type-Options": "nosniff",
47
+ "X-Frame-Options": "DENY",
48
+ "Referrer-Policy": "strict-origin-when-cross-origin"
49
+ };
50
+ var secureApiHeaders = {
51
+ ...cacheControl,
52
+ ...contentSecurityPolicy,
53
+ ...secureHeaders
54
+ };
52
55
 
53
56
  // src/errors.ts
54
57
  var AuthInternalError = class extends Error {
@@ -71,129 +74,78 @@ var AuthSecurityError = class extends Error {
71
74
  Error.captureStackTrace(this, new.target);
72
75
  }
73
76
  };
74
- var isAuthSecurityError = (error) => {
75
- return error instanceof AuthSecurityError;
76
- };
77
-
78
- // src/utils.ts
79
- var toSnakeCase = (str) => {
80
- return str.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2").toLowerCase().replace(/^_+/, "");
81
- };
82
- var toUpperCase = (str) => {
83
- return str.toUpperCase();
84
- };
85
- var toCastCase = (obj, type = "snake") => {
86
- return Object.entries(obj).reduce((previous, [key, value]) => {
87
- const newKey = type === "snake" ? toSnakeCase(key) : toUpperCase(key);
88
- return { ...previous, [newKey]: value };
89
- }, {});
90
- };
91
- var equals = (a, b) => {
92
- if (a === null || b === null || a === void 0 || b === void 0) return false;
93
- return a === b;
94
- };
95
- var sanitizeURL = (url) => {
96
- try {
97
- let decodedURL = decodeURIComponent(url).trim();
98
- const protocolMatch = decodedURL.match(/^([a-zA-Z][a-zA-Z0-9+.-]*:\/\/)/);
99
- let protocol = "";
100
- let rest = decodedURL;
101
- if (protocolMatch) {
102
- protocol = protocolMatch[1];
103
- rest = decodedURL.slice(protocol.length);
104
- const slashIndex = rest.indexOf("/");
105
- if (slashIndex === -1) {
106
- return protocol + rest;
107
- }
108
- const domain = rest.slice(0, slashIndex);
109
- let path = rest.slice(slashIndex).replace(/\/\.\.\//g, "/").replace(/\/\.\.$/, "").replace(/\.{2,}/g, "").replace(/\/{2,}/g, "/");
110
- if (path !== "/" && path.endsWith("/")) {
111
- path = path.replace(/\/+$/, "/");
112
- } else if (path !== "/") {
113
- path = path.replace(/\/+$/, "");
114
- }
115
- return protocol + domain + path;
116
- }
117
- let sanitized = decodedURL.replace(/\/\.\.\//g, "/").replace(/\/\.\.$/, "").replace(/\.{2,}/g, "").replace(/\/{2,}/g, "/");
118
- if (sanitized !== "/" && sanitized.endsWith("/")) {
119
- sanitized = sanitized.replace(/\/+$/, "/");
120
- } else if (sanitized !== "/") {
121
- sanitized = sanitized.replace(/\/+$/, "");
122
- }
123
- return sanitized;
124
- } catch {
125
- return url.trim();
126
- }
127
- };
128
- var getNormalizedOriginPath = (path) => {
129
- try {
130
- const url = new URL(path);
131
- url.hash = "";
132
- url.search = "";
133
- return `${url.origin}${url.pathname}`;
134
- } catch {
135
- return sanitizeURL(path);
136
- }
137
- };
138
- var formatZodError = (error) => {
139
- if (!error.issues || error.issues.length === 0) {
140
- return {};
141
- }
142
- return error.issues.reduce((previous, issue) => {
143
- const key = issue.path.join(".");
144
- return {
145
- ...previous,
146
- [key]: {
147
- code: issue.code,
148
- message: issue.message
149
- }
150
- };
151
- }, {});
152
- };
153
77
 
154
- // src/assert.ts
155
- var isValidURL = (value) => {
156
- if (value.includes("\r\n") || value.includes("\n") || value.includes("\r")) return false;
157
- const regex = /^https?:\/\/(?:[a-zA-Z0-9._-]+|localhost|\[[0-9a-fA-F:]+\])(?::\d{1,5})?(?:\/[a-zA-Z0-9._~!$&'()*+,;=:@-]*)*\/?$/;
158
- return regex.test(value);
159
- };
160
-
161
- // src/secure.ts
162
- var generateSecure = (length = 32) => {
163
- return import_crypto.default.randomBytes(length).toString("base64url");
164
- };
165
- var createHash = (data, base = "hex") => {
166
- return import_crypto.default.createHash("sha256").update(data).digest().toString(base);
167
- };
168
- var createPKCE = async (verifier) => {
169
- const codeVerifier = verifier ?? generateSecure(86);
170
- const codeChallenge = createHash(codeVerifier, "base64url");
171
- return { codeVerifier, codeChallenge, method: "S256" };
172
- };
78
+ // src/api/signIn.ts
79
+ var import_router2 = require("@aura-stack/router");
173
80
 
174
81
  // src/schemas.ts
175
- var import_zod = require("zod");
176
- var OAuthProviderConfigSchema = (0, import_zod.object)({
177
- authorizeURL: (0, import_zod.string)().url(),
178
- accessToken: (0, import_zod.string)().url(),
179
- scope: (0, import_zod.string)().optional(),
180
- userInfo: (0, import_zod.string)().url(),
181
- responseType: (0, import_zod.enum)(["code", "token", "id_token"]),
182
- clientId: (0, import_zod.string)(),
183
- clientSecret: (0, import_zod.string)()
82
+ var import_v4 = require("zod/v4");
83
+ var AuthorizeConfigSchema = import_v4.z.union([
84
+ (0, import_v4.string)().url(),
85
+ (0, import_v4.object)({
86
+ url: (0, import_v4.string)().url(),
87
+ params: (0, import_v4.object)({
88
+ responseType: (0, import_v4.enum)(["code", "token", "id_token", "refresh_token"]).optional(),
89
+ scope: (0, import_v4.string)().optional()
90
+ })
91
+ })
92
+ ]);
93
+ var AccessTokenConfigSchema = import_v4.z.union([
94
+ (0, import_v4.string)().url(),
95
+ (0, import_v4.object)({
96
+ url: (0, import_v4.string)().url(),
97
+ headers: import_v4.z.record((0, import_v4.string)(), (0, import_v4.string)()).optional()
98
+ })
99
+ ]);
100
+ var UserInfoConfigSchema = import_v4.z.union([
101
+ (0, import_v4.string)().url(),
102
+ (0, import_v4.object)({
103
+ url: (0, import_v4.string)().url(),
104
+ headers: import_v4.z.record((0, import_v4.string)(), (0, import_v4.string)()).optional(),
105
+ method: (0, import_v4.string)().optional()
106
+ })
107
+ ]);
108
+ var OAuthProviderCredentialsSchema = (0, import_v4.object)({
109
+ id: (0, import_v4.string)(),
110
+ name: (0, import_v4.string)(),
111
+ authorize: AuthorizeConfigSchema.optional(),
112
+ /** @deprecated */
113
+ authorizeURL: (0, import_v4.string)().url().optional(),
114
+ accessToken: AccessTokenConfigSchema,
115
+ /** @deprecated */
116
+ scope: (0, import_v4.string)().optional(),
117
+ userInfo: UserInfoConfigSchema,
118
+ /** @deprecated */
119
+ responseType: (0, import_v4.enum)(["code", "token", "id_token", "refresh_token"]).optional(),
120
+ clientId: (0, import_v4.string)(),
121
+ clientSecret: (0, import_v4.string)(),
122
+ profile: import_v4.z.function().optional()
123
+ });
124
+ var OAuthProviderConfigSchema = (0, import_v4.object)({
125
+ authorize: AuthorizeConfigSchema.optional(),
126
+ /** @deprecated */
127
+ authorizeURL: (0, import_v4.string)().url().optional(),
128
+ accessToken: AccessTokenConfigSchema,
129
+ /** @deprecated */
130
+ scope: (0, import_v4.string)().optional(),
131
+ userInfo: UserInfoConfigSchema,
132
+ /** @deprecated */
133
+ responseType: (0, import_v4.enum)(["code", "token", "id_token", "refresh_token"]).optional(),
134
+ clientId: (0, import_v4.string)(),
135
+ clientSecret: (0, import_v4.string)()
184
136
  });
185
137
  var OAuthAuthorization = OAuthProviderConfigSchema.extend({
186
- redirectURI: (0, import_zod.string)(),
187
- state: (0, import_zod.string)(),
188
- codeChallenge: (0, import_zod.string)(),
189
- codeChallengeMethod: (0, import_zod.enum)(["plain", "S256"])
138
+ redirectURI: (0, import_v4.string)(),
139
+ state: (0, import_v4.string)(),
140
+ codeChallenge: (0, import_v4.string)(),
141
+ codeChallengeMethod: (0, import_v4.enum)(["plain", "S256"])
190
142
  });
191
- var OAuthAuthorizationResponse = (0, import_zod.object)({
192
- state: (0, import_zod.string)({ message: "Missing state parameter in the OAuth authorization response." }),
193
- code: (0, import_zod.string)({ message: "Missing code parameter in the OAuth authorization response." })
143
+ var OAuthAuthorizationResponse = (0, import_v4.object)({
144
+ state: (0, import_v4.string)({ message: "Missing state parameter in the OAuth authorization response." }),
145
+ code: (0, import_v4.string)({ message: "Missing code parameter in the OAuth authorization response." })
194
146
  });
195
- var OAuthAuthorizationErrorResponse = (0, import_zod.object)({
196
- error: (0, import_zod.enum)([
147
+ var OAuthAuthorizationErrorResponse = (0, import_v4.object)({
148
+ error: (0, import_v4.enum)([
197
149
  "invalid_request",
198
150
  "unauthorized_client",
199
151
  "access_denied",
@@ -202,24 +154,24 @@ var OAuthAuthorizationErrorResponse = (0, import_zod.object)({
202
154
  "server_error",
203
155
  "temporarily_unavailable"
204
156
  ]),
205
- error_description: (0, import_zod.string)().optional(),
206
- error_uri: (0, import_zod.string)().optional(),
207
- state: (0, import_zod.string)()
157
+ error_description: (0, import_v4.string)().optional(),
158
+ error_uri: (0, import_v4.string)().optional(),
159
+ state: (0, import_v4.string)()
208
160
  });
209
161
  var OAuthAccessToken = OAuthProviderConfigSchema.extend({
210
- redirectURI: (0, import_zod.string)(),
211
- code: (0, import_zod.string)(),
212
- codeVerifier: (0, import_zod.string)().min(43).max(128)
162
+ redirectURI: (0, import_v4.string)(),
163
+ code: (0, import_v4.string)(),
164
+ codeVerifier: (0, import_v4.string)().min(43).max(128)
213
165
  });
214
- var OAuthAccessTokenResponse = (0, import_zod.object)({
215
- access_token: (0, import_zod.string)(),
216
- token_type: (0, import_zod.string)().optional(),
217
- expires_in: (0, import_zod.number)().optional(),
218
- refresh_token: (0, import_zod.string)().optional(),
219
- scope: (0, import_zod.string)().optional().or((0, import_zod.null)())
166
+ var OAuthAccessTokenResponse = (0, import_v4.object)({
167
+ access_token: (0, import_v4.string)(),
168
+ token_type: (0, import_v4.string)().optional(),
169
+ expires_in: (0, import_v4.number)().optional(),
170
+ refresh_token: (0, import_v4.string)().optional(),
171
+ scope: (0, import_v4.union)([(0, import_v4.string)().optional().or((0, import_v4.null)()), (0, import_v4.array)((0, import_v4.string)()).optional()])
220
172
  });
221
- var OAuthAccessTokenErrorResponse = (0, import_zod.object)({
222
- error: (0, import_zod.enum)([
173
+ var OAuthAccessTokenErrorResponse = (0, import_v4.object)({
174
+ error: (0, import_v4.enum)([
223
175
  "invalid_request",
224
176
  "invalid_client",
225
177
  "invalid_grant",
@@ -227,129 +179,412 @@ var OAuthAccessTokenErrorResponse = (0, import_zod.object)({
227
179
  "unsupported_grant_type",
228
180
  "invalid_scope"
229
181
  ]),
230
- error_description: (0, import_zod.string)().optional(),
231
- error_uri: (0, import_zod.string)().optional()
182
+ error_description: (0, import_v4.string)().optional(),
183
+ error_uri: (0, import_v4.string)().optional()
232
184
  });
233
- var OAuthErrorResponse = (0, import_zod.object)({
234
- error: (0, import_zod.string)(),
235
- error_description: (0, import_zod.string)().optional()
185
+ var OAuthErrorResponse = (0, import_v4.object)({
186
+ error: (0, import_v4.string)(),
187
+ error_description: (0, import_v4.string)().optional()
236
188
  });
237
- var OAuthEnvSchema = (0, import_zod.object)({
238
- clientId: import_zod.z.string().min(1, "OAuth Client ID is required in the environment variables."),
239
- clientSecret: import_zod.z.string().min(1, "OAuth Client Secret is required in the environment variables.")
189
+ var OAuthEnvSchema = (0, import_v4.object)({
190
+ clientId: import_v4.z.string().min(1, "OAuth Client ID is required in the environment variables."),
191
+ clientSecret: import_v4.z.string().min(1, "OAuth Client Secret is required in the environment variables.")
240
192
  });
241
193
 
242
- // src/actions/signIn/authorization.ts
243
- var createAuthorizationURL = (oauthConfig, redirectURI, state, codeChallenge, codeChallengeMethod) => {
244
- const parsed = OAuthAuthorization.safeParse({ ...oauthConfig, redirectURI, state, codeChallenge, codeChallengeMethod });
245
- if (!parsed.success) {
246
- const msg = JSON.stringify(formatZodError(parsed.error), null, 2);
247
- throw new AuthInternalError("INVALID_OAUTH_CONFIGURATION", msg);
194
+ // src/utils.ts
195
+ var import_router = require("@aura-stack/router");
196
+
197
+ // src/env.ts
198
+ var import_meta = {};
199
+ var env = new Proxy({}, {
200
+ get(_, prop) {
201
+ if (typeof prop !== "string") return void 0;
202
+ const hasProperty = (process2) => {
203
+ return process2 && Object.prototype.hasOwnProperty.call(process2, prop);
204
+ };
205
+ try {
206
+ if (typeof process !== "undefined" && hasProperty(process.env)) {
207
+ return process.env[prop];
208
+ }
209
+ if (typeof import_meta !== "undefined" && hasProperty(import_meta.env)) {
210
+ return import_meta.env[prop];
211
+ }
212
+ if (typeof Deno !== "undefined" && Deno.env?.get) {
213
+ return Deno.env.get(prop);
214
+ }
215
+ if (typeof Bun !== "undefined" && hasProperty(Bun.env)) {
216
+ return Bun.env[prop];
217
+ }
218
+ const globalValue = globalThis[prop];
219
+ return typeof globalValue === "string" ? globalValue : void 0;
220
+ } catch {
221
+ return void 0;
222
+ }
248
223
  }
249
- const { authorizeURL, ...options2 } = parsed.data;
250
- const { userInfo, accessToken, clientSecret, ...required } = options2;
251
- const searchParams = new URLSearchParams(toCastCase(required));
252
- return `${authorizeURL}?${searchParams}`;
253
- };
254
- var getOriginURL = (request, trustedProxyHeaders) => {
255
- const headers = request.headers;
256
- if (trustedProxyHeaders) {
257
- const protocol = headers.get("X-Forwarded-Proto") ?? headers.get("Forwarded")?.match(/proto=([^;]+)/i)?.[1] ?? "http";
258
- const host = headers.get("X-Forwarded-Host") ?? headers.get("Host") ?? headers.get("Forwarded")?.match(/host=([^;]+)/i)?.[1] ?? null;
259
- return new URL(`${protocol}://${host}${getNormalizedOriginPath(new URL(request.url).pathname)}`);
260
- } else {
261
- return new URL(getNormalizedOriginPath(request.url));
224
+ });
225
+ var getEnv = (key) => {
226
+ const keys = [`AURA_AUTH_${key.toUpperCase()}`, `AURA_${key.toUpperCase()}`, `AUTH_${key.toUpperCase()}`, key.toUpperCase()];
227
+ return env[keys.find((k) => env[k]) ?? ""];
228
+ };
229
+
230
+ // src/assert.ts
231
+ var import_crypto = require("@aura-stack/jose/crypto");
232
+ var unsafeChars = [
233
+ "<",
234
+ ">",
235
+ '"',
236
+ "`",
237
+ " ",
238
+ "\r",
239
+ "\n",
240
+ " ",
241
+ "\\",
242
+ "%2F",
243
+ "%5C",
244
+ "%2f",
245
+ "%5c",
246
+ "\r\n",
247
+ "%0A",
248
+ "%0D",
249
+ "%0a",
250
+ "%0d",
251
+ "..",
252
+ "//",
253
+ "///",
254
+ "...",
255
+ "%20",
256
+ "\0"
257
+ ];
258
+ var isValidURL = (value) => {
259
+ if (!new RegExp(/^https?:\/\/[^/]/).test(value)) {
260
+ return false;
262
261
  }
262
+ const match = value.match(/^(https?:\/\/)(.*)$/);
263
+ if (!match) return false;
264
+ const rest = match[2];
265
+ for (const char of unsafeChars) {
266
+ if (rest.includes(char)) return false;
267
+ }
268
+ const regex = /^https?:\/\/(?:[a-zA-Z0-9._-]+|localhost|\[[0-9a-fA-F:]+\])(?::\d{1,5})?(?:\/[a-zA-Z0-9._~!$&'()?#*+,;=:@-]*)*\/?$/;
269
+ return regex.test(match[0]);
270
+ };
271
+ var isRelativeURL = (value) => {
272
+ if (value.length > 100) return false;
273
+ for (const char of unsafeChars) {
274
+ if (value.includes(char)) return false;
275
+ }
276
+ const regex = /^\/[a-zA-Z0-9\-_\/.?&=#]*\/?$/;
277
+ return regex.test(value);
263
278
  };
264
- var createRedirectURI = (request, oauth, basePath, trustedProxyHeaders) => {
265
- const url = getOriginURL(request, trustedProxyHeaders);
266
- return `${url.origin}${basePath}/callback/${oauth}`;
279
+ var isSameOrigin = (origin, expected) => {
280
+ const originURL = new URL(origin);
281
+ const expectedURL = new URL(expected);
282
+ return equals(originURL.origin, expectedURL.origin);
267
283
  };
268
- var createRedirectTo = (request, redirectTo, trustedProxyHeaders) => {
284
+ var patternToRegex = (pattern) => {
269
285
  try {
270
- const headers = request.headers;
271
- const origin = headers.get("Origin");
272
- const referer = headers.get("Referer");
273
- let hostedURL = getOriginURL(request, trustedProxyHeaders);
274
- if (redirectTo) {
275
- if (redirectTo.startsWith("/")) {
276
- return sanitizeURL(redirectTo);
277
- }
278
- const redirectToURL = new URL(sanitizeURL(getNormalizedOriginPath(redirectTo)));
279
- if (!isValidURL(redirectTo) || !equals(redirectToURL.origin, hostedURL.origin)) {
280
- throw new AuthSecurityError(
281
- "POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED",
282
- "The redirectTo parameter does not match the hosted origin."
283
- );
286
+ if (pattern.length > 2048) return null;
287
+ pattern = pattern.replace(/\\/g, "");
288
+ const match = pattern.match(/^(https?):\/\/([a-zA-Z0-9.*-]{1,253})(?::(\d{1,5}|\*))?(?:\/.*)?$/);
289
+ if (!match) return null;
290
+ const [, protocol, host, port] = match;
291
+ const hasWildcard = host.includes("*");
292
+ if (hasWildcard && !host.startsWith("*.")) return null;
293
+ if (hasWildcard && host.slice(2).includes("*")) return null;
294
+ const domain = hasWildcard ? host.slice(2) : host;
295
+ const escapedDomain = domain.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
296
+ const hostRegex = hasWildcard ? `[^.]+\\.${escapedDomain}` : escapedDomain;
297
+ const portRegex = port === "*" ? ":\\d{1,5}" : port ? `:${port}` : "";
298
+ return new RegExp(`^${protocol}:\\/\\/${hostRegex}${portRegex}$`);
299
+ } catch {
300
+ return null;
301
+ }
302
+ };
303
+ var isTrustedOrigin = (url, trustedOrigins) => {
304
+ if (!isValidURL(url) || trustedOrigins.length === 0) return false;
305
+ try {
306
+ const urlOrigin = new URL(url).origin;
307
+ for (const pattern of trustedOrigins) {
308
+ const regex = patternToRegex(pattern);
309
+ if (regex?.test(urlOrigin)) return true;
310
+ try {
311
+ if (isValidURL(pattern) && equals(new URL(pattern).origin, urlOrigin)) return true;
312
+ } catch {
284
313
  }
285
- return sanitizeURL(redirectToURL.pathname);
286
314
  }
287
- if (referer) {
288
- const refererURL = new URL(sanitizeURL(referer));
289
- if (!isValidURL(referer) || !equals(refererURL.origin, hostedURL.origin)) {
290
- throw new AuthSecurityError(
291
- "POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED",
292
- "The referer of the request does not match the hosted origin."
293
- );
294
- }
295
- return sanitizeURL(refererURL.pathname);
315
+ } catch {
316
+ }
317
+ return false;
318
+ };
319
+
320
+ // src/utils.ts
321
+ var equals = (a, b) => {
322
+ if (a === null || b === null || a === void 0 || b === void 0) return false;
323
+ return a === b;
324
+ };
325
+ var extractPath = (url) => {
326
+ const pathRegex = /^https?:\/\/[a-zA-Z0-9_\-\.]+(:\d+)?(\/.*)$/;
327
+ const match = url.match(pathRegex);
328
+ return match && match[2] ? match[2] : "/";
329
+ };
330
+
331
+ // src/jose.ts
332
+ var import_jose = require("@aura-stack/jose");
333
+ var import_jose2 = require("@aura-stack/jose/jose");
334
+ var import_crypto2 = require("@aura-stack/jose/crypto");
335
+
336
+ // src/secure.ts
337
+ var generateSecure = (length = 32) => {
338
+ return import_jose2.base64url.encode((0, import_crypto2.getRandomBytes)(length));
339
+ };
340
+ var createSecretValue = (length = 32) => {
341
+ return import_jose2.base64url.encode((0, import_crypto2.getRandomBytes)(length));
342
+ };
343
+ var createHash = async (data) => {
344
+ const subtle = (0, import_crypto2.getSubtleCrypto)();
345
+ const digest = await subtle.digest("SHA-256", import_crypto2.encoder.encode(data));
346
+ return import_jose2.base64url.encode(new Uint8Array(digest));
347
+ };
348
+ var createPKCE = async (verifier) => {
349
+ const byteLength = verifier ? void 0 : Math.floor(Math.random() * (96 - 32 + 1) + 32);
350
+ const codeVerifier = verifier ?? generateSecure(byteLength ?? 64);
351
+ if (codeVerifier.length < 43 || codeVerifier.length > 128) {
352
+ throw new AuthSecurityError("PKCE_VERIFIER_INVALID", "The code verifier must be between 43 and 128 characters in length.");
353
+ }
354
+ const codeChallenge = await createHash(codeVerifier);
355
+ return { codeVerifier, codeChallenge, method: "S256" };
356
+ };
357
+
358
+ // src/actions/signIn/authorization-url.ts
359
+ var setSearchParams = (url, params) => {
360
+ for (const [key, value] of Object.entries(params)) {
361
+ if (value !== void 0 && value !== "") {
362
+ url.searchParams.set(key, value);
296
363
  }
297
- if (origin) {
298
- const originURL = new URL(sanitizeURL(getNormalizedOriginPath(origin)));
299
- if (!isValidURL(origin) || !equals(originURL.origin, hostedURL.origin)) {
300
- throw new AuthSecurityError("POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED", "Invalid origin (potential CSRF).");
364
+ }
365
+ };
366
+ var buildAuthorizationURL = (oauth, redirect_uri, state, code_challenge, code_challenge_method) => {
367
+ const authorizeConfig = oauth.authorize;
368
+ const baseURL = typeof authorizeConfig === "string" ? authorizeConfig : authorizeConfig?.url ?? oauth.authorizeURL;
369
+ if (!baseURL) {
370
+ throw new AuthInternalError("INVALID_OAUTH_CONFIGURATION", "Missing authorization URL in OAuth provider configuration.");
371
+ }
372
+ const url = new URL(baseURL);
373
+ const authorizeParams = typeof authorizeConfig === "string" ? void 0 : authorizeConfig?.params;
374
+ setSearchParams(url, {
375
+ response_type: authorizeParams?.responseType ?? oauth.responseType ?? "code",
376
+ client_id: oauth.clientId,
377
+ redirect_uri,
378
+ state,
379
+ code_challenge,
380
+ code_challenge_method,
381
+ scope: authorizeParams?.scope ?? oauth.scope,
382
+ prompt: authorizeParams?.prompt,
383
+ response_mode: authorizeParams?.responseMode,
384
+ login_hint: authorizeParams?.loginHint,
385
+ nonce: authorizeParams?.nonce,
386
+ display: authorizeParams?.display,
387
+ audience: authorizeParams?.audience
388
+ });
389
+ return url.toString();
390
+ };
391
+ var createAuthorizationURL = async (oauth, redirectURI, ctx) => {
392
+ const state = createSecretValue();
393
+ const { codeVerifier, codeChallenge, method } = await createPKCE();
394
+ const authorization = buildAuthorizationURL(oauth, redirectURI, state, codeChallenge, method);
395
+ const parsed = OAuthAuthorization.safeParse({ ...oauth, redirectURI, state, codeChallenge, codeChallengeMethod: method });
396
+ if (!parsed.success) {
397
+ ctx?.logger?.log("INVALID_OAUTH_CONFIGURATION", {
398
+ structuredData: {
399
+ scope: oauth?.scope ?? "",
400
+ redirect_uri: redirectURI,
401
+ has_state: Boolean(state),
402
+ has_code_challenge: Boolean(codeChallenge),
403
+ code_challenge_method: method
301
404
  }
302
- return sanitizeURL(originURL.pathname);
303
- }
304
- return "/";
405
+ });
406
+ throw new AuthInternalError("INVALID_OAUTH_CONFIGURATION", "The OAuth provider configuration is invalid.");
407
+ }
408
+ return {
409
+ authorization,
410
+ state,
411
+ codeVerifier,
412
+ method
413
+ };
414
+ };
415
+
416
+ // src/actions/signIn/authorization.ts
417
+ var getTrustedOrigins = async (request, trustedOrigins) => {
418
+ if (!trustedOrigins) return [];
419
+ const raw = typeof trustedOrigins === "function" ? await trustedOrigins(request) : trustedOrigins;
420
+ return Array.isArray(raw) ? raw : typeof raw === "string" ? [raw] : [];
421
+ };
422
+ var getBaseURL = async ({
423
+ ctx,
424
+ request,
425
+ headers: headersInit
426
+ }) => {
427
+ const origin = getEnv("BASE_URL") || ctx?.baseURL;
428
+ if (origin && origin !== "/") return origin;
429
+ if (ctx?.trustedProxyHeaders) {
430
+ const headers = headersInit && new Headers(headersInit) || request?.headers;
431
+ const protocol = headers?.get("Forwarded")?.match(/proto=([^;]+)/i)?.[1] ?? headers?.get("X-Forwarded-Proto") ?? "http";
432
+ const host = headers?.get("Host") ?? headers?.get("Forwarded")?.match(/host=([^;]+)/i)?.[1] ?? headers?.get("X-Forwarded-Host") ?? null;
433
+ if (host) return `${protocol}://${host}`;
434
+ throw new AuthInternalError(
435
+ "INVALID_OAUTH_CONFIGURATION",
436
+ "The URL cannot be constructed. Please set the BASE_URL environment variable or provide trusted proxy host headers."
437
+ );
438
+ }
439
+ try {
440
+ return new URL(request?.url ?? "not-found").origin;
305
441
  } catch (error) {
306
- if (isAuthSecurityError(error)) {
307
- throw error;
308
- }
309
- throw new AuthSecurityError("POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED", "Invalid origin (potential CSRF).");
442
+ throw new AuthInternalError(
443
+ "INVALID_OAUTH_CONFIGURATION",
444
+ "The URL cannot be constructed. Please set the BASE_URL environment variable or enable trustedProxyHeaders.",
445
+ { cause: error }
446
+ );
447
+ }
448
+ };
449
+ var getOriginURL = async (request, context) => {
450
+ const trustedOrigins = await getTrustedOrigins(request, context?.trustedOrigins);
451
+ trustedOrigins.push(new URL(request.url).origin);
452
+ const origin = await getBaseURL({ request, ctx: context });
453
+ if (!isTrustedOrigin(origin, trustedOrigins)) {
454
+ context?.logger?.log("UNTRUSTED_ORIGIN", { structuredData: { origin } });
455
+ throw new AuthInternalError("UNTRUSTED_ORIGIN", "The constructed origin URL is not trusted.");
456
+ }
457
+ return origin;
458
+ };
459
+ var createRedirectURI = async (request, oauth, context) => {
460
+ const origin = await getOriginURL(request, context);
461
+ return `${origin}${context.basePath}/callback/${oauth}`;
462
+ };
463
+ var createSignInURL = async ({
464
+ request,
465
+ oauth,
466
+ ctx,
467
+ redirectTo
468
+ }) => {
469
+ const origin = await getOriginURL(request, ctx);
470
+ const searchParams = new URLSearchParams();
471
+ if (redirectTo !== void 0) searchParams.set("redirectTo", String(redirectTo));
472
+ return `${origin}${ctx.basePath}/signIn/${oauth}?${searchParams.toString()}`;
473
+ };
474
+ var createRedirectTo = async (request, redirectTo, context) => {
475
+ try {
476
+ const headers = request.headers;
477
+ const requestOrigin = await getOriginURL(request, context);
478
+ const origins = await getTrustedOrigins(request, context?.trustedOrigins);
479
+ const validateURL = (url) => {
480
+ if (!isRelativeURL(url) && !isValidURL(url)) return "/";
481
+ if (isRelativeURL(url)) return url;
482
+ if (origins.length > 0) {
483
+ if (isTrustedOrigin(url, origins)) {
484
+ const urlOrigin = new URL(url).origin;
485
+ for (const pattern of origins) {
486
+ const regex = patternToRegex(pattern);
487
+ if (regex?.test(urlOrigin)) {
488
+ return isSameOrigin(url, request.url) ? extractPath(url) : url;
489
+ }
490
+ if (isValidURL(pattern) && equals(new URL(pattern).origin, urlOrigin)) return url;
491
+ }
492
+ }
493
+ context?.logger?.log("OPEN_REDIRECT_ATTACK");
494
+ return "/";
495
+ }
496
+ if (isSameOrigin(url, requestOrigin)) {
497
+ return extractPath(url);
498
+ }
499
+ context?.logger?.log("OPEN_REDIRECT_ATTACK");
500
+ return "/";
501
+ };
502
+ return validateURL(redirectTo ?? headers.get("Referer") ?? headers.get("Origin") ?? "/");
503
+ } catch (error) {
504
+ context?.logger?.log("POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED");
505
+ return "/";
310
506
  }
311
507
  };
312
508
 
509
+ // src/api/signIn.ts
510
+ var signIn = async (oauth, {
511
+ ctx,
512
+ headers: headersInit,
513
+ redirectTo = "/",
514
+ redirect,
515
+ request: requestInit
516
+ }) => {
517
+ const headers = new Headers(headersInit);
518
+ const provider = ctx.oauth[oauth];
519
+ if (!provider) {
520
+ throw new AuthInternalError("INVALID_OAUTH_CONFIGURATION", `The OAuth provider "${oauth}" is not configured.`);
521
+ }
522
+ let request = requestInit;
523
+ if (!request) {
524
+ const origin = await getBaseURL({ ctx, headers });
525
+ const url = `${origin}${ctx.basePath}/signIn/${oauth}`;
526
+ request = new Request(url, { headers });
527
+ }
528
+ if (redirect === false) {
529
+ const signInURL = await createSignInURL({ request, oauth, ctx, redirectTo });
530
+ return { redirect: false, signInURL };
531
+ }
532
+ const redirectURI = await createRedirectURI(request, oauth, ctx);
533
+ const redirectToValue = await createRedirectTo(request, redirectTo, ctx);
534
+ const { authorization, state, codeVerifier } = await createAuthorizationURL(provider, redirectURI, ctx);
535
+ ctx?.logger?.log("SIGN_IN_INITIATED", {
536
+ structuredData: { oauth_provider: oauth }
537
+ });
538
+ const headersList = new import_router2.HeadersBuilder(cacheControl).setHeader("Location", authorization).setCookie(ctx.cookies.state.name, state, ctx.cookies.state.attributes).setCookie(ctx.cookies.redirectURI.name, redirectURI, ctx.cookies.redirectURI.attributes).setCookie(ctx.cookies.redirectTo.name, redirectToValue, ctx.cookies.redirectTo.attributes).setCookie(ctx.cookies.codeVerifier.name, codeVerifier, ctx.cookies.codeVerifier.attributes).toHeaders();
539
+ return Response.json(
540
+ { redirect: redirect ?? true, signInURL: authorization },
541
+ {
542
+ status: redirect ?? true ? 302 : 200,
543
+ headers: headersList
544
+ }
545
+ );
546
+ };
547
+
313
548
  // src/actions/signIn/signIn.ts
549
+ var import_router3 = require("@aura-stack/router");
314
550
  var signInConfig = (oauth) => {
315
- return (0, import_router2.createEndpointConfig)("/signIn/:oauth", {
551
+ return (0, import_router3.createEndpointConfig)("/signIn/:oauth", {
316
552
  schemas: {
317
- params: import_zod2.z.object({
318
- oauth: import_zod2.z.enum(
553
+ params: import_v42.z.object({
554
+ oauth: import_v42.z.enum(
319
555
  Object.keys(oauth),
320
556
  "The OAuth provider is not supported or invalid."
321
557
  )
322
558
  }),
323
- searchParams: import_zod2.z.object({
324
- redirectTo: import_zod2.z.string().optional()
559
+ searchParams: import_v42.z.object({
560
+ redirect: import_v42.z.stringbool().optional().default(true),
561
+ redirectTo: import_v42.z.string().optional()
325
562
  })
326
563
  }
327
564
  });
328
565
  };
329
566
  var signInAction = (oauth) => {
330
- return (0, import_router2.createEndpoint)(
567
+ return (0, import_router3.createEndpoint)(
331
568
  "GET",
332
569
  "/signIn/:oauth",
333
570
  async (ctx) => {
334
571
  const {
335
572
  request,
336
573
  params: { oauth: oauth2 },
337
- searchParams: { redirectTo },
338
- context: { oauth: providers, cookies, trustedProxyHeaders, basePath }
574
+ searchParams: { redirectTo, redirect },
575
+ context
339
576
  } = ctx;
340
- const state = generateSecure();
341
- const redirectURI = createRedirectURI(request, oauth2, basePath, trustedProxyHeaders);
342
- const redirectToValue = createRedirectTo(request, redirectTo, trustedProxyHeaders);
343
- const { codeVerifier, codeChallenge, method } = await createPKCE();
344
- const authorization = createAuthorizationURL(providers[oauth2], redirectURI, state, codeChallenge, method);
345
- const headers = new import_router2.HeadersBuilder(cacheControl).setHeader("Location", authorization).setCookie(cookies.state.name, state, cookies.state.attributes).setCookie(cookies.redirectURI.name, redirectURI, cookies.redirectURI.attributes).setCookie(cookies.redirectTo.name, redirectToValue, cookies.redirectTo.attributes).setCookie(cookies.codeVerifier.name, codeVerifier, cookies.codeVerifier.attributes).toHeaders();
346
- return Response.json(
347
- { oauth: oauth2 },
348
- {
349
- status: 302,
350
- headers
351
- }
352
- );
577
+ const signInResult = await signIn(oauth2, {
578
+ ctx: context,
579
+ headers: request.headers,
580
+ redirect,
581
+ redirectTo,
582
+ request
583
+ });
584
+ if (!redirect) {
585
+ return Response.json(signInResult, { status: 200 });
586
+ }
587
+ return signInResult;
353
588
  },
354
589
  signInConfig(oauth)
355
590
  );