@aura-stack/auth 0.2.0 → 0.3.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 (76) hide show
  1. package/dist/@types/index.d.ts +3 -2
  2. package/dist/@types/router.d.d.ts +3 -2
  3. package/dist/actions/callback/access-token.cjs +52 -41
  4. package/dist/actions/callback/access-token.d.ts +5 -4
  5. package/dist/actions/callback/access-token.js +3 -2
  6. package/dist/actions/callback/callback.cjs +69 -52
  7. package/dist/actions/callback/callback.d.ts +4 -3
  8. package/dist/actions/callback/callback.js +6 -5
  9. package/dist/actions/callback/userinfo.cjs +54 -43
  10. package/dist/actions/callback/userinfo.d.ts +3 -2
  11. package/dist/actions/callback/userinfo.js +3 -2
  12. package/dist/actions/csrfToken/csrfToken.cjs +2 -2
  13. package/dist/actions/csrfToken/csrfToken.js +2 -2
  14. package/dist/actions/index.cjs +93 -71
  15. package/dist/actions/index.d.ts +3 -2
  16. package/dist/actions/index.js +15 -14
  17. package/dist/actions/session/session.js +2 -2
  18. package/dist/actions/signIn/authorization.cjs +40 -40
  19. package/dist/actions/signIn/authorization.d.ts +3 -2
  20. package/dist/actions/signIn/authorization.js +2 -2
  21. package/dist/actions/signIn/signIn.cjs +63 -50
  22. package/dist/actions/signIn/signIn.d.ts +4 -3
  23. package/dist/actions/signIn/signIn.js +4 -3
  24. package/dist/actions/signOut/signOut.cjs +66 -66
  25. package/dist/actions/signOut/signOut.js +4 -4
  26. package/dist/assert.d.ts +3 -2
  27. package/dist/{chunk-2RXNXMCZ.js → chunk-3EUWD5BB.js} +15 -7
  28. package/dist/{chunk-NEVKX6K2.js → chunk-A3N4PVAT.js} +3 -3
  29. package/dist/chunk-B737EUJV.js +22 -0
  30. package/dist/{chunk-7H3OR6UU.js → chunk-EMKJA2GJ.js} +18 -10
  31. package/dist/{chunk-4V4JNXVF.js → chunk-GA2SMTJO.js} +9 -6
  32. package/dist/chunk-HP34YGGJ.js +22 -0
  33. package/dist/{chunk-QDO2KSRJ.js → chunk-HT4YLL7N.js} +1 -1
  34. package/dist/{chunk-ZLR3LI6X.js → chunk-IVET23KF.js} +7 -4
  35. package/dist/{chunk-PTJUYB33.js → chunk-JVFTCTTE.js} +1 -1
  36. package/dist/{chunk-UEH3LVON.js → chunk-KSWLO5ZU.js} +21 -16
  37. package/dist/{chunk-QEZL7EYN.js → chunk-N4SX7TZT.js} +3 -3
  38. package/dist/{chunk-IMICRJ5U.js → chunk-W6LG7BFW.js} +14 -14
  39. package/dist/{chunk-WD7AUHQ5.js → chunk-YRCB5FLE.js} +8 -8
  40. package/dist/chunk-ZNCZVF6U.js +14 -0
  41. package/dist/cookie.cjs +14 -14
  42. package/dist/cookie.d.ts +3 -2
  43. package/dist/cookie.js +1 -1
  44. package/dist/errors.d.ts +3 -2
  45. package/dist/{index-EqsoyjrF.d.ts → index-DkaLJFn8.d.ts} +57 -8
  46. package/dist/index.cjs +155 -93
  47. package/dist/index.d.ts +4 -3
  48. package/dist/index.js +20 -17
  49. package/dist/jose.cjs +2 -2
  50. package/dist/oauth/bitbucket.d.ts +3 -2
  51. package/dist/oauth/discord.d.ts +3 -2
  52. package/dist/oauth/figma.d.ts +3 -2
  53. package/dist/oauth/github.d.ts +3 -2
  54. package/dist/oauth/gitlab.d.ts +3 -2
  55. package/dist/oauth/index.cjs +85 -41
  56. package/dist/oauth/index.d.ts +3 -2
  57. package/dist/oauth/index.js +16 -8
  58. package/dist/oauth/mailchimp.cjs +46 -0
  59. package/dist/oauth/mailchimp.d.ts +7 -0
  60. package/dist/oauth/mailchimp.js +6 -0
  61. package/dist/oauth/pinterest.cjs +46 -0
  62. package/dist/oauth/pinterest.d.ts +7 -0
  63. package/dist/oauth/pinterest.js +6 -0
  64. package/dist/oauth/spotify.d.ts +3 -2
  65. package/dist/oauth/strava.d.ts +3 -2
  66. package/dist/oauth/x.d.ts +3 -2
  67. package/dist/request.cjs +38 -0
  68. package/dist/request.d.ts +13 -0
  69. package/dist/request.js +6 -0
  70. package/dist/schemas.cjs +40 -40
  71. package/dist/schemas.d.ts +15 -15
  72. package/dist/schemas.js +1 -1
  73. package/dist/secure.cjs +5 -5
  74. package/dist/secure.d.ts +3 -2
  75. package/dist/utils.d.ts +3 -3
  76. package/package.json +6 -4
@@ -1,6 +1,7 @@
1
- import 'zod/v4';
1
+ import 'zod';
2
2
  import '../schemas.js';
3
3
  import '@aura-stack/router/cookie';
4
+ import '@aura-stack/jose';
4
5
  import '@aura-stack/jose/jose';
5
- export { i as APIErrorMap, V as AccessTokenError, d as AuthConfig, e as AuthInstance, b as AuthInternalErrorCode, A as AuthRuntimeConfig, c as AuthSecurityErrorCode, T as AuthorizationError, C as CookieConfig, P as CookieName, a as CookieStoreConfig, M as CookieStrategyAttributes, E as ErrorType, K as HostCookie, J as JWTPayloadWithToken, z as JWTStandardClaims, f as JoseInstance, Y as OAuthEnv, Q as OAuthError, O as OAuthProvider, g as OAuthProviderConfig, h as OAuthProviderCredentials, R as RouterGlobalContext, H as SecureCookie, S as Session, L as StandardCookie, W as TokenRevocationError, U as User } from '../index-EqsoyjrF.js';
6
+ export { i as APIErrorMap, a0 as AccessTokenError, d as AuthConfig, e as AuthInstance, b as AuthInternalErrorCode, A as AuthRuntimeConfig, c as AuthSecurityErrorCode, $ as AuthorizationError, C as CookieConfig, Z as CookieName, a as CookieStoreConfig, Y as CookieStrategyAttributes, E as ErrorType, V as HostCookie, J as JWTPayloadWithToken, Q as JWTStandardClaims, f as JoseInstance, a2 as OAuthEnv, _ as OAuthError, O as OAuthProvider, g as OAuthProviderConfig, h as OAuthProviderCredentials, j as OAuthProviderRecord, R as RouterGlobalContext, T as SecureCookie, S as Session, W as StandardCookie, a1 as TokenRevocationError, U as User } from '../index-DkaLJFn8.js';
6
7
  export { LiteralUnion, Prettify } from './utility.js';
@@ -1,7 +1,8 @@
1
- import { R as RouterGlobalContext } from '../index-EqsoyjrF.js';
2
- import 'zod/v4';
1
+ import { R as RouterGlobalContext } from '../index-DkaLJFn8.js';
2
+ import 'zod';
3
3
  import '../schemas.js';
4
4
  import '@aura-stack/router/cookie';
5
+ import '@aura-stack/jose';
5
6
  import '@aura-stack/jose/jose';
6
7
  import './utility.js';
7
8
 
@@ -24,6 +24,17 @@ __export(access_token_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(access_token_exports);
26
26
 
27
+ // src/request.ts
28
+ var fetchAsync = async (url, options2 = {}, timeout = 5e3) => {
29
+ const controller = new AbortController();
30
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
31
+ const response = await fetch(url, {
32
+ ...options2,
33
+ signal: controller.signal
34
+ }).finally(() => clearTimeout(timeoutId));
35
+ return response;
36
+ };
37
+
27
38
  // src/utils.ts
28
39
  var import_router = require("@aura-stack/router");
29
40
 
@@ -69,28 +80,28 @@ var formatZodError = (error) => {
69
80
  };
70
81
 
71
82
  // src/schemas.ts
72
- var import_v4 = require("zod/v4");
73
- var OAuthProviderConfigSchema = (0, import_v4.object)({
74
- authorizeURL: (0, import_v4.httpUrl)(),
75
- accessToken: (0, import_v4.httpUrl)(),
76
- scope: (0, import_v4.string)().optional(),
77
- userInfo: (0, import_v4.httpUrl)(),
78
- responseType: (0, import_v4.enum)(["code", "token", "id_token"]),
79
- clientId: (0, import_v4.string)(),
80
- clientSecret: (0, import_v4.string)()
83
+ var import_zod = require("zod");
84
+ var OAuthProviderConfigSchema = (0, import_zod.object)({
85
+ authorizeURL: (0, import_zod.string)().url(),
86
+ accessToken: (0, import_zod.string)().url(),
87
+ scope: (0, import_zod.string)().optional(),
88
+ userInfo: (0, import_zod.string)().url(),
89
+ responseType: (0, import_zod.enum)(["code", "token", "id_token"]),
90
+ clientId: (0, import_zod.string)(),
91
+ clientSecret: (0, import_zod.string)()
81
92
  });
82
93
  var OAuthAuthorization = OAuthProviderConfigSchema.extend({
83
- redirectURI: (0, import_v4.string)(),
84
- state: (0, import_v4.string)(),
85
- codeChallenge: (0, import_v4.string)(),
86
- codeChallengeMethod: (0, import_v4.enum)(["plain", "S256"])
94
+ redirectURI: (0, import_zod.string)(),
95
+ state: (0, import_zod.string)(),
96
+ codeChallenge: (0, import_zod.string)(),
97
+ codeChallengeMethod: (0, import_zod.enum)(["plain", "S256"])
87
98
  });
88
- var OAuthAuthorizationResponse = (0, import_v4.object)({
89
- state: (0, import_v4.string)("Missing state parameter in the OAuth authorization response."),
90
- code: (0, import_v4.string)("Missing code parameter in the OAuth authorization response.")
99
+ var OAuthAuthorizationResponse = (0, import_zod.object)({
100
+ state: (0, import_zod.string)({ message: "Missing state parameter in the OAuth authorization response." }),
101
+ code: (0, import_zod.string)({ message: "Missing code parameter in the OAuth authorization response." })
91
102
  });
92
- var OAuthAuthorizationErrorResponse = (0, import_v4.object)({
93
- error: (0, import_v4.enum)([
103
+ var OAuthAuthorizationErrorResponse = (0, import_zod.object)({
104
+ error: (0, import_zod.enum)([
94
105
  "invalid_request",
95
106
  "unauthorized_client",
96
107
  "access_denied",
@@ -99,24 +110,24 @@ var OAuthAuthorizationErrorResponse = (0, import_v4.object)({
99
110
  "server_error",
100
111
  "temporarily_unavailable"
101
112
  ]),
102
- error_description: (0, import_v4.string)().optional(),
103
- error_uri: (0, import_v4.string)().optional(),
104
- state: (0, import_v4.string)()
113
+ error_description: (0, import_zod.string)().optional(),
114
+ error_uri: (0, import_zod.string)().optional(),
115
+ state: (0, import_zod.string)()
105
116
  });
106
117
  var OAuthAccessToken = OAuthProviderConfigSchema.extend({
107
- redirectURI: (0, import_v4.string)(),
108
- code: (0, import_v4.string)(),
109
- codeVerifier: (0, import_v4.string)().min(43).max(128)
118
+ redirectURI: (0, import_zod.string)(),
119
+ code: (0, import_zod.string)(),
120
+ codeVerifier: (0, import_zod.string)().min(43).max(128)
110
121
  });
111
- var OAuthAccessTokenResponse = (0, import_v4.object)({
112
- access_token: (0, import_v4.string)(),
113
- token_type: (0, import_v4.string)(),
114
- expires_in: (0, import_v4.number)().optional(),
115
- refresh_token: (0, import_v4.string)().optional(),
116
- scope: (0, import_v4.string)().optional()
122
+ var OAuthAccessTokenResponse = (0, import_zod.object)({
123
+ access_token: (0, import_zod.string)(),
124
+ token_type: (0, import_zod.string)().optional(),
125
+ expires_in: (0, import_zod.number)().optional(),
126
+ refresh_token: (0, import_zod.string)().optional(),
127
+ scope: (0, import_zod.string)().optional().or((0, import_zod.null)())
117
128
  });
118
- var OAuthAccessTokenErrorResponse = (0, import_v4.object)({
119
- error: (0, import_v4.enum)([
129
+ var OAuthAccessTokenErrorResponse = (0, import_zod.object)({
130
+ error: (0, import_zod.enum)([
120
131
  "invalid_request",
121
132
  "invalid_client",
122
133
  "invalid_grant",
@@ -124,16 +135,16 @@ var OAuthAccessTokenErrorResponse = (0, import_v4.object)({
124
135
  "unsupported_grant_type",
125
136
  "invalid_scope"
126
137
  ]),
127
- error_description: (0, import_v4.string)().optional(),
128
- error_uri: (0, import_v4.string)().optional()
138
+ error_description: (0, import_zod.string)().optional(),
139
+ error_uri: (0, import_zod.string)().optional()
129
140
  });
130
- var OAuthErrorResponse = (0, import_v4.object)({
131
- error: (0, import_v4.string)(),
132
- error_description: (0, import_v4.string)().optional()
141
+ var OAuthErrorResponse = (0, import_zod.object)({
142
+ error: (0, import_zod.string)(),
143
+ error_description: (0, import_zod.string)().optional()
133
144
  });
134
- var OAuthEnvSchema = (0, import_v4.object)({
135
- clientId: import_v4.z.string().min(1, "OAuth Client ID is required in the environment variables."),
136
- clientSecret: import_v4.z.string().min(1, "OAuth Client Secret is required in the environment variables.")
145
+ var OAuthEnvSchema = (0, import_zod.object)({
146
+ clientId: import_zod.z.string().min(1, "OAuth Client ID is required in the environment variables."),
147
+ clientSecret: import_zod.z.string().min(1, "OAuth Client Secret is required in the environment variables.")
137
148
  });
138
149
 
139
150
  // src/actions/callback/access-token.ts
@@ -145,7 +156,7 @@ var createAccessToken = async (oauthConfig, redirectURI, code, codeVerifier) =>
145
156
  }
146
157
  const { accessToken, clientId, clientSecret, code: codeParsed, redirectURI: redirectParsed } = parsed.data;
147
158
  try {
148
- const response = await fetch(accessToken, {
159
+ const response = await fetchAsync(accessToken, {
149
160
  method: "POST",
150
161
  headers: {
151
162
  Accept: "application/json",
@@ -1,7 +1,8 @@
1
- import { h as OAuthProviderCredentials } from '../../index-EqsoyjrF.js';
2
- import 'zod/v4';
1
+ import { h as OAuthProviderCredentials } from '../../index-DkaLJFn8.js';
2
+ import 'zod';
3
3
  import '../../schemas.js';
4
4
  import '@aura-stack/router/cookie';
5
+ import '@aura-stack/jose';
5
6
  import '@aura-stack/jose/jose';
6
7
  import '../../@types/utility.js';
7
8
 
@@ -18,10 +19,10 @@ import '../../@types/utility.js';
18
19
  */
19
20
  declare const createAccessToken: (oauthConfig: OAuthProviderCredentials, redirectURI: string, code: string, codeVerifier: string) => Promise<{
20
21
  access_token: string;
21
- token_type: string;
22
+ token_type?: string | undefined;
22
23
  expires_in?: number | undefined;
23
24
  refresh_token?: string | undefined;
24
- scope?: string | undefined;
25
+ scope?: string | null | undefined;
25
26
  }>;
26
27
 
27
28
  export { createAccessToken };
@@ -1,9 +1,10 @@
1
1
  import {
2
2
  createAccessToken
3
- } from "../../chunk-4V4JNXVF.js";
4
- import "../../chunk-WD7AUHQ5.js";
3
+ } from "../../chunk-GA2SMTJO.js";
5
4
  import "../../chunk-CXLATHS5.js";
6
5
  import "../../chunk-RRLIF4PQ.js";
6
+ import "../../chunk-ZNCZVF6U.js";
7
+ import "../../chunk-YRCB5FLE.js";
7
8
  export {
8
9
  createAccessToken
9
10
  };
@@ -33,11 +33,11 @@ __export(callback_exports, {
33
33
  callbackAction: () => callbackAction
34
34
  });
35
35
  module.exports = __toCommonJS(callback_exports);
36
- var import_zod = __toESM(require("zod"), 1);
36
+ var import_zod2 = require("zod");
37
37
  var import_router2 = require("@aura-stack/router");
38
38
 
39
39
  // src/secure.ts
40
- var import_node_crypto = __toESM(require("crypto"), 1);
40
+ var import_crypto = __toESM(require("crypto"), 1);
41
41
 
42
42
  // src/utils.ts
43
43
  var import_router = require("@aura-stack/router");
@@ -146,7 +146,7 @@ var formatZodError = (error) => {
146
146
 
147
147
  // src/secure.ts
148
148
  var generateSecure = (length = 32) => {
149
- return import_node_crypto.default.randomBytes(length).toString("base64url");
149
+ return import_crypto.default.randomBytes(length).toString("base64url");
150
150
  };
151
151
  var createCSRF = async (jose, csrfCookie) => {
152
152
  try {
@@ -170,29 +170,40 @@ var cacheControl = {
170
170
  Vary: "Cookie"
171
171
  };
172
172
 
173
+ // src/request.ts
174
+ var fetchAsync = async (url, options2 = {}, timeout = 5e3) => {
175
+ const controller = new AbortController();
176
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
177
+ const response = await fetch(url, {
178
+ ...options2,
179
+ signal: controller.signal
180
+ }).finally(() => clearTimeout(timeoutId));
181
+ return response;
182
+ };
183
+
173
184
  // src/schemas.ts
174
- var import_v4 = require("zod/v4");
175
- var OAuthProviderConfigSchema = (0, import_v4.object)({
176
- authorizeURL: (0, import_v4.httpUrl)(),
177
- accessToken: (0, import_v4.httpUrl)(),
178
- scope: (0, import_v4.string)().optional(),
179
- userInfo: (0, import_v4.httpUrl)(),
180
- responseType: (0, import_v4.enum)(["code", "token", "id_token"]),
181
- clientId: (0, import_v4.string)(),
182
- clientSecret: (0, import_v4.string)()
185
+ var import_zod = require("zod");
186
+ var OAuthProviderConfigSchema = (0, import_zod.object)({
187
+ authorizeURL: (0, import_zod.string)().url(),
188
+ accessToken: (0, import_zod.string)().url(),
189
+ scope: (0, import_zod.string)().optional(),
190
+ userInfo: (0, import_zod.string)().url(),
191
+ responseType: (0, import_zod.enum)(["code", "token", "id_token"]),
192
+ clientId: (0, import_zod.string)(),
193
+ clientSecret: (0, import_zod.string)()
183
194
  });
184
195
  var OAuthAuthorization = OAuthProviderConfigSchema.extend({
185
- redirectURI: (0, import_v4.string)(),
186
- state: (0, import_v4.string)(),
187
- codeChallenge: (0, import_v4.string)(),
188
- codeChallengeMethod: (0, import_v4.enum)(["plain", "S256"])
196
+ redirectURI: (0, import_zod.string)(),
197
+ state: (0, import_zod.string)(),
198
+ codeChallenge: (0, import_zod.string)(),
199
+ codeChallengeMethod: (0, import_zod.enum)(["plain", "S256"])
189
200
  });
190
- var OAuthAuthorizationResponse = (0, import_v4.object)({
191
- state: (0, import_v4.string)("Missing state parameter in the OAuth authorization response."),
192
- code: (0, import_v4.string)("Missing code parameter in the OAuth authorization response.")
201
+ var OAuthAuthorizationResponse = (0, import_zod.object)({
202
+ state: (0, import_zod.string)({ message: "Missing state parameter in the OAuth authorization response." }),
203
+ code: (0, import_zod.string)({ message: "Missing code parameter in the OAuth authorization response." })
193
204
  });
194
- var OAuthAuthorizationErrorResponse = (0, import_v4.object)({
195
- error: (0, import_v4.enum)([
205
+ var OAuthAuthorizationErrorResponse = (0, import_zod.object)({
206
+ error: (0, import_zod.enum)([
196
207
  "invalid_request",
197
208
  "unauthorized_client",
198
209
  "access_denied",
@@ -201,24 +212,24 @@ var OAuthAuthorizationErrorResponse = (0, import_v4.object)({
201
212
  "server_error",
202
213
  "temporarily_unavailable"
203
214
  ]),
204
- error_description: (0, import_v4.string)().optional(),
205
- error_uri: (0, import_v4.string)().optional(),
206
- state: (0, import_v4.string)()
215
+ error_description: (0, import_zod.string)().optional(),
216
+ error_uri: (0, import_zod.string)().optional(),
217
+ state: (0, import_zod.string)()
207
218
  });
208
219
  var OAuthAccessToken = OAuthProviderConfigSchema.extend({
209
- redirectURI: (0, import_v4.string)(),
210
- code: (0, import_v4.string)(),
211
- codeVerifier: (0, import_v4.string)().min(43).max(128)
220
+ redirectURI: (0, import_zod.string)(),
221
+ code: (0, import_zod.string)(),
222
+ codeVerifier: (0, import_zod.string)().min(43).max(128)
212
223
  });
213
- var OAuthAccessTokenResponse = (0, import_v4.object)({
214
- access_token: (0, import_v4.string)(),
215
- token_type: (0, import_v4.string)(),
216
- expires_in: (0, import_v4.number)().optional(),
217
- refresh_token: (0, import_v4.string)().optional(),
218
- scope: (0, import_v4.string)().optional()
224
+ var OAuthAccessTokenResponse = (0, import_zod.object)({
225
+ access_token: (0, import_zod.string)(),
226
+ token_type: (0, import_zod.string)().optional(),
227
+ expires_in: (0, import_zod.number)().optional(),
228
+ refresh_token: (0, import_zod.string)().optional(),
229
+ scope: (0, import_zod.string)().optional().or((0, import_zod.null)())
219
230
  });
220
- var OAuthAccessTokenErrorResponse = (0, import_v4.object)({
221
- error: (0, import_v4.enum)([
231
+ var OAuthAccessTokenErrorResponse = (0, import_zod.object)({
232
+ error: (0, import_zod.enum)([
222
233
  "invalid_request",
223
234
  "invalid_client",
224
235
  "invalid_grant",
@@ -226,16 +237,16 @@ var OAuthAccessTokenErrorResponse = (0, import_v4.object)({
226
237
  "unsupported_grant_type",
227
238
  "invalid_scope"
228
239
  ]),
229
- error_description: (0, import_v4.string)().optional(),
230
- error_uri: (0, import_v4.string)().optional()
240
+ error_description: (0, import_zod.string)().optional(),
241
+ error_uri: (0, import_zod.string)().optional()
231
242
  });
232
- var OAuthErrorResponse = (0, import_v4.object)({
233
- error: (0, import_v4.string)(),
234
- error_description: (0, import_v4.string)().optional()
243
+ var OAuthErrorResponse = (0, import_zod.object)({
244
+ error: (0, import_zod.string)(),
245
+ error_description: (0, import_zod.string)().optional()
235
246
  });
236
- var OAuthEnvSchema = (0, import_v4.object)({
237
- clientId: import_v4.z.string().min(1, "OAuth Client ID is required in the environment variables."),
238
- clientSecret: import_v4.z.string().min(1, "OAuth Client Secret is required in the environment variables.")
247
+ var OAuthEnvSchema = (0, import_zod.object)({
248
+ clientId: import_zod.z.string().min(1, "OAuth Client ID is required in the environment variables."),
249
+ clientSecret: import_zod.z.string().min(1, "OAuth Client Secret is required in the environment variables.")
239
250
  });
240
251
 
241
252
  // src/actions/callback/userinfo.ts
@@ -251,7 +262,7 @@ var getDefaultUserInfo = (profile) => {
251
262
  var getUserInfo = async (oauthConfig, accessToken) => {
252
263
  const userinfoEndpoint = oauthConfig.userInfo;
253
264
  try {
254
- const response = await fetch(userinfoEndpoint, {
265
+ const response = await fetchAsync(userinfoEndpoint, {
255
266
  method: "GET",
256
267
  headers: {
257
268
  Accept: "application/json",
@@ -287,7 +298,7 @@ var createAccessToken = async (oauthConfig, redirectURI, code, codeVerifier) =>
287
298
  }
288
299
  const { accessToken, clientId, clientSecret, code: codeParsed, redirectURI: redirectParsed } = parsed.data;
289
300
  try {
290
- const response = await fetch(accessToken, {
301
+ const response = await fetchAsync(accessToken, {
291
302
  method: "POST",
292
303
  headers: {
293
304
  Accept: "application/json",
@@ -360,9 +371,15 @@ var createSessionCookie = async (jose, session) => {
360
371
  var callbackConfig = (oauth) => {
361
372
  return (0, import_router2.createEndpointConfig)("/callback/:oauth", {
362
373
  schemas: {
363
- searchParams: OAuthAuthorizationResponse,
364
- params: import_zod.default.object({
365
- oauth: import_zod.default.enum(Object.keys(oauth), "The OAuth provider is not supported or invalid.")
374
+ params: import_zod2.z.object({
375
+ oauth: import_zod2.z.enum(
376
+ Object.keys(oauth),
377
+ "The OAuth provider is not supported or invalid."
378
+ )
379
+ }),
380
+ searchParams: import_zod2.z.object({
381
+ code: import_zod2.z.string("Missing code parameter in the OAuth authorization response."),
382
+ state: import_zod2.z.string("Missing state parameter in the OAuth authorization response.")
366
383
  })
367
384
  },
368
385
  middlewares: [
@@ -390,9 +407,9 @@ var callbackAction = (oauth) => {
390
407
  } = ctx;
391
408
  const oauthConfig = providers[oauth2];
392
409
  const cookieState = getCookie(request, cookies.state.name);
393
- const cookieRedirectTo = getCookie(request, cookies.redirect_to.name);
394
- const cookieRedirectURI = getCookie(request, cookies.redirect_uri.name);
395
- const codeVerifier = getCookie(request, cookies.code_verifier.name);
410
+ const cookieRedirectTo = getCookie(request, cookies.redirectTo.name);
411
+ const cookieRedirectURI = getCookie(request, cookies.redirectURI.name);
412
+ const codeVerifier = getCookie(request, cookies.codeVerifier.name);
396
413
  if (!equals(cookieState, state)) {
397
414
  throw new AuthSecurityError(
398
415
  "MISMATCHING_STATE",
@@ -410,7 +427,7 @@ var callbackAction = (oauth) => {
410
427
  const userInfo = await getUserInfo(oauthConfig, accessToken.access_token);
411
428
  const sessionCookie = await createSessionCookie(jose, userInfo);
412
429
  const csrfToken = await createCSRF(jose);
413
- const headers = new import_router2.HeadersBuilder(cacheControl).setHeader("Location", sanitized).setCookie(cookies.sessionToken.name, sessionCookie, cookies.sessionToken.attributes).setCookie(cookies.csrfToken.name, csrfToken, cookies.csrfToken.attributes).setCookie(cookies.state.name, "", expiredCookieAttributes).setCookie(cookies.redirect_uri.name, "", expiredCookieAttributes).setCookie(cookies.redirect_to.name, "", expiredCookieAttributes).setCookie(cookies.code_verifier.name, "", expiredCookieAttributes).toHeaders();
430
+ const headers = new import_router2.HeadersBuilder(cacheControl).setHeader("Location", sanitized).setCookie(cookies.sessionToken.name, sessionCookie, cookies.sessionToken.attributes).setCookie(cookies.csrfToken.name, csrfToken, cookies.csrfToken.attributes).setCookie(cookies.state.name, "", expiredCookieAttributes).setCookie(cookies.redirectURI.name, "", expiredCookieAttributes).setCookie(cookies.redirectTo.name, "", expiredCookieAttributes).setCookie(cookies.codeVerifier.name, "", expiredCookieAttributes).toHeaders();
414
431
  return Response.json({ oauth: oauth2 }, { status: 302, headers });
415
432
  },
416
433
  callbackConfig(oauth)
@@ -1,11 +1,12 @@
1
1
  import * as _aura_stack_router from '@aura-stack/router';
2
- import { A as AuthRuntimeConfig } from '../../index-EqsoyjrF.js';
3
- import 'zod/v4';
2
+ import { j as OAuthProviderRecord } from '../../index-DkaLJFn8.js';
3
+ import 'zod';
4
4
  import '../../schemas.js';
5
5
  import '@aura-stack/router/cookie';
6
+ import '@aura-stack/jose';
6
7
  import '@aura-stack/jose/jose';
7
8
  import '../../@types/utility.js';
8
9
 
9
- declare const callbackAction: (oauth: AuthRuntimeConfig["oauth"]) => _aura_stack_router.RouteEndpoint<"GET", "/callback/:oauth", {}>;
10
+ declare const callbackAction: (oauth: OAuthProviderRecord) => _aura_stack_router.RouteEndpoint<"GET", "/callback/:oauth", {}>;
10
11
 
11
12
  export { callbackAction };
@@ -1,15 +1,16 @@
1
1
  import {
2
2
  callbackAction
3
- } from "../../chunk-UEH3LVON.js";
4
- import "../../chunk-ZLR3LI6X.js";
5
- import "../../chunk-4V4JNXVF.js";
6
- import "../../chunk-IMICRJ5U.js";
3
+ } from "../../chunk-KSWLO5ZU.js";
4
+ import "../../chunk-GA2SMTJO.js";
5
+ import "../../chunk-IVET23KF.js";
6
+ import "../../chunk-W6LG7BFW.js";
7
7
  import "../../chunk-STHEPPUZ.js";
8
- import "../../chunk-WD7AUHQ5.js";
9
8
  import "../../chunk-N2APGLXA.js";
10
9
  import "../../chunk-CXLATHS5.js";
11
10
  import "../../chunk-EIL2FPSS.js";
12
11
  import "../../chunk-RRLIF4PQ.js";
12
+ import "../../chunk-ZNCZVF6U.js";
13
+ import "../../chunk-YRCB5FLE.js";
13
14
  export {
14
15
  callbackAction
15
16
  };
@@ -34,8 +34,19 @@ __export(userinfo_exports, {
34
34
  });
35
35
  module.exports = __toCommonJS(userinfo_exports);
36
36
 
37
+ // src/request.ts
38
+ var fetchAsync = async (url, options2 = {}, timeout = 5e3) => {
39
+ const controller = new AbortController();
40
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
41
+ const response = await fetch(url, {
42
+ ...options2,
43
+ signal: controller.signal
44
+ }).finally(() => clearTimeout(timeoutId));
45
+ return response;
46
+ };
47
+
37
48
  // src/secure.ts
38
- var import_node_crypto = __toESM(require("crypto"), 1);
49
+ var import_crypto = __toESM(require("crypto"), 1);
39
50
 
40
51
  // src/utils.ts
41
52
  var import_router = require("@aura-stack/router");
@@ -62,32 +73,32 @@ var isOAuthProtocolError = (error) => {
62
73
 
63
74
  // src/secure.ts
64
75
  var generateSecure = (length = 32) => {
65
- return import_node_crypto.default.randomBytes(length).toString("base64url");
76
+ return import_crypto.default.randomBytes(length).toString("base64url");
66
77
  };
67
78
 
68
79
  // src/schemas.ts
69
- var import_v4 = require("zod/v4");
70
- var OAuthProviderConfigSchema = (0, import_v4.object)({
71
- authorizeURL: (0, import_v4.httpUrl)(),
72
- accessToken: (0, import_v4.httpUrl)(),
73
- scope: (0, import_v4.string)().optional(),
74
- userInfo: (0, import_v4.httpUrl)(),
75
- responseType: (0, import_v4.enum)(["code", "token", "id_token"]),
76
- clientId: (0, import_v4.string)(),
77
- clientSecret: (0, import_v4.string)()
80
+ var import_zod = require("zod");
81
+ var OAuthProviderConfigSchema = (0, import_zod.object)({
82
+ authorizeURL: (0, import_zod.string)().url(),
83
+ accessToken: (0, import_zod.string)().url(),
84
+ scope: (0, import_zod.string)().optional(),
85
+ userInfo: (0, import_zod.string)().url(),
86
+ responseType: (0, import_zod.enum)(["code", "token", "id_token"]),
87
+ clientId: (0, import_zod.string)(),
88
+ clientSecret: (0, import_zod.string)()
78
89
  });
79
90
  var OAuthAuthorization = OAuthProviderConfigSchema.extend({
80
- redirectURI: (0, import_v4.string)(),
81
- state: (0, import_v4.string)(),
82
- codeChallenge: (0, import_v4.string)(),
83
- codeChallengeMethod: (0, import_v4.enum)(["plain", "S256"])
91
+ redirectURI: (0, import_zod.string)(),
92
+ state: (0, import_zod.string)(),
93
+ codeChallenge: (0, import_zod.string)(),
94
+ codeChallengeMethod: (0, import_zod.enum)(["plain", "S256"])
84
95
  });
85
- var OAuthAuthorizationResponse = (0, import_v4.object)({
86
- state: (0, import_v4.string)("Missing state parameter in the OAuth authorization response."),
87
- code: (0, import_v4.string)("Missing code parameter in the OAuth authorization response.")
96
+ var OAuthAuthorizationResponse = (0, import_zod.object)({
97
+ state: (0, import_zod.string)({ message: "Missing state parameter in the OAuth authorization response." }),
98
+ code: (0, import_zod.string)({ message: "Missing code parameter in the OAuth authorization response." })
88
99
  });
89
- var OAuthAuthorizationErrorResponse = (0, import_v4.object)({
90
- error: (0, import_v4.enum)([
100
+ var OAuthAuthorizationErrorResponse = (0, import_zod.object)({
101
+ error: (0, import_zod.enum)([
91
102
  "invalid_request",
92
103
  "unauthorized_client",
93
104
  "access_denied",
@@ -96,24 +107,24 @@ var OAuthAuthorizationErrorResponse = (0, import_v4.object)({
96
107
  "server_error",
97
108
  "temporarily_unavailable"
98
109
  ]),
99
- error_description: (0, import_v4.string)().optional(),
100
- error_uri: (0, import_v4.string)().optional(),
101
- state: (0, import_v4.string)()
110
+ error_description: (0, import_zod.string)().optional(),
111
+ error_uri: (0, import_zod.string)().optional(),
112
+ state: (0, import_zod.string)()
102
113
  });
103
114
  var OAuthAccessToken = OAuthProviderConfigSchema.extend({
104
- redirectURI: (0, import_v4.string)(),
105
- code: (0, import_v4.string)(),
106
- codeVerifier: (0, import_v4.string)().min(43).max(128)
115
+ redirectURI: (0, import_zod.string)(),
116
+ code: (0, import_zod.string)(),
117
+ codeVerifier: (0, import_zod.string)().min(43).max(128)
107
118
  });
108
- var OAuthAccessTokenResponse = (0, import_v4.object)({
109
- access_token: (0, import_v4.string)(),
110
- token_type: (0, import_v4.string)(),
111
- expires_in: (0, import_v4.number)().optional(),
112
- refresh_token: (0, import_v4.string)().optional(),
113
- scope: (0, import_v4.string)().optional()
119
+ var OAuthAccessTokenResponse = (0, import_zod.object)({
120
+ access_token: (0, import_zod.string)(),
121
+ token_type: (0, import_zod.string)().optional(),
122
+ expires_in: (0, import_zod.number)().optional(),
123
+ refresh_token: (0, import_zod.string)().optional(),
124
+ scope: (0, import_zod.string)().optional().or((0, import_zod.null)())
114
125
  });
115
- var OAuthAccessTokenErrorResponse = (0, import_v4.object)({
116
- error: (0, import_v4.enum)([
126
+ var OAuthAccessTokenErrorResponse = (0, import_zod.object)({
127
+ error: (0, import_zod.enum)([
117
128
  "invalid_request",
118
129
  "invalid_client",
119
130
  "invalid_grant",
@@ -121,16 +132,16 @@ var OAuthAccessTokenErrorResponse = (0, import_v4.object)({
121
132
  "unsupported_grant_type",
122
133
  "invalid_scope"
123
134
  ]),
124
- error_description: (0, import_v4.string)().optional(),
125
- error_uri: (0, import_v4.string)().optional()
135
+ error_description: (0, import_zod.string)().optional(),
136
+ error_uri: (0, import_zod.string)().optional()
126
137
  });
127
- var OAuthErrorResponse = (0, import_v4.object)({
128
- error: (0, import_v4.string)(),
129
- error_description: (0, import_v4.string)().optional()
138
+ var OAuthErrorResponse = (0, import_zod.object)({
139
+ error: (0, import_zod.string)(),
140
+ error_description: (0, import_zod.string)().optional()
130
141
  });
131
- var OAuthEnvSchema = (0, import_v4.object)({
132
- clientId: import_v4.z.string().min(1, "OAuth Client ID is required in the environment variables."),
133
- clientSecret: import_v4.z.string().min(1, "OAuth Client Secret is required in the environment variables.")
142
+ var OAuthEnvSchema = (0, import_zod.object)({
143
+ clientId: import_zod.z.string().min(1, "OAuth Client ID is required in the environment variables."),
144
+ clientSecret: import_zod.z.string().min(1, "OAuth Client Secret is required in the environment variables.")
134
145
  });
135
146
 
136
147
  // src/actions/callback/userinfo.ts
@@ -146,7 +157,7 @@ var getDefaultUserInfo = (profile) => {
146
157
  var getUserInfo = async (oauthConfig, accessToken) => {
147
158
  const userinfoEndpoint = oauthConfig.userInfo;
148
159
  try {
149
- const response = await fetch(userinfoEndpoint, {
160
+ const response = await fetchAsync(userinfoEndpoint, {
150
161
  method: "GET",
151
162
  headers: {
152
163
  Accept: "application/json",
@@ -1,7 +1,8 @@
1
- import { h as OAuthProviderCredentials, U as User } from '../../index-EqsoyjrF.js';
2
- import 'zod/v4';
1
+ import { h as OAuthProviderCredentials, U as User } from '../../index-DkaLJFn8.js';
2
+ import 'zod';
3
3
  import '../../schemas.js';
4
4
  import '@aura-stack/router/cookie';
5
+ import '@aura-stack/jose';
5
6
  import '@aura-stack/jose/jose';
6
7
  import '../../@types/utility.js';
7
8
 
@@ -1,11 +1,12 @@
1
1
  import {
2
2
  getUserInfo
3
- } from "../../chunk-ZLR3LI6X.js";
4
- import "../../chunk-WD7AUHQ5.js";
3
+ } from "../../chunk-IVET23KF.js";
5
4
  import "../../chunk-N2APGLXA.js";
6
5
  import "../../chunk-CXLATHS5.js";
7
6
  import "../../chunk-EIL2FPSS.js";
8
7
  import "../../chunk-RRLIF4PQ.js";
8
+ import "../../chunk-ZNCZVF6U.js";
9
+ import "../../chunk-YRCB5FLE.js";
9
10
  export {
10
11
  getUserInfo
11
12
  };
@@ -36,7 +36,7 @@ module.exports = __toCommonJS(csrfToken_exports);
36
36
  var import_router2 = require("@aura-stack/router");
37
37
 
38
38
  // src/secure.ts
39
- var import_node_crypto = __toESM(require("crypto"), 1);
39
+ var import_crypto = __toESM(require("crypto"), 1);
40
40
 
41
41
  // src/utils.ts
42
42
  var import_router = require("@aura-stack/router");
@@ -55,7 +55,7 @@ var AuthInternalError = class extends Error {
55
55
 
56
56
  // src/secure.ts
57
57
  var generateSecure = (length = 32) => {
58
- return import_node_crypto.default.randomBytes(length).toString("base64url");
58
+ return import_crypto.default.randomBytes(length).toString("base64url");
59
59
  };
60
60
  var createCSRF = async (jose, csrfCookie) => {
61
61
  try {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  csrfTokenAction
3
- } from "../../chunk-QDO2KSRJ.js";
4
- import "../../chunk-IMICRJ5U.js";
3
+ } from "../../chunk-HT4YLL7N.js";
4
+ import "../../chunk-W6LG7BFW.js";
5
5
  import "../../chunk-STHEPPUZ.js";
6
6
  import "../../chunk-N2APGLXA.js";
7
7
  import "../../chunk-CXLATHS5.js";