@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
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/oauth/pinterest.ts
21
+ var pinterest_exports = {};
22
+ __export(pinterest_exports, {
23
+ pinterest: () => pinterest
24
+ });
25
+ module.exports = __toCommonJS(pinterest_exports);
26
+ var pinterest = {
27
+ id: "pinterest",
28
+ name: "Pinterest",
29
+ authorizeURL: "https://api.pinterest.com/oauth/",
30
+ accessToken: "https://api.pinterest.com/v5/oauth/token",
31
+ userInfo: "https://api.pinterest.com/v5/user_account",
32
+ scope: "user_accounts:read",
33
+ responseType: "code",
34
+ profile(profile) {
35
+ return {
36
+ sub: profile.id,
37
+ name: profile.username,
38
+ email: null,
39
+ image: profile.profile_image
40
+ };
41
+ }
42
+ };
43
+ // Annotate the CommonJS export names for ESM import in node:
44
+ 0 && (module.exports = {
45
+ pinterest
46
+ });
@@ -0,0 +1,7 @@
1
+ export { P as PinterestProfile, p as pinterest } from '../index-DkaLJFn8.js';
2
+ import '../@types/utility.js';
3
+ import 'zod';
4
+ import '../schemas.js';
5
+ import '@aura-stack/router/cookie';
6
+ import '@aura-stack/jose';
7
+ import '@aura-stack/jose/jose';
@@ -0,0 +1,6 @@
1
+ import {
2
+ pinterest
3
+ } from "../chunk-HP34YGGJ.js";
4
+ export {
5
+ pinterest
6
+ };
@@ -1,7 +1,7 @@
1
- export { g as SpotifyProfile, s as spotify } from '../index-DpfbvTZ_.js';
2
- import 'zod/v4';
3
- import '@aura-stack/jose/jose';
1
+ export { I as Image, o as SpotifyProfile, q as spotify } from '../index-DkaLJFn8.js';
2
+ import 'zod';
4
3
  import '../schemas.js';
5
- import 'zod/v4/core';
6
- import 'cookie';
4
+ import '@aura-stack/router/cookie';
5
+ import '@aura-stack/jose';
6
+ import '@aura-stack/jose/jose';
7
7
  import '../@types/utility.js';
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/oauth/strava.ts
21
+ var strava_exports = {};
22
+ __export(strava_exports, {
23
+ strava: () => strava
24
+ });
25
+ module.exports = __toCommonJS(strava_exports);
26
+ var strava = {
27
+ id: "strava",
28
+ name: "Strava",
29
+ authorizeURL: "https://www.strava.com/oauth/authorize",
30
+ accessToken: "https://www.strava.com/oauth/token",
31
+ userInfo: "https://www.strava.com/api/v3/athlete",
32
+ scope: "read",
33
+ responseType: "code",
34
+ profile(profile) {
35
+ return {
36
+ sub: profile.id.toString(),
37
+ name: `${profile.firstname} ${profile.lastname}`,
38
+ image: profile.profile,
39
+ email: ""
40
+ };
41
+ }
42
+ };
43
+ // Annotate the CommonJS export names for ESM import in node:
44
+ 0 && (module.exports = {
45
+ strava
46
+ });
@@ -0,0 +1,7 @@
1
+ export { n as StravaProfile, k as SummaryClub, l as SummaryGear, s as strava } from '../index-DkaLJFn8.js';
2
+ import 'zod';
3
+ import '../schemas.js';
4
+ import '@aura-stack/router/cookie';
5
+ import '@aura-stack/jose';
6
+ import '@aura-stack/jose/jose';
7
+ import '../@types/utility.js';
@@ -0,0 +1,6 @@
1
+ import {
2
+ strava
3
+ } from "../chunk-6R2YZ4AC.js";
4
+ export {
5
+ strava
6
+ };
package/dist/oauth/x.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- export { X as XProfile, x } from '../index-DpfbvTZ_.js';
2
- import 'zod/v4';
3
- import '@aura-stack/jose/jose';
1
+ export { X as XProfile, x } from '../index-DkaLJFn8.js';
2
+ import 'zod';
4
3
  import '../schemas.js';
5
- import 'zod/v4/core';
6
- import 'cookie';
4
+ import '@aura-stack/router/cookie';
5
+ import '@aura-stack/jose';
6
+ import '@aura-stack/jose/jose';
7
7
  import '../@types/utility.js';
@@ -17,18 +17,22 @@ var __copyProps = (to, from, except, desc) => {
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
 
20
- // src/response.ts
21
- var response_exports = {};
22
- __export(response_exports, {
23
- AuraResponse: () => AuraResponse
20
+ // src/request.ts
21
+ var request_exports = {};
22
+ __export(request_exports, {
23
+ fetchAsync: () => fetchAsync
24
24
  });
25
- module.exports = __toCommonJS(response_exports);
26
- var AuraResponse = class extends Response {
27
- static json(body, init) {
28
- return Response.json(body, init);
29
- }
25
+ module.exports = __toCommonJS(request_exports);
26
+ var fetchAsync = async (url, options = {}, timeout = 5e3) => {
27
+ const controller = new AbortController();
28
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
29
+ const response = await fetch(url, {
30
+ ...options,
31
+ signal: controller.signal
32
+ }).finally(() => clearTimeout(timeoutId));
33
+ return response;
30
34
  };
31
35
  // Annotate the CommonJS export names for ESM import in node:
32
36
  0 && (module.exports = {
33
- AuraResponse
37
+ fetchAsync
34
38
  });
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Fetches a resource with a timeout mechanism.
3
+ *
4
+ * @param url - The URL or Request object to fetch
5
+ * @param options - Optional RequestInit configuration object
6
+ * @param timeout - Timeout duration in milliseconds (default: 5000ms)
7
+ * @returns A promise that resolves to the Response object
8
+ * @example
9
+ * const response = await fetchAsync('https://api.example.com/data', {}, 3000);
10
+ */
11
+ declare const fetchAsync: (url: string | Request, options?: RequestInit, timeout?: number) => Promise<Response>;
12
+
13
+ export { fetchAsync };
@@ -0,0 +1,6 @@
1
+ import {
2
+ fetchAsync
3
+ } from "./chunk-ZNCZVF6U.js";
4
+ export {
5
+ fetchAsync
6
+ };
package/dist/schemas.cjs CHANGED
@@ -26,32 +26,33 @@ __export(schemas_exports, {
26
26
  OAuthAuthorization: () => OAuthAuthorization,
27
27
  OAuthAuthorizationErrorResponse: () => OAuthAuthorizationErrorResponse,
28
28
  OAuthAuthorizationResponse: () => OAuthAuthorizationResponse,
29
+ OAuthEnvSchema: () => OAuthEnvSchema,
29
30
  OAuthErrorResponse: () => OAuthErrorResponse,
30
31
  OAuthProviderConfigSchema: () => OAuthProviderConfigSchema
31
32
  });
32
33
  module.exports = __toCommonJS(schemas_exports);
33
- var import_v4 = require("zod/v4");
34
- var OAuthProviderConfigSchema = (0, import_v4.object)({
35
- authorizeURL: (0, import_v4.url)(),
36
- accessToken: (0, import_v4.url)(),
37
- scope: (0, import_v4.string)().optional(),
38
- userInfo: (0, import_v4.url)(),
39
- responseType: (0, import_v4.enum)(["code", "token", "id_token"]),
40
- clientId: (0, import_v4.string)(),
41
- clientSecret: (0, import_v4.string)()
34
+ var import_zod = require("zod");
35
+ var OAuthProviderConfigSchema = (0, import_zod.object)({
36
+ authorizeURL: (0, import_zod.string)().url(),
37
+ accessToken: (0, import_zod.string)().url(),
38
+ scope: (0, import_zod.string)().optional(),
39
+ userInfo: (0, import_zod.string)().url(),
40
+ responseType: (0, import_zod.enum)(["code", "token", "id_token"]),
41
+ clientId: (0, import_zod.string)(),
42
+ clientSecret: (0, import_zod.string)()
42
43
  });
43
44
  var OAuthAuthorization = OAuthProviderConfigSchema.extend({
44
- redirectURI: (0, import_v4.string)(),
45
- state: (0, import_v4.string)(),
46
- codeChallenge: (0, import_v4.string)(),
47
- codeChallengeMethod: (0, import_v4.enum)(["plain", "S256"])
45
+ redirectURI: (0, import_zod.string)(),
46
+ state: (0, import_zod.string)(),
47
+ codeChallenge: (0, import_zod.string)(),
48
+ codeChallengeMethod: (0, import_zod.enum)(["plain", "S256"])
48
49
  });
49
- var OAuthAuthorizationResponse = (0, import_v4.object)({
50
- state: (0, import_v4.string)(),
51
- code: (0, import_v4.string)()
50
+ var OAuthAuthorizationResponse = (0, import_zod.object)({
51
+ state: (0, import_zod.string)({ message: "Missing state parameter in the OAuth authorization response." }),
52
+ code: (0, import_zod.string)({ message: "Missing code parameter in the OAuth authorization response." })
52
53
  });
53
- var OAuthAuthorizationErrorResponse = (0, import_v4.object)({
54
- error: (0, import_v4.enum)([
54
+ var OAuthAuthorizationErrorResponse = (0, import_zod.object)({
55
+ error: (0, import_zod.enum)([
55
56
  "invalid_request",
56
57
  "unauthorized_client",
57
58
  "access_denied",
@@ -60,24 +61,24 @@ var OAuthAuthorizationErrorResponse = (0, import_v4.object)({
60
61
  "server_error",
61
62
  "temporarily_unavailable"
62
63
  ]),
63
- error_description: (0, import_v4.string)().optional(),
64
- error_uri: (0, import_v4.string)().optional(),
65
- state: (0, import_v4.string)()
64
+ error_description: (0, import_zod.string)().optional(),
65
+ error_uri: (0, import_zod.string)().optional(),
66
+ state: (0, import_zod.string)()
66
67
  });
67
68
  var OAuthAccessToken = OAuthProviderConfigSchema.extend({
68
- redirectURI: (0, import_v4.string)(),
69
- code: (0, import_v4.string)(),
70
- codeVerifier: (0, import_v4.string)().min(43).max(128)
69
+ redirectURI: (0, import_zod.string)(),
70
+ code: (0, import_zod.string)(),
71
+ codeVerifier: (0, import_zod.string)().min(43).max(128)
71
72
  });
72
- var OAuthAccessTokenResponse = (0, import_v4.object)({
73
- access_token: (0, import_v4.string)(),
74
- token_type: (0, import_v4.string)(),
75
- expires_in: (0, import_v4.number)().optional(),
76
- refresh_token: (0, import_v4.string)().optional(),
77
- scope: (0, import_v4.string)().optional()
73
+ var OAuthAccessTokenResponse = (0, import_zod.object)({
74
+ access_token: (0, import_zod.string)(),
75
+ token_type: (0, import_zod.string)().optional(),
76
+ expires_in: (0, import_zod.number)().optional(),
77
+ refresh_token: (0, import_zod.string)().optional(),
78
+ scope: (0, import_zod.string)().optional().or((0, import_zod.null)())
78
79
  });
79
- var OAuthAccessTokenErrorResponse = (0, import_v4.object)({
80
- error: (0, import_v4.enum)([
80
+ var OAuthAccessTokenErrorResponse = (0, import_zod.object)({
81
+ error: (0, import_zod.enum)([
81
82
  "invalid_request",
82
83
  "invalid_client",
83
84
  "invalid_grant",
@@ -85,12 +86,16 @@ var OAuthAccessTokenErrorResponse = (0, import_v4.object)({
85
86
  "unsupported_grant_type",
86
87
  "invalid_scope"
87
88
  ]),
88
- error_description: (0, import_v4.string)().optional(),
89
- error_uri: (0, import_v4.string)().optional()
89
+ error_description: (0, import_zod.string)().optional(),
90
+ error_uri: (0, import_zod.string)().optional()
90
91
  });
91
- var OAuthErrorResponse = (0, import_v4.object)({
92
- error: (0, import_v4.string)(),
93
- error_description: (0, import_v4.string)().optional()
92
+ var OAuthErrorResponse = (0, import_zod.object)({
93
+ error: (0, import_zod.string)(),
94
+ error_description: (0, import_zod.string)().optional()
95
+ });
96
+ var OAuthEnvSchema = (0, import_zod.object)({
97
+ clientId: import_zod.z.string().min(1, "OAuth Client ID is required in the environment variables."),
98
+ clientSecret: import_zod.z.string().min(1, "OAuth Client Secret is required in the environment variables.")
94
99
  });
95
100
  // Annotate the CommonJS export names for ESM import in node:
96
101
  0 && (module.exports = {
@@ -100,6 +105,7 @@ var OAuthErrorResponse = (0, import_v4.object)({
100
105
  OAuthAuthorization,
101
106
  OAuthAuthorizationErrorResponse,
102
107
  OAuthAuthorizationResponse,
108
+ OAuthEnvSchema,
103
109
  OAuthErrorResponse,
104
110
  OAuthProviderConfigSchema
105
111
  });
package/dist/schemas.d.ts CHANGED
@@ -1,63 +1,62 @@
1
- import * as zod_v4_core from 'zod/v4/core';
2
- import * as zod_v4 from 'zod/v4';
1
+ import { z } from 'zod';
3
2
 
4
3
  /**
5
4
  * Schema for OAuth Provider Configuration
6
5
  */
7
- declare const OAuthProviderConfigSchema: zod_v4.ZodObject<{
8
- authorizeURL: zod_v4.ZodURL;
9
- accessToken: zod_v4.ZodURL;
10
- scope: zod_v4.ZodOptional<zod_v4.ZodString>;
11
- userInfo: zod_v4.ZodURL;
12
- responseType: zod_v4.ZodEnum<{
6
+ declare const OAuthProviderConfigSchema: z.ZodObject<{
7
+ authorizeURL: z.ZodString;
8
+ accessToken: z.ZodString;
9
+ scope: z.ZodOptional<z.ZodString>;
10
+ userInfo: z.ZodString;
11
+ responseType: z.ZodEnum<{
13
12
  token: "token";
14
13
  code: "code";
15
14
  id_token: "id_token";
16
15
  }>;
17
- clientId: zod_v4.ZodString;
18
- clientSecret: zod_v4.ZodString;
19
- }, zod_v4_core.$strip>;
16
+ clientId: z.ZodString;
17
+ clientSecret: z.ZodString;
18
+ }, z.core.$strip>;
20
19
  /**
21
20
  * Schema used to create the authorization URL for the OAuth flow and verify the
22
21
  * OAuth configuration.
23
22
  * @see https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.1
24
23
  */
25
- declare const OAuthAuthorization: zod_v4.ZodObject<{
26
- authorizeURL: zod_v4.ZodURL;
27
- accessToken: zod_v4.ZodURL;
28
- scope: zod_v4.ZodOptional<zod_v4.ZodString>;
29
- userInfo: zod_v4.ZodURL;
30
- responseType: zod_v4.ZodEnum<{
24
+ declare const OAuthAuthorization: z.ZodObject<{
25
+ authorizeURL: z.ZodString;
26
+ accessToken: z.ZodString;
27
+ scope: z.ZodOptional<z.ZodString>;
28
+ userInfo: z.ZodString;
29
+ responseType: z.ZodEnum<{
31
30
  token: "token";
32
31
  code: "code";
33
32
  id_token: "id_token";
34
33
  }>;
35
- clientId: zod_v4.ZodString;
36
- clientSecret: zod_v4.ZodString;
37
- redirectURI: zod_v4.ZodString;
38
- state: zod_v4.ZodString;
39
- codeChallenge: zod_v4.ZodString;
40
- codeChallengeMethod: zod_v4.ZodEnum<{
41
- S256: "S256";
34
+ clientId: z.ZodString;
35
+ clientSecret: z.ZodString;
36
+ redirectURI: z.ZodString;
37
+ state: z.ZodString;
38
+ codeChallenge: z.ZodString;
39
+ codeChallengeMethod: z.ZodEnum<{
42
40
  plain: "plain";
41
+ S256: "S256";
43
42
  }>;
44
- }, zod_v4_core.$strip>;
43
+ }, z.core.$strip>;
45
44
  /**
46
45
  * Schema used in the callback action to validate the authorization response when the resource owner
47
46
  * has granted.
48
47
  * @see https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.2
49
48
  */
50
- declare const OAuthAuthorizationResponse: zod_v4.ZodObject<{
51
- state: zod_v4.ZodString;
52
- code: zod_v4.ZodString;
53
- }, zod_v4_core.$strip>;
49
+ declare const OAuthAuthorizationResponse: z.ZodObject<{
50
+ state: z.ZodString;
51
+ code: z.ZodString;
52
+ }, z.core.$strip>;
54
53
  /**
55
54
  * Schema used in the callback action to validate the authorization error response when the resource owner
56
55
  * has denied the authorization request.
57
56
  * @see https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.2.1
58
57
  */
59
- declare const OAuthAuthorizationErrorResponse: zod_v4.ZodObject<{
60
- error: zod_v4.ZodEnum<{
58
+ declare const OAuthAuthorizationErrorResponse: z.ZodObject<{
59
+ error: z.ZodEnum<{
61
60
  invalid_request: "invalid_request";
62
61
  unauthorized_client: "unauthorized_client";
63
62
  access_denied: "access_denied";
@@ -66,48 +65,48 @@ declare const OAuthAuthorizationErrorResponse: zod_v4.ZodObject<{
66
65
  server_error: "server_error";
67
66
  temporarily_unavailable: "temporarily_unavailable";
68
67
  }>;
69
- error_description: zod_v4.ZodOptional<zod_v4.ZodString>;
70
- error_uri: zod_v4.ZodOptional<zod_v4.ZodString>;
71
- state: zod_v4.ZodString;
72
- }, zod_v4_core.$strip>;
68
+ error_description: z.ZodOptional<z.ZodString>;
69
+ error_uri: z.ZodOptional<z.ZodString>;
70
+ state: z.ZodString;
71
+ }, z.core.$strip>;
73
72
  /**
74
73
  * Schema for OAuth Access Token Request and OAuth Configuration
75
74
  * @see https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.3
76
75
  */
77
- declare const OAuthAccessToken: zod_v4.ZodObject<{
78
- authorizeURL: zod_v4.ZodURL;
79
- accessToken: zod_v4.ZodURL;
80
- scope: zod_v4.ZodOptional<zod_v4.ZodString>;
81
- userInfo: zod_v4.ZodURL;
82
- responseType: zod_v4.ZodEnum<{
76
+ declare const OAuthAccessToken: z.ZodObject<{
77
+ authorizeURL: z.ZodString;
78
+ accessToken: z.ZodString;
79
+ scope: z.ZodOptional<z.ZodString>;
80
+ userInfo: z.ZodString;
81
+ responseType: z.ZodEnum<{
83
82
  token: "token";
84
83
  code: "code";
85
84
  id_token: "id_token";
86
85
  }>;
87
- clientId: zod_v4.ZodString;
88
- clientSecret: zod_v4.ZodString;
89
- redirectURI: zod_v4.ZodString;
90
- code: zod_v4.ZodString;
91
- codeVerifier: zod_v4.ZodString;
92
- }, zod_v4_core.$strip>;
86
+ clientId: z.ZodString;
87
+ clientSecret: z.ZodString;
88
+ redirectURI: z.ZodString;
89
+ code: z.ZodString;
90
+ codeVerifier: z.ZodString;
91
+ }, z.core.$strip>;
93
92
  /**
94
93
  * Schema for OAuth Access Token Response
95
94
  * @see https://datatracker.ietf.org/doc/html/rfc6749#section-5.1
96
95
  * @see https://datatracker.ietf.org/doc/html/rfc7636#section-4
97
96
  */
98
- declare const OAuthAccessTokenResponse: zod_v4.ZodObject<{
99
- access_token: zod_v4.ZodString;
100
- token_type: zod_v4.ZodString;
101
- expires_in: zod_v4.ZodOptional<zod_v4.ZodNumber>;
102
- refresh_token: zod_v4.ZodOptional<zod_v4.ZodString>;
103
- scope: zod_v4.ZodOptional<zod_v4.ZodString>;
104
- }, zod_v4_core.$strip>;
97
+ declare const OAuthAccessTokenResponse: z.ZodObject<{
98
+ access_token: z.ZodString;
99
+ token_type: z.ZodOptional<z.ZodString>;
100
+ expires_in: z.ZodOptional<z.ZodNumber>;
101
+ refresh_token: z.ZodOptional<z.ZodString>;
102
+ scope: z.ZodUnion<[z.ZodOptional<z.ZodString>, z.ZodNull]>;
103
+ }, z.core.$strip>;
105
104
  /**
106
105
  * Schema for OAuth Access Token Error Response
107
106
  * @see https://datatracker.ietf.org/doc/html/rfc6749#section-5.2
108
107
  */
109
- declare const OAuthAccessTokenErrorResponse: zod_v4.ZodObject<{
110
- error: zod_v4.ZodEnum<{
108
+ declare const OAuthAccessTokenErrorResponse: z.ZodObject<{
109
+ error: z.ZodEnum<{
111
110
  invalid_request: "invalid_request";
112
111
  unauthorized_client: "unauthorized_client";
113
112
  invalid_scope: "invalid_scope";
@@ -115,16 +114,20 @@ declare const OAuthAccessTokenErrorResponse: zod_v4.ZodObject<{
115
114
  invalid_grant: "invalid_grant";
116
115
  unsupported_grant_type: "unsupported_grant_type";
117
116
  }>;
118
- error_description: zod_v4.ZodOptional<zod_v4.ZodString>;
119
- error_uri: zod_v4.ZodOptional<zod_v4.ZodString>;
120
- }, zod_v4_core.$strip>;
117
+ error_description: z.ZodOptional<z.ZodString>;
118
+ error_uri: z.ZodOptional<z.ZodString>;
119
+ }, z.core.$strip>;
121
120
  /**
122
121
  * @todo: verify if this schema is still needed
123
122
  * @deprecated
124
123
  */
125
- declare const OAuthErrorResponse: zod_v4.ZodObject<{
126
- error: zod_v4.ZodString;
127
- error_description: zod_v4.ZodOptional<zod_v4.ZodString>;
128
- }, zod_v4_core.$strip>;
124
+ declare const OAuthErrorResponse: z.ZodObject<{
125
+ error: z.ZodString;
126
+ error_description: z.ZodOptional<z.ZodString>;
127
+ }, z.core.$strip>;
128
+ declare const OAuthEnvSchema: z.ZodObject<{
129
+ clientId: z.ZodString;
130
+ clientSecret: z.ZodString;
131
+ }, z.core.$strip>;
129
132
 
130
- export { OAuthAccessToken, OAuthAccessTokenErrorResponse, OAuthAccessTokenResponse, OAuthAuthorization, OAuthAuthorizationErrorResponse, OAuthAuthorizationResponse, OAuthErrorResponse, OAuthProviderConfigSchema };
133
+ export { OAuthAccessToken, OAuthAccessTokenErrorResponse, OAuthAccessTokenResponse, OAuthAuthorization, OAuthAuthorizationErrorResponse, OAuthAuthorizationResponse, OAuthEnvSchema, OAuthErrorResponse, OAuthProviderConfigSchema };
package/dist/schemas.js CHANGED
@@ -5,9 +5,10 @@ import {
5
5
  OAuthAuthorization,
6
6
  OAuthAuthorizationErrorResponse,
7
7
  OAuthAuthorizationResponse,
8
+ OAuthEnvSchema,
8
9
  OAuthErrorResponse,
9
10
  OAuthProviderConfigSchema
10
- } from "./chunk-HMRKN75I.js";
11
+ } from "./chunk-YRCB5FLE.js";
11
12
  export {
12
13
  OAuthAccessToken,
13
14
  OAuthAccessTokenErrorResponse,
@@ -15,6 +16,7 @@ export {
15
16
  OAuthAuthorization,
16
17
  OAuthAuthorizationErrorResponse,
17
18
  OAuthAuthorizationResponse,
19
+ OAuthEnvSchema,
18
20
  OAuthErrorResponse,
19
21
  OAuthProviderConfigSchema
20
22
  };
package/dist/secure.cjs CHANGED
@@ -38,23 +38,20 @@ __export(secure_exports, {
38
38
  verifyCSRF: () => verifyCSRF
39
39
  });
40
40
  module.exports = __toCommonJS(secure_exports);
41
- var import_node_crypto = __toESM(require("crypto"), 1);
41
+ var import_crypto = __toESM(require("crypto"), 1);
42
42
 
43
43
  // src/utils.ts
44
44
  var import_router = require("@aura-stack/router");
45
45
 
46
- // src/error.ts
47
- var AuthError = class extends Error {
48
- constructor(type, message) {
49
- super(message);
50
- this.type = type;
51
- this.name = "AuthError";
52
- }
53
- };
54
- var InvalidCsrfTokenError = class extends AuthError {
55
- constructor(message = "The provided CSRF token is invalid or has expired") {
56
- super("invalid_csrf_token", message);
57
- this.name = "InvalidCsrfTokenError";
46
+ // src/errors.ts
47
+ var AuthSecurityError = class extends Error {
48
+ type = "AUTH_SECURITY_ERROR";
49
+ code;
50
+ constructor(code, message, options) {
51
+ super(message, options);
52
+ this.code = code;
53
+ this.name = new.target.name;
54
+ Error.captureStackTrace(this, new.target);
58
55
  }
59
56
  };
60
57
 
@@ -64,12 +61,17 @@ var equals = (a, b) => {
64
61
  return a === b;
65
62
  };
66
63
 
64
+ // src/assert.ts
65
+ var isJWTPayloadWithToken = (payload) => {
66
+ return typeof payload === "object" && payload !== null && "token" in payload && typeof payload?.token === "string";
67
+ };
68
+
67
69
  // src/secure.ts
68
70
  var generateSecure = (length = 32) => {
69
- return import_node_crypto.default.randomBytes(length).toString("base64url");
71
+ return import_crypto.default.randomBytes(length).toString("base64url");
70
72
  };
71
73
  var createHash = (data, base = "hex") => {
72
- return import_node_crypto.default.createHash("sha256").update(data).digest().toString(base);
74
+ return import_crypto.default.createHash("sha256").update(data).digest().toString(base);
73
75
  };
74
76
  var createPKCE = async (verifier) => {
75
77
  const codeVerifier = verifier ?? generateSecure(86);
@@ -91,23 +93,29 @@ var createCSRF = async (jose, csrfCookie) => {
91
93
  };
92
94
  var verifyCSRF = async (jose, cookie, header) => {
93
95
  try {
94
- const { token: cookieToken } = await jose.verifyJWS(cookie);
95
- const { token: headerToken } = await jose.verifyJWS(header);
96
- const cookieBuffer = Buffer.from(cookieToken);
97
- const headerBuffer = Buffer.from(headerToken);
96
+ const cookiePayload = await jose.verifyJWS(cookie);
97
+ const headerPayload = await jose.verifyJWS(header);
98
+ if (!isJWTPayloadWithToken(cookiePayload)) {
99
+ throw new AuthSecurityError("CSRF_TOKEN_INVALID", "Cookie payload missing token field.");
100
+ }
101
+ if (!isJWTPayloadWithToken(headerPayload)) {
102
+ throw new AuthSecurityError("CSRF_TOKEN_INVALID", "Header payload missing token field.");
103
+ }
104
+ const cookieBuffer = Buffer.from(cookiePayload.token);
105
+ const headerBuffer = Buffer.from(headerPayload.token);
98
106
  if (!equals(headerBuffer.length, cookieBuffer.length)) {
99
- throw new InvalidCsrfTokenError();
107
+ throw new AuthSecurityError("CSRF_TOKEN_INVALID", "The CSRF tokens do not match.");
100
108
  }
101
- if (!import_node_crypto.default.timingSafeEqual(cookieBuffer, headerBuffer)) {
102
- throw new InvalidCsrfTokenError();
109
+ if (!import_crypto.default.timingSafeEqual(cookieBuffer, headerBuffer)) {
110
+ throw new AuthSecurityError("CSRF_TOKEN_INVALID", "The CSRF tokens do not match.");
103
111
  }
104
112
  return true;
105
113
  } catch {
106
- throw new InvalidCsrfTokenError();
114
+ throw new AuthSecurityError("CSRF_TOKEN_INVALID", "The CSRF tokens do not match.");
107
115
  }
108
116
  };
109
117
  var createDerivedSalt = (secret) => {
110
- return import_node_crypto.default.createHash("sha256").update(secret).update("aura-auth-salt").digest("hex");
118
+ return import_crypto.default.createHash("sha256").update(secret).update("aura-auth-salt").digest("hex");
111
119
  };
112
120
  // Annotate the CommonJS export names for ESM import in node:
113
121
  0 && (module.exports = {
package/dist/secure.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { A as AuthRuntimeConfig } from './index-DpfbvTZ_.js';
2
- import 'zod/v4';
3
- import '@aura-stack/jose/jose';
1
+ import { A as AuthRuntimeConfig } from './index-DkaLJFn8.js';
2
+ import 'zod';
4
3
  import './schemas.js';
5
- import 'zod/v4/core';
6
- import 'cookie';
4
+ import '@aura-stack/router/cookie';
5
+ import '@aura-stack/jose';
6
+ import '@aura-stack/jose/jose';
7
7
  import './@types/utility.js';
8
8
 
9
9
  declare const generateSecure: (length?: number) => string;