@aura-stack/auth 0.1.0 → 0.2.0-rc.1

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 (111) hide show
  1. package/dist/@types/index.d.ts +5 -5
  2. package/dist/@types/router.d.d.ts +5 -5
  3. package/dist/@types/utility.d.ts +1 -5
  4. package/dist/actions/callback/access-token.cjs +95 -74
  5. package/dist/actions/callback/access-token.d.ts +7 -7
  6. package/dist/actions/callback/access-token.js +5 -3
  7. package/dist/actions/callback/callback.cjs +171 -249
  8. package/dist/actions/callback/callback.d.ts +6 -6
  9. package/dist/actions/callback/callback.js +10 -10
  10. package/dist/actions/callback/userinfo.cjs +81 -57
  11. package/dist/actions/callback/userinfo.d.ts +5 -5
  12. package/dist/actions/callback/userinfo.js +7 -5
  13. package/dist/actions/csrfToken/csrfToken.cjs +36 -105
  14. package/dist/actions/csrfToken/csrfToken.js +6 -6
  15. package/dist/actions/index.cjs +309 -444
  16. package/dist/actions/index.d.ts +5 -5
  17. package/dist/actions/index.js +19 -19
  18. package/dist/actions/session/session.cjs +25 -109
  19. package/dist/actions/session/session.js +4 -5
  20. package/dist/actions/signIn/authorization.cjs +96 -87
  21. package/dist/actions/signIn/authorization.d.ts +5 -5
  22. package/dist/actions/signIn/authorization.js +5 -5
  23. package/dist/actions/signIn/signIn.cjs +133 -242
  24. package/dist/actions/signIn/signIn.d.ts +6 -6
  25. package/dist/actions/signIn/signIn.js +8 -9
  26. package/dist/actions/signOut/signOut.cjs +136 -282
  27. package/dist/actions/signOut/signOut.js +8 -9
  28. package/dist/assert.cjs +5 -0
  29. package/dist/assert.d.ts +10 -1
  30. package/dist/assert.js +3 -1
  31. package/dist/chunk-3EUWD5BB.js +63 -0
  32. package/dist/chunk-6R2YZ4AC.js +22 -0
  33. package/dist/chunk-A3N4PVAT.js +70 -0
  34. package/dist/chunk-B737EUJV.js +22 -0
  35. package/dist/{chunk-256KIVJL.js → chunk-CXLATHS5.js} +53 -9
  36. package/dist/{chunk-6SM22VVJ.js → chunk-EIL2FPSS.js} +5 -1
  37. package/dist/{chunk-VFTYH33W.js → chunk-EMKJA2GJ.js} +36 -8
  38. package/dist/{chunk-UJJ7R56J.js → chunk-GA2SMTJO.js} +16 -10
  39. package/dist/chunk-HP34YGGJ.js +22 -0
  40. package/dist/chunk-HT4YLL7N.js +35 -0
  41. package/dist/{chunk-EBPE35JT.js → chunk-IUYZQTJV.js} +0 -1
  42. package/dist/{chunk-RLT4RFKV.js → chunk-IVET23KF.js} +21 -8
  43. package/dist/{chunk-XXJKNKGQ.js → chunk-JVFTCTTE.js} +9 -13
  44. package/dist/chunk-KSWLO5ZU.js +102 -0
  45. package/dist/{chunk-GZU3RBTB.js → chunk-N2APGLXA.js} +19 -10
  46. package/dist/{chunk-CAKJT3KS.js → chunk-N4SX7TZT.js} +21 -17
  47. package/dist/chunk-RRLIF4PQ.js +55 -0
  48. package/dist/chunk-TLE4PXY3.js +39 -0
  49. package/dist/chunk-W6LG7BFW.js +197 -0
  50. package/dist/{chunk-HMRKN75I.js → chunk-YRCB5FLE.js} +14 -9
  51. package/dist/chunk-ZNCZVF6U.js +14 -0
  52. package/dist/cookie.cjs +140 -99
  53. package/dist/cookie.d.ts +35 -44
  54. package/dist/cookie.js +10 -17
  55. package/dist/errors.cjs +85 -0
  56. package/dist/errors.d.ts +49 -0
  57. package/dist/errors.js +18 -0
  58. package/dist/{index-DpfbvTZ_.d.ts → index-DkaLJFn8.d.ts} +192 -61
  59. package/dist/index.cjs +543 -443
  60. package/dist/index.d.ts +6 -6
  61. package/dist/index.js +42 -28
  62. package/dist/jose.cjs +25 -14
  63. package/dist/jose.d.ts +4 -1
  64. package/dist/jose.js +5 -4
  65. package/dist/oauth/bitbucket.d.ts +5 -5
  66. package/dist/oauth/discord.cjs +0 -1
  67. package/dist/oauth/discord.d.ts +5 -5
  68. package/dist/oauth/discord.js +1 -1
  69. package/dist/oauth/figma.d.ts +5 -5
  70. package/dist/oauth/github.d.ts +5 -5
  71. package/dist/oauth/gitlab.d.ts +5 -5
  72. package/dist/oauth/index.cjs +176 -6
  73. package/dist/oauth/index.d.ts +5 -5
  74. package/dist/oauth/index.js +19 -4
  75. package/dist/oauth/mailchimp.cjs +46 -0
  76. package/dist/oauth/mailchimp.d.ts +7 -0
  77. package/dist/oauth/mailchimp.js +6 -0
  78. package/dist/oauth/pinterest.cjs +46 -0
  79. package/dist/oauth/pinterest.d.ts +7 -0
  80. package/dist/oauth/pinterest.js +6 -0
  81. package/dist/oauth/spotify.d.ts +5 -5
  82. package/dist/oauth/strava.cjs +46 -0
  83. package/dist/oauth/strava.d.ts +7 -0
  84. package/dist/oauth/strava.js +6 -0
  85. package/dist/oauth/x.d.ts +5 -5
  86. package/dist/{response.cjs → request.cjs} +14 -10
  87. package/dist/request.d.ts +13 -0
  88. package/dist/request.js +6 -0
  89. package/dist/schemas.cjs +43 -37
  90. package/dist/schemas.d.ts +67 -64
  91. package/dist/schemas.js +3 -1
  92. package/dist/secure.cjs +32 -24
  93. package/dist/secure.d.ts +5 -5
  94. package/dist/secure.js +4 -3
  95. package/dist/utils.cjs +90 -15
  96. package/dist/utils.d.ts +11 -2
  97. package/dist/utils.js +8 -4
  98. package/package.json +8 -7
  99. package/dist/chunk-FJUDBLCP.js +0 -59
  100. package/dist/chunk-HGJ4TXY4.js +0 -137
  101. package/dist/chunk-JAPMIE6S.js +0 -10
  102. package/dist/chunk-LLR722CL.js +0 -96
  103. package/dist/chunk-SJPDVKUS.js +0 -112
  104. package/dist/chunk-SMQO5WD7.js +0 -30
  105. package/dist/chunk-UTDLUEEG.js +0 -31
  106. package/dist/chunk-ZV4BH47P.js +0 -154
  107. package/dist/error.cjs +0 -88
  108. package/dist/error.d.ts +0 -62
  109. package/dist/error.js +0 -16
  110. package/dist/response.d.ts +0 -10
  111. package/dist/response.js +0 -6
@@ -1,9 +1,12 @@
1
1
  import {
2
2
  equals
3
- } from "./chunk-256KIVJL.js";
3
+ } from "./chunk-CXLATHS5.js";
4
4
  import {
5
- InvalidCsrfTokenError
6
- } from "./chunk-FJUDBLCP.js";
5
+ isJWTPayloadWithToken
6
+ } from "./chunk-EIL2FPSS.js";
7
+ import {
8
+ AuthSecurityError
9
+ } from "./chunk-RRLIF4PQ.js";
7
10
 
8
11
  // src/secure.ts
9
12
  import crypto from "crypto";
@@ -33,19 +36,25 @@ var createCSRF = async (jose, csrfCookie) => {
33
36
  };
34
37
  var verifyCSRF = async (jose, cookie, header) => {
35
38
  try {
36
- const { token: cookieToken } = await jose.verifyJWS(cookie);
37
- const { token: headerToken } = await jose.verifyJWS(header);
38
- const cookieBuffer = Buffer.from(cookieToken);
39
- const headerBuffer = Buffer.from(headerToken);
39
+ const cookiePayload = await jose.verifyJWS(cookie);
40
+ const headerPayload = await jose.verifyJWS(header);
41
+ if (!isJWTPayloadWithToken(cookiePayload)) {
42
+ throw new AuthSecurityError("CSRF_TOKEN_INVALID", "Cookie payload missing token field.");
43
+ }
44
+ if (!isJWTPayloadWithToken(headerPayload)) {
45
+ throw new AuthSecurityError("CSRF_TOKEN_INVALID", "Header payload missing token field.");
46
+ }
47
+ const cookieBuffer = Buffer.from(cookiePayload.token);
48
+ const headerBuffer = Buffer.from(headerPayload.token);
40
49
  if (!equals(headerBuffer.length, cookieBuffer.length)) {
41
- throw new InvalidCsrfTokenError();
50
+ throw new AuthSecurityError("CSRF_TOKEN_INVALID", "The CSRF tokens do not match.");
42
51
  }
43
52
  if (!crypto.timingSafeEqual(cookieBuffer, headerBuffer)) {
44
- throw new InvalidCsrfTokenError();
53
+ throw new AuthSecurityError("CSRF_TOKEN_INVALID", "The CSRF tokens do not match.");
45
54
  }
46
55
  return true;
47
56
  } catch {
48
- throw new InvalidCsrfTokenError();
57
+ throw new AuthSecurityError("CSRF_TOKEN_INVALID", "The CSRF tokens do not match.");
49
58
  }
50
59
  };
51
60
  var createDerivedSalt = (secret) => {
@@ -1,27 +1,28 @@
1
- import {
2
- isValidURL
3
- } from "./chunk-6SM22VVJ.js";
4
1
  import {
5
2
  equals,
3
+ formatZodError,
6
4
  getNormalizedOriginPath,
7
5
  sanitizeURL,
8
6
  toCastCase
9
- } from "./chunk-256KIVJL.js";
7
+ } from "./chunk-CXLATHS5.js";
10
8
  import {
11
- AuthError,
12
- ERROR_RESPONSE,
13
- InvalidRedirectToError,
14
- isAuthError
15
- } from "./chunk-FJUDBLCP.js";
9
+ isValidURL
10
+ } from "./chunk-EIL2FPSS.js";
11
+ import {
12
+ AuthInternalError,
13
+ AuthSecurityError,
14
+ isAuthSecurityError
15
+ } from "./chunk-RRLIF4PQ.js";
16
16
  import {
17
17
  OAuthAuthorization
18
- } from "./chunk-HMRKN75I.js";
18
+ } from "./chunk-YRCB5FLE.js";
19
19
 
20
20
  // src/actions/signIn/authorization.ts
21
21
  var createAuthorizationURL = (oauthConfig, redirectURI, state, codeChallenge, codeChallengeMethod) => {
22
22
  const parsed = OAuthAuthorization.safeParse({ ...oauthConfig, redirectURI, state, codeChallenge, codeChallengeMethod });
23
23
  if (!parsed.success) {
24
- throw new AuthError(ERROR_RESPONSE.AUTHORIZATION.SERVER_ERROR, "Invalid OAuth configuration");
24
+ const msg = JSON.stringify(formatZodError(parsed.error), null, 2);
25
+ throw new AuthInternalError("INVALID_OAUTH_CONFIGURATION", msg);
25
26
  }
26
27
  const { authorizeURL, ...options } = parsed.data;
27
28
  const { userInfo, accessToken, clientSecret, ...required } = options;
@@ -54,15 +55,18 @@ var createRedirectTo = (request, redirectTo, trustedProxyHeaders) => {
54
55
  }
55
56
  const redirectToURL = new URL(sanitizeURL(getNormalizedOriginPath(redirectTo)));
56
57
  if (!isValidURL(redirectTo) || !equals(redirectToURL.origin, hostedURL.origin)) {
57
- throw new InvalidRedirectToError();
58
+ throw new AuthSecurityError(
59
+ "POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED",
60
+ "The redirectTo parameter does not match the hosted origin."
61
+ );
58
62
  }
59
63
  return sanitizeURL(redirectToURL.pathname);
60
64
  }
61
65
  if (referer) {
62
66
  const refererURL = new URL(sanitizeURL(referer));
63
67
  if (!isValidURL(referer) || !equals(refererURL.origin, hostedURL.origin)) {
64
- throw new AuthError(
65
- ERROR_RESPONSE.AUTHORIZATION.INVALID_REQUEST,
68
+ throw new AuthSecurityError(
69
+ "POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED",
66
70
  "The referer of the request does not match the hosted origin."
67
71
  );
68
72
  }
@@ -71,16 +75,16 @@ var createRedirectTo = (request, redirectTo, trustedProxyHeaders) => {
71
75
  if (origin) {
72
76
  const originURL = new URL(sanitizeURL(getNormalizedOriginPath(origin)));
73
77
  if (!isValidURL(origin) || !equals(originURL.origin, hostedURL.origin)) {
74
- throw new AuthError(ERROR_RESPONSE.AUTHORIZATION.INVALID_REQUEST, "Invalid origin (potential CSRF).");
78
+ throw new AuthSecurityError("POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED", "Invalid origin (potential CSRF).");
75
79
  }
76
80
  return sanitizeURL(originURL.pathname);
77
81
  }
78
82
  return "/";
79
83
  } catch (error) {
80
- if (isAuthError(error)) {
84
+ if (isAuthSecurityError(error)) {
81
85
  throw error;
82
86
  }
83
- throw new AuthError(ERROR_RESPONSE.AUTHORIZATION.INVALID_REQUEST, "Invalid origin (potential CSRF).");
87
+ throw new AuthSecurityError("POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED", "Invalid origin (potential CSRF).");
84
88
  }
85
89
  };
86
90
 
@@ -0,0 +1,55 @@
1
+ // src/errors.ts
2
+ var OAuthProtocolError = class extends Error {
3
+ type = "OAUTH_PROTOCOL_ERROR";
4
+ error;
5
+ errorURI;
6
+ constructor(error, description, errorURI, options) {
7
+ super(description, options);
8
+ this.error = error;
9
+ this.errorURI = errorURI;
10
+ this.name = new.target.name;
11
+ Error.captureStackTrace(this, new.target);
12
+ }
13
+ };
14
+ var AuthInternalError = class extends Error {
15
+ type = "AUTH_INTERNAL_ERROR";
16
+ code;
17
+ constructor(code, message, options) {
18
+ super(message, options);
19
+ this.code = code;
20
+ this.name = new.target.name;
21
+ Error.captureStackTrace(this, new.target);
22
+ }
23
+ };
24
+ var AuthSecurityError = class extends Error {
25
+ type = "AUTH_SECURITY_ERROR";
26
+ code;
27
+ constructor(code, message, options) {
28
+ super(message, options);
29
+ this.code = code;
30
+ this.name = new.target.name;
31
+ Error.captureStackTrace(this, new.target);
32
+ }
33
+ };
34
+ var isNativeError = (error) => {
35
+ return error instanceof Error;
36
+ };
37
+ var isOAuthProtocolError = (error) => {
38
+ return error instanceof OAuthProtocolError;
39
+ };
40
+ var isAuthInternalError = (error) => {
41
+ return error instanceof AuthInternalError;
42
+ };
43
+ var isAuthSecurityError = (error) => {
44
+ return error instanceof AuthSecurityError;
45
+ };
46
+
47
+ export {
48
+ OAuthProtocolError,
49
+ AuthInternalError,
50
+ AuthSecurityError,
51
+ isNativeError,
52
+ isOAuthProtocolError,
53
+ isAuthInternalError,
54
+ isAuthSecurityError
55
+ };
@@ -0,0 +1,39 @@
1
+ import {
2
+ createDerivedSalt
3
+ } from "./chunk-N2APGLXA.js";
4
+ import {
5
+ AuthInternalError
6
+ } from "./chunk-RRLIF4PQ.js";
7
+
8
+ // src/jose.ts
9
+ import "dotenv/config";
10
+ import { createJWT, createJWS, createJWE, createDeriveKey } from "@aura-stack/jose";
11
+ var createJoseInstance = (secret) => {
12
+ const env = process.env;
13
+ secret ??= env.AURA_AUTH_SECRET ?? env.AUTH_SECRET;
14
+ if (!secret) {
15
+ throw new AuthInternalError(
16
+ "JOSE_INITIALIZATION_FAILED",
17
+ "AURA_AUTH_SECRET environment variable is not set and no secret was provided."
18
+ );
19
+ }
20
+ const salt = env.AURA_AUTH_SALT ?? env.AUTH_SALT ?? createDerivedSalt(secret);
21
+ const { derivedKey: derivedSigningKey } = createDeriveKey(secret, salt, "signing");
22
+ const { derivedKey: derivedEncryptionKey } = createDeriveKey(secret, salt, "encryption");
23
+ const { derivedKey: derivedCsrfTokenKey } = createDeriveKey(secret, salt, "csrfToken");
24
+ const { decodeJWT, encodeJWT } = createJWT({ jws: derivedSigningKey, jwe: derivedEncryptionKey });
25
+ const { signJWS, verifyJWS } = createJWS(derivedCsrfTokenKey);
26
+ const { encryptJWE, decryptJWE } = createJWE(derivedEncryptionKey);
27
+ return {
28
+ decodeJWT,
29
+ encodeJWT,
30
+ signJWS,
31
+ verifyJWS,
32
+ encryptJWE,
33
+ decryptJWE
34
+ };
35
+ };
36
+
37
+ export {
38
+ createJoseInstance
39
+ };
@@ -0,0 +1,197 @@
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
+ };
42
+ var getCookie = (request, cookieName) => {
43
+ const cookies = request.headers.get("Cookie");
44
+ if (!cookies) {
45
+ throw new AuthInternalError("COOKIE_NOT_FOUND", "No cookies found. There is no active session");
46
+ }
47
+ const value = parse(cookies)[cookieName];
48
+ if (!value) {
49
+ throw new AuthInternalError("COOKIE_NOT_FOUND", `Cookie "${cookieName}" not found. There is no active session`);
50
+ }
51
+ return value;
52
+ };
53
+ var getSetCookie = (response, cookieName) => {
54
+ const cookies = response.headers.getSetCookie();
55
+ if (!cookies) {
56
+ throw new AuthInternalError("COOKIE_NOT_FOUND", "No cookies found in response.");
57
+ }
58
+ const strCookie = cookies.find((cookie) => cookie.startsWith(`${cookieName}=`));
59
+ if (!strCookie) {
60
+ throw new AuthInternalError("COOKIE_NOT_FOUND", `Cookie "${cookieName}" not found in response.`);
61
+ }
62
+ return parseSetCookie(strCookie).value;
63
+ };
64
+ var createSessionCookie = async (jose, session) => {
65
+ try {
66
+ const encoded = await jose.encodeJWT(session);
67
+ return encoded;
68
+ } catch (error) {
69
+ throw new AuthInternalError("INVALID_JWT_TOKEN", "Failed to create session cookie", { cause: error });
70
+ }
71
+ };
72
+ var defineSecureCookieOptions = (useSecure, attributes, strategy) => {
73
+ if (!attributes.httpOnly) {
74
+ console.warn(
75
+ "[WARNING]: Cookie is configured without HttpOnly. This allows JavaScript access via document.cookie and increases XSS risk."
76
+ );
77
+ }
78
+ if (attributes.domain === "*") {
79
+ attributes.domain = void 0;
80
+ console.warn("[WARNING]: Cookie 'Domain' is set to '*', which is insecure. Avoid wildcard domains.");
81
+ }
82
+ if (!useSecure) {
83
+ if (attributes.secure) {
84
+ console.warn(
85
+ "[WARNING]: The 'Secure' attribute will be disabled for this cookie. Serve over HTTPS to enforce Secure cookies."
86
+ );
87
+ }
88
+ if (attributes.sameSite == "none") {
89
+ attributes.sameSite = "lax";
90
+ console.warn("[WARNING]: SameSite=None requires Secure attribute. Changing SameSite to 'Lax'.");
91
+ }
92
+ if (process.env.NODE_ENV === "production") {
93
+ console.warn("[WARNING]: In production, ensure cookies are served over HTTPS to maintain security.");
94
+ }
95
+ if (strategy === "host") {
96
+ console.warn("[WARNING]: __Host- cookies require a secure context. Falling back to standard cookie settings.");
97
+ }
98
+ return {
99
+ ...defaultCookieOptions,
100
+ ...attributes,
101
+ ...defaultStandardCookieConfig
102
+ };
103
+ }
104
+ return strategy === "host" ? {
105
+ ...defaultCookieOptions,
106
+ ...attributes,
107
+ ...defaultHostCookieConfig
108
+ } : { ...defaultCookieOptions, ...attributes, ...defaultSecureCookieConfig };
109
+ };
110
+ var createCookieStore = (useSecure, prefix, overrides) => {
111
+ prefix ??= COOKIE_NAME;
112
+ const securePrefix = useSecure ? "__Secure-" : "";
113
+ const hostPrefix = useSecure ? "__Host-" : "";
114
+ return {
115
+ sessionToken: {
116
+ name: `${securePrefix}${prefix}.${overrides?.sessionToken?.name ?? "session_token"}`,
117
+ attributes: defineSecureCookieOptions(
118
+ useSecure,
119
+ {
120
+ ...defaultCookieOptions,
121
+ ...overrides?.sessionToken?.attributes
122
+ },
123
+ overrides?.sessionToken?.attributes?.strategy ?? "secure"
124
+ )
125
+ },
126
+ state: {
127
+ name: `${securePrefix}${prefix}.${overrides?.state?.name ?? "state"}`,
128
+ attributes: defineSecureCookieOptions(
129
+ useSecure,
130
+ {
131
+ ...oauthCookieOptions,
132
+ ...overrides?.state?.attributes
133
+ },
134
+ overrides?.state?.attributes?.strategy ?? "secure"
135
+ )
136
+ },
137
+ csrfToken: {
138
+ name: `${hostPrefix}${prefix}.${overrides?.csrfToken?.name ?? "csrf_token"}`,
139
+ attributes: defineSecureCookieOptions(
140
+ useSecure,
141
+ {
142
+ ...overrides?.csrfToken?.attributes,
143
+ ...defaultHostCookieConfig
144
+ },
145
+ overrides?.csrfToken?.attributes?.strategy ?? "host"
146
+ )
147
+ },
148
+ redirectTo: {
149
+ name: `${securePrefix}${prefix}.${overrides?.redirectTo?.name ?? "redirect_to"}`,
150
+ attributes: defineSecureCookieOptions(
151
+ useSecure,
152
+ {
153
+ ...oauthCookieOptions,
154
+ ...overrides?.redirectTo?.attributes
155
+ },
156
+ overrides?.redirectTo?.attributes?.strategy ?? "secure"
157
+ )
158
+ },
159
+ redirectURI: {
160
+ name: `${securePrefix}${prefix}.${overrides?.redirectURI?.name ?? "redirect_uri"}`,
161
+ attributes: defineSecureCookieOptions(
162
+ useSecure,
163
+ {
164
+ ...oauthCookieOptions,
165
+ ...overrides?.redirectURI?.attributes
166
+ },
167
+ overrides?.redirectURI?.attributes?.strategy ?? "secure"
168
+ )
169
+ },
170
+ codeVerifier: {
171
+ name: `${securePrefix}${prefix}.${overrides?.codeVerifier?.name ?? "code_verifier"}`,
172
+ attributes: defineSecureCookieOptions(
173
+ useSecure,
174
+ {
175
+ ...oauthCookieOptions,
176
+ ...overrides?.codeVerifier?.attributes
177
+ },
178
+ overrides?.codeVerifier?.attributes?.strategy ?? "secure"
179
+ )
180
+ }
181
+ };
182
+ };
183
+
184
+ export {
185
+ COOKIE_NAME,
186
+ defaultCookieOptions,
187
+ defaultStandardCookieConfig,
188
+ defaultSecureCookieConfig,
189
+ defaultHostCookieConfig,
190
+ setCookie,
191
+ expiredCookieAttributes,
192
+ getCookie,
193
+ getSetCookie,
194
+ createSessionCookie,
195
+ defineSecureCookieOptions,
196
+ createCookieStore
197
+ };
@@ -1,10 +1,10 @@
1
1
  // src/schemas.ts
2
- import { object, string, enum as options, number, url } from "zod/v4";
2
+ import { object, string, enum as options, number, z, null as nullable } from "zod";
3
3
  var OAuthProviderConfigSchema = object({
4
- authorizeURL: url(),
5
- accessToken: url(),
4
+ authorizeURL: string().url(),
5
+ accessToken: string().url(),
6
6
  scope: string().optional(),
7
- userInfo: url(),
7
+ userInfo: string().url(),
8
8
  responseType: options(["code", "token", "id_token"]),
9
9
  clientId: string(),
10
10
  clientSecret: string()
@@ -16,8 +16,8 @@ var OAuthAuthorization = OAuthProviderConfigSchema.extend({
16
16
  codeChallengeMethod: options(["plain", "S256"])
17
17
  });
18
18
  var OAuthAuthorizationResponse = object({
19
- state: string(),
20
- code: string()
19
+ state: string({ message: "Missing state parameter in the OAuth authorization response." }),
20
+ code: string({ message: "Missing code parameter in the OAuth authorization response." })
21
21
  });
22
22
  var OAuthAuthorizationErrorResponse = object({
23
23
  error: options([
@@ -40,10 +40,10 @@ var OAuthAccessToken = OAuthProviderConfigSchema.extend({
40
40
  });
41
41
  var OAuthAccessTokenResponse = object({
42
42
  access_token: string(),
43
- token_type: string(),
43
+ token_type: string().optional(),
44
44
  expires_in: number().optional(),
45
45
  refresh_token: string().optional(),
46
- scope: string().optional()
46
+ scope: string().optional().or(nullable())
47
47
  });
48
48
  var OAuthAccessTokenErrorResponse = object({
49
49
  error: options([
@@ -61,6 +61,10 @@ var OAuthErrorResponse = object({
61
61
  error: string(),
62
62
  error_description: string().optional()
63
63
  });
64
+ var OAuthEnvSchema = object({
65
+ clientId: z.string().min(1, "OAuth Client ID is required in the environment variables."),
66
+ clientSecret: z.string().min(1, "OAuth Client Secret is required in the environment variables.")
67
+ });
64
68
 
65
69
  export {
66
70
  OAuthProviderConfigSchema,
@@ -70,5 +74,6 @@ export {
70
74
  OAuthAccessToken,
71
75
  OAuthAccessTokenResponse,
72
76
  OAuthAccessTokenErrorResponse,
73
- OAuthErrorResponse
77
+ OAuthErrorResponse,
78
+ OAuthEnvSchema
74
79
  };
@@ -0,0 +1,14 @@
1
+ // src/request.ts
2
+ var fetchAsync = async (url, options = {}, timeout = 5e3) => {
3
+ const controller = new AbortController();
4
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
5
+ const response = await fetch(url, {
6
+ ...options,
7
+ signal: controller.signal
8
+ }).finally(() => clearTimeout(timeoutId));
9
+ return response;
10
+ };
11
+
12
+ export {
13
+ fetchAsync
14
+ };