@aura-stack/auth 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (179) hide show
  1. package/README.md +36 -1
  2. package/dist/@types/index.cjs +0 -18
  3. package/dist/@types/index.d.ts +2 -8
  4. package/dist/@types/index.js +0 -1
  5. package/dist/assert-B3iQSYlK.js +3 -0
  6. package/dist/assert-NJGroSJd.cjs +3 -0
  7. package/dist/client/index.cjs +1 -0
  8. package/dist/client/index.d.ts +11 -0
  9. package/dist/client/index.js +1 -0
  10. package/dist/crypto-Bz8nIciY.js +1 -0
  11. package/dist/crypto-CoXA5w_4.cjs +1 -0
  12. package/dist/env-bq387KyP.cjs +1 -0
  13. package/dist/env-nvh8QBNz.js +1 -0
  14. package/dist/errors-CCYPHuBO.cjs +1 -0
  15. package/dist/errors-DFWHOho6.js +1 -0
  16. package/dist/index-BkpwQ0l4.d.cts +2279 -0
  17. package/dist/index-nqLV2t91.d.ts +2279 -0
  18. package/dist/index.cjs +1 -1839
  19. package/dist/index.d.cts +2 -0
  20. package/dist/index.d.ts +2 -35
  21. package/dist/index.js +1 -132
  22. package/dist/logger-C59_CDMk.js +1 -0
  23. package/dist/logger-UnUhYL2V.cjs +1 -0
  24. package/dist/oauth/atlassian.cjs +1 -0
  25. package/dist/oauth/atlassian.d.ts +2 -0
  26. package/dist/oauth/atlassian.js +1 -0
  27. package/dist/oauth/bitbucket.cjs +1 -49
  28. package/dist/oauth/bitbucket.d.ts +2 -8
  29. package/dist/oauth/bitbucket.js +1 -6
  30. package/dist/oauth/discord.cjs +1 -57
  31. package/dist/oauth/discord.d.ts +2 -8
  32. package/dist/oauth/discord.js +1 -6
  33. package/dist/oauth/dropbox.cjs +1 -0
  34. package/dist/oauth/dropbox.d.ts +2 -0
  35. package/dist/oauth/dropbox.js +1 -0
  36. package/dist/oauth/figma.cjs +1 -49
  37. package/dist/oauth/figma.d.ts +2 -8
  38. package/dist/oauth/figma.js +1 -6
  39. package/dist/oauth/github.cjs +1 -49
  40. package/dist/oauth/github.d.ts +2 -8
  41. package/dist/oauth/github.js +1 -6
  42. package/dist/oauth/gitlab.cjs +1 -49
  43. package/dist/oauth/gitlab.d.ts +2 -8
  44. package/dist/oauth/gitlab.js +1 -6
  45. package/dist/oauth/index.cjs +1 -483
  46. package/dist/oauth/index.d.ts +2 -8
  47. package/dist/oauth/index.js +1 -52
  48. package/dist/oauth/mailchimp.cjs +1 -49
  49. package/dist/oauth/mailchimp.d.ts +2 -8
  50. package/dist/oauth/mailchimp.js +1 -6
  51. package/dist/oauth/notion.cjs +1 -0
  52. package/dist/oauth/notion.d.ts +2 -0
  53. package/dist/oauth/notion.js +1 -0
  54. package/dist/oauth/pinterest.cjs +1 -49
  55. package/dist/oauth/pinterest.d.ts +2 -8
  56. package/dist/oauth/pinterest.js +1 -6
  57. package/dist/oauth/spotify.cjs +1 -49
  58. package/dist/oauth/spotify.d.ts +2 -8
  59. package/dist/oauth/spotify.js +1 -6
  60. package/dist/oauth/strava.cjs +1 -49
  61. package/dist/oauth/strava.d.ts +2 -8
  62. package/dist/oauth/strava.js +1 -6
  63. package/dist/oauth/twitch.cjs +1 -0
  64. package/dist/oauth/twitch.d.ts +2 -0
  65. package/dist/oauth/twitch.js +1 -0
  66. package/dist/oauth/x.cjs +1 -49
  67. package/dist/oauth/x.d.ts +2 -8
  68. package/dist/oauth/x.js +1 -6
  69. package/dist/oauth-BntNm6aE.cjs +1 -0
  70. package/dist/oauth-DmHy9VrB.js +1 -0
  71. package/dist/shared/crypto.cjs +1 -0
  72. package/dist/shared/crypto.d.ts +47 -0
  73. package/dist/shared/crypto.js +1 -0
  74. package/dist/shared/identity.cjs +1 -0
  75. package/dist/shared/identity.d.ts +2 -0
  76. package/dist/shared/identity.js +1 -0
  77. package/dist/shared/index.cjs +1 -0
  78. package/dist/shared/index.d.ts +5 -0
  79. package/dist/shared/index.js +1 -0
  80. package/package.json +39 -12
  81. package/dist/@types/router.d.cjs +0 -1
  82. package/dist/@types/router.d.d.ts +0 -12
  83. package/dist/@types/router.d.js +0 -0
  84. package/dist/@types/utility.cjs +0 -18
  85. package/dist/@types/utility.d.ts +0 -6
  86. package/dist/@types/utility.js +0 -1
  87. package/dist/actions/callback/access-token.cjs +0 -206
  88. package/dist/actions/callback/access-token.d.ts +0 -29
  89. package/dist/actions/callback/access-token.js +0 -9
  90. package/dist/actions/callback/callback.cjs +0 -649
  91. package/dist/actions/callback/callback.d.ts +0 -13
  92. package/dist/actions/callback/callback.js +0 -19
  93. package/dist/actions/callback/userinfo.cjs +0 -250
  94. package/dist/actions/callback/userinfo.d.ts +0 -21
  95. package/dist/actions/callback/userinfo.js +0 -14
  96. package/dist/actions/csrfToken/csrfToken.cjs +0 -197
  97. package/dist/actions/csrfToken/csrfToken.d.ts +0 -5
  98. package/dist/actions/csrfToken/csrfToken.js +0 -14
  99. package/dist/actions/index.cjs +0 -954
  100. package/dist/actions/index.d.ts +0 -14
  101. package/dist/actions/index.js +0 -36
  102. package/dist/actions/session/session.cjs +0 -136
  103. package/dist/actions/session/session.d.ts +0 -5
  104. package/dist/actions/session/session.js +0 -10
  105. package/dist/actions/signIn/authorization.cjs +0 -322
  106. package/dist/actions/signIn/authorization.d.ts +0 -53
  107. package/dist/actions/signIn/authorization.js +0 -18
  108. package/dist/actions/signIn/signIn.cjs +0 -467
  109. package/dist/actions/signIn/signIn.d.ts +0 -13
  110. package/dist/actions/signIn/signIn.js +0 -15
  111. package/dist/actions/signOut/signOut.cjs +0 -493
  112. package/dist/actions/signOut/signOut.d.ts +0 -8
  113. package/dist/actions/signOut/signOut.js +0 -16
  114. package/dist/assert.cjs +0 -161
  115. package/dist/assert.d.ts +0 -33
  116. package/dist/assert.js +0 -26
  117. package/dist/chunk-4EKY7655.js +0 -123
  118. package/dist/chunk-4MYWAOLG.js +0 -31
  119. package/dist/chunk-4YHJ4IEQ.js +0 -25
  120. package/dist/chunk-54CZPKR4.js +0 -25
  121. package/dist/chunk-5LZ7TOM3.js +0 -25
  122. package/dist/chunk-5W4BRQYG.js +0 -201
  123. package/dist/chunk-6MXFPFR3.js +0 -143
  124. package/dist/chunk-7QF22LHP.js +0 -67
  125. package/dist/chunk-ALG3GIV4.js +0 -95
  126. package/dist/chunk-E6G5YCI6.js +0 -25
  127. package/dist/chunk-EBAMFRB7.js +0 -34
  128. package/dist/chunk-EEE7UM5T.js +0 -25
  129. package/dist/chunk-FRJFWTOY.js +0 -70
  130. package/dist/chunk-FW4W3REU.js +0 -25
  131. package/dist/chunk-ICAZ4OVS.js +0 -37
  132. package/dist/chunk-IPKO6UQN.js +0 -25
  133. package/dist/chunk-ITQ7352M.js +0 -0
  134. package/dist/chunk-KJBAQZX2.js +0 -92
  135. package/dist/chunk-KMMAZFSJ.js +0 -25
  136. package/dist/chunk-LDU7A2JE.js +0 -25
  137. package/dist/chunk-NUDITUKX.js +0 -73
  138. package/dist/chunk-OVHNRULD.js +0 -33
  139. package/dist/chunk-PG7UYFG5.js +0 -0
  140. package/dist/chunk-PHFH2MGS.js +0 -36
  141. package/dist/chunk-QQVSRXGX.js +0 -149
  142. package/dist/chunk-RRLIF4PQ.js +0 -55
  143. package/dist/chunk-TM5IPSNF.js +0 -113
  144. package/dist/chunk-TZB6MUXN.js +0 -78
  145. package/dist/chunk-VNCNJKS2.js +0 -267
  146. package/dist/chunk-XGLBNXL4.js +0 -75
  147. package/dist/chunk-XUP6KKNG.js +0 -106
  148. package/dist/chunk-ZNCZVF6U.js +0 -14
  149. package/dist/cookie.cjs +0 -246
  150. package/dist/cookie.d.ts +0 -85
  151. package/dist/cookie.js +0 -29
  152. package/dist/env.cjs +0 -56
  153. package/dist/env.d.ts +0 -7
  154. package/dist/env.js +0 -6
  155. package/dist/errors.cjs +0 -85
  156. package/dist/errors.d.ts +0 -50
  157. package/dist/errors.js +0 -18
  158. package/dist/headers.cjs +0 -61
  159. package/dist/headers.d.ts +0 -33
  160. package/dist/headers.js +0 -12
  161. package/dist/index-CSyIJmCM.d.ts +0 -1007
  162. package/dist/jose.cjs +0 -128
  163. package/dist/jose.d.ts +0 -25
  164. package/dist/jose.js +0 -12
  165. package/dist/logger.cjs +0 -292
  166. package/dist/logger.d.ts +0 -8
  167. package/dist/logger.js +0 -8
  168. package/dist/request.cjs +0 -38
  169. package/dist/request.d.ts +0 -13
  170. package/dist/request.js +0 -6
  171. package/dist/schemas.cjs +0 -125
  172. package/dist/schemas.d.ts +0 -149
  173. package/dist/schemas.js +0 -24
  174. package/dist/secure.cjs +0 -170
  175. package/dist/secure.d.ts +0 -35
  176. package/dist/secure.js +0 -19
  177. package/dist/utils.cjs +0 -223
  178. package/dist/utils.d.ts +0 -24
  179. package/dist/utils.js +0 -29
package/dist/schemas.d.ts DELETED
@@ -1,149 +0,0 @@
1
- import { z } from 'zod';
2
-
3
- declare const OAuthProviderCredentialsSchema: z.ZodObject<{
4
- id: z.ZodString;
5
- name: z.ZodString;
6
- authorizeURL: z.ZodString;
7
- accessToken: z.ZodString;
8
- scope: z.ZodString;
9
- userInfo: z.ZodString;
10
- responseType: z.ZodEnum<{
11
- token: "token";
12
- code: "code";
13
- id_token: "id_token";
14
- }>;
15
- clientId: z.ZodString;
16
- clientSecret: z.ZodString;
17
- profile: z.ZodOptional<z.ZodFunction<z.core.$ZodFunctionArgs, z.core.$ZodFunctionOut>>;
18
- }, z.core.$strip>;
19
- /**
20
- * Schema for OAuth Provider Configuration
21
- */
22
- declare const OAuthProviderConfigSchema: z.ZodObject<{
23
- authorizeURL: z.ZodString;
24
- accessToken: z.ZodString;
25
- scope: z.ZodOptional<z.ZodString>;
26
- userInfo: z.ZodString;
27
- responseType: z.ZodEnum<{
28
- token: "token";
29
- code: "code";
30
- id_token: "id_token";
31
- }>;
32
- clientId: z.ZodString;
33
- clientSecret: z.ZodString;
34
- }, z.core.$strip>;
35
- /**
36
- * Schema used to create the authorization URL for the OAuth flow and verify the
37
- * OAuth configuration.
38
- * @see https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.1
39
- */
40
- declare const OAuthAuthorization: z.ZodObject<{
41
- authorizeURL: z.ZodString;
42
- accessToken: z.ZodString;
43
- scope: z.ZodOptional<z.ZodString>;
44
- userInfo: z.ZodString;
45
- responseType: z.ZodEnum<{
46
- token: "token";
47
- code: "code";
48
- id_token: "id_token";
49
- }>;
50
- clientId: z.ZodString;
51
- clientSecret: z.ZodString;
52
- redirectURI: z.ZodString;
53
- state: z.ZodString;
54
- codeChallenge: z.ZodString;
55
- codeChallengeMethod: z.ZodEnum<{
56
- plain: "plain";
57
- S256: "S256";
58
- }>;
59
- }, z.core.$strip>;
60
- /**
61
- * Schema used in the callback action to validate the authorization response when the resource owner
62
- * has granted.
63
- * @see https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.2
64
- */
65
- declare const OAuthAuthorizationResponse: z.ZodObject<{
66
- state: z.ZodString;
67
- code: z.ZodString;
68
- }, z.core.$strip>;
69
- /**
70
- * Schema used in the callback action to validate the authorization error response when the resource owner
71
- * has denied the authorization request.
72
- * @see https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.2.1
73
- */
74
- declare const OAuthAuthorizationErrorResponse: z.ZodObject<{
75
- error: z.ZodEnum<{
76
- invalid_request: "invalid_request";
77
- unauthorized_client: "unauthorized_client";
78
- access_denied: "access_denied";
79
- unsupported_response_type: "unsupported_response_type";
80
- invalid_scope: "invalid_scope";
81
- server_error: "server_error";
82
- temporarily_unavailable: "temporarily_unavailable";
83
- }>;
84
- error_description: z.ZodOptional<z.ZodString>;
85
- error_uri: z.ZodOptional<z.ZodString>;
86
- state: z.ZodString;
87
- }, z.core.$strip>;
88
- /**
89
- * Schema for OAuth Access Token Request and OAuth Configuration
90
- * @see https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.3
91
- */
92
- declare const OAuthAccessToken: z.ZodObject<{
93
- authorizeURL: z.ZodString;
94
- accessToken: z.ZodString;
95
- scope: z.ZodOptional<z.ZodString>;
96
- userInfo: z.ZodString;
97
- responseType: z.ZodEnum<{
98
- token: "token";
99
- code: "code";
100
- id_token: "id_token";
101
- }>;
102
- clientId: z.ZodString;
103
- clientSecret: z.ZodString;
104
- redirectURI: z.ZodString;
105
- code: z.ZodString;
106
- codeVerifier: z.ZodString;
107
- }, z.core.$strip>;
108
- /**
109
- * Schema for OAuth Access Token Response
110
- * @see https://datatracker.ietf.org/doc/html/rfc6749#section-5.1
111
- * @see https://datatracker.ietf.org/doc/html/rfc7636#section-4
112
- */
113
- declare const OAuthAccessTokenResponse: z.ZodObject<{
114
- access_token: z.ZodString;
115
- token_type: z.ZodOptional<z.ZodString>;
116
- expires_in: z.ZodOptional<z.ZodNumber>;
117
- refresh_token: z.ZodOptional<z.ZodString>;
118
- scope: z.ZodUnion<[z.ZodOptional<z.ZodString>, z.ZodNull]>;
119
- }, z.core.$strip>;
120
- /**
121
- * Schema for OAuth Access Token Error Response
122
- * @see https://datatracker.ietf.org/doc/html/rfc6749#section-5.2
123
- */
124
- declare const OAuthAccessTokenErrorResponse: z.ZodObject<{
125
- error: z.ZodEnum<{
126
- invalid_request: "invalid_request";
127
- unauthorized_client: "unauthorized_client";
128
- invalid_scope: "invalid_scope";
129
- invalid_client: "invalid_client";
130
- invalid_grant: "invalid_grant";
131
- unsupported_grant_type: "unsupported_grant_type";
132
- }>;
133
- error_description: z.ZodOptional<z.ZodString>;
134
- error_uri: z.ZodOptional<z.ZodString>;
135
- }, z.core.$strip>;
136
- /**
137
- * @todo: verify if this schema is still needed
138
- * @deprecated
139
- */
140
- declare const OAuthErrorResponse: z.ZodObject<{
141
- error: z.ZodString;
142
- error_description: z.ZodOptional<z.ZodString>;
143
- }, z.core.$strip>;
144
- declare const OAuthEnvSchema: z.ZodObject<{
145
- clientId: z.ZodString;
146
- clientSecret: z.ZodString;
147
- }, z.core.$strip>;
148
-
149
- export { OAuthAccessToken, OAuthAccessTokenErrorResponse, OAuthAccessTokenResponse, OAuthAuthorization, OAuthAuthorizationErrorResponse, OAuthAuthorizationResponse, OAuthEnvSchema, OAuthErrorResponse, OAuthProviderConfigSchema, OAuthProviderCredentialsSchema };
package/dist/schemas.js DELETED
@@ -1,24 +0,0 @@
1
- import {
2
- OAuthAccessToken,
3
- OAuthAccessTokenErrorResponse,
4
- OAuthAccessTokenResponse,
5
- OAuthAuthorization,
6
- OAuthAuthorizationErrorResponse,
7
- OAuthAuthorizationResponse,
8
- OAuthEnvSchema,
9
- OAuthErrorResponse,
10
- OAuthProviderConfigSchema,
11
- OAuthProviderCredentialsSchema
12
- } from "./chunk-KJBAQZX2.js";
13
- export {
14
- OAuthAccessToken,
15
- OAuthAccessTokenErrorResponse,
16
- OAuthAccessTokenResponse,
17
- OAuthAuthorization,
18
- OAuthAuthorizationErrorResponse,
19
- OAuthAuthorizationResponse,
20
- OAuthEnvSchema,
21
- OAuthErrorResponse,
22
- OAuthProviderConfigSchema,
23
- OAuthProviderCredentialsSchema
24
- };
package/dist/secure.cjs DELETED
@@ -1,170 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
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
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/secure.ts
31
- var secure_exports = {};
32
- __export(secure_exports, {
33
- createCSRF: () => createCSRF,
34
- createHash: () => createHash,
35
- createPKCE: () => createPKCE,
36
- generateSecure: () => generateSecure,
37
- verifyCSRF: () => verifyCSRF
38
- });
39
- module.exports = __toCommonJS(secure_exports);
40
- var import_crypto2 = __toESM(require("crypto"), 1);
41
-
42
- // src/utils.ts
43
- var import_router = require("@aura-stack/router");
44
-
45
- // src/errors.ts
46
- var AuthSecurityError = class extends Error {
47
- type = "AUTH_SECURITY_ERROR";
48
- code;
49
- constructor(code, message, options) {
50
- super(message, options);
51
- this.code = code;
52
- this.name = new.target.name;
53
- Error.captureStackTrace(this, new.target);
54
- }
55
- };
56
-
57
- // src/utils.ts
58
- var equals = (a, b) => {
59
- if (a === null || b === null || a === void 0 || b === void 0) return false;
60
- return a === b;
61
- };
62
-
63
- // src/assert.ts
64
- var import_crypto = require("crypto");
65
- var isJWTPayloadWithToken = (payload) => {
66
- return typeof payload === "object" && payload !== null && "token" in payload && typeof payload?.token === "string";
67
- };
68
- var safeEquals = (a, b) => {
69
- const bufferA = Buffer.from(a);
70
- const bufferB = Buffer.from(b);
71
- if (bufferA.length !== bufferB.length) {
72
- return false;
73
- }
74
- return (0, import_crypto.timingSafeEqual)(bufferA, bufferB);
75
- };
76
-
77
- // src/env.ts
78
- var import_meta = {};
79
- var env = new Proxy({}, {
80
- get(_, prop) {
81
- if (typeof prop !== "string") return void 0;
82
- const hasProperty = (process2) => {
83
- return process2 && Object.prototype.hasOwnProperty.call(process2, prop);
84
- };
85
- try {
86
- if (typeof process !== "undefined" && hasProperty(process.env)) {
87
- return process.env[prop];
88
- }
89
- if (typeof import_meta !== "undefined" && hasProperty(import_meta.env)) {
90
- return import_meta.env[prop];
91
- }
92
- if (typeof Deno !== "undefined" && Deno.env?.get) {
93
- return Deno.env.get(prop);
94
- }
95
- if (typeof Bun !== "undefined" && hasProperty(Bun.env)) {
96
- return Bun.env[prop];
97
- }
98
- const globalValue = globalThis[prop];
99
- return typeof globalValue === "string" ? globalValue : void 0;
100
- } catch {
101
- return void 0;
102
- }
103
- }
104
- });
105
-
106
- // src/jose.ts
107
- var import_jose = require("@aura-stack/jose");
108
- var jwtVerificationOptions = {
109
- algorithms: ["HS256"],
110
- typ: "JWT"
111
- };
112
-
113
- // src/secure.ts
114
- var generateSecure = (length = 32) => {
115
- return import_crypto2.default.randomBytes(length).toString("base64url");
116
- };
117
- var createHash = (data, base = "hex") => {
118
- return import_crypto2.default.createHash("sha256").update(data).digest().toString(base);
119
- };
120
- var createPKCE = async (verifier) => {
121
- const byteLength = verifier ? void 0 : Math.floor(Math.random() * (96 - 32 + 1) + 32);
122
- const codeVerifier = verifier ?? generateSecure(byteLength ?? 64);
123
- if (codeVerifier.length < 43 || codeVerifier.length > 128) {
124
- throw new AuthSecurityError("PKCE_VERIFIER_INVALID", "The code verifier must be between 43 and 128 characters in length.");
125
- }
126
- const codeChallenge = createHash(codeVerifier, "base64url");
127
- return { codeVerifier, codeChallenge, method: "S256" };
128
- };
129
- var createCSRF = async (jose, csrfCookie) => {
130
- try {
131
- const token = generateSecure(32);
132
- if (csrfCookie) {
133
- await jose.verifyJWS(csrfCookie, jwtVerificationOptions);
134
- return csrfCookie;
135
- }
136
- return jose.signJWS({ token });
137
- } catch {
138
- const token = generateSecure(32);
139
- return jose.signJWS({ token });
140
- }
141
- };
142
- var verifyCSRF = async (jose, cookie, header) => {
143
- try {
144
- const cookiePayload = await jose.verifyJWS(cookie, jwtVerificationOptions);
145
- const headerPayload = await jose.verifyJWS(header, jwtVerificationOptions);
146
- if (!isJWTPayloadWithToken(cookiePayload)) {
147
- throw new AuthSecurityError("CSRF_TOKEN_INVALID", "Cookie payload missing token field.");
148
- }
149
- if (!isJWTPayloadWithToken(headerPayload)) {
150
- throw new AuthSecurityError("CSRF_TOKEN_INVALID", "Header payload missing token field.");
151
- }
152
- if (!equals(cookiePayload.token.length, headerPayload.token.length)) {
153
- throw new AuthSecurityError("CSRF_TOKEN_INVALID", "The CSRF tokens do not match.");
154
- }
155
- if (!safeEquals(cookiePayload.token, headerPayload.token)) {
156
- throw new AuthSecurityError("CSRF_TOKEN_INVALID", "The CSRF tokens do not match.");
157
- }
158
- return true;
159
- } catch {
160
- throw new AuthSecurityError("CSRF_TOKEN_INVALID", "The CSRF tokens do not match.");
161
- }
162
- };
163
- // Annotate the CommonJS export names for ESM import in node:
164
- 0 && (module.exports = {
165
- createCSRF,
166
- createHash,
167
- createPKCE,
168
- generateSecure,
169
- verifyCSRF
170
- });
package/dist/secure.d.ts DELETED
@@ -1,35 +0,0 @@
1
- import { A as AuthRuntimeConfig } from './index-CSyIJmCM.js';
2
- import 'zod';
3
- import './schemas.js';
4
- import './jose.js';
5
- import '@aura-stack/jose';
6
- import '@aura-stack/jose/jose';
7
- import '@aura-stack/router/cookie';
8
- import './@types/utility.js';
9
-
10
- declare const generateSecure: (length?: number) => string;
11
- declare const createHash: (data: string, base?: "hex" | "base64" | "base64url") => string;
12
- /**
13
- * Creates the code challenge flow for PKCE OAuth flow. It generates a code verifier and its corresponding
14
- * code challenge using SHA-256 hashing.
15
- * - code_verifier: A cryptographically random string used to mitigate authorization code interception attacks.
16
- * - code_challenge: A hashed version of the code_verifier sent in the authorization request.
17
- * - method: The method used to generate the code challenge, typically "S256" for SHA-256.
18
- *
19
- * @see https://datatracker.ietf.org/doc/html/rfc7636#section-4.1
20
- */
21
- declare const createPKCE: (verifier?: string) => Promise<{
22
- codeVerifier: string;
23
- codeChallenge: string;
24
- method: string;
25
- }>;
26
- /**
27
- * Creates a CSRF token to be used in OAuth flows to prevent cross-site request forgery attacks.
28
- *
29
- * @param csrfCookie - Optional existing CSRF cookie to verify and reuse
30
- * @returns Signed CSRF token
31
- */
32
- declare const createCSRF: (jose: AuthRuntimeConfig["jose"], csrfCookie?: string) => Promise<string>;
33
- declare const verifyCSRF: (jose: AuthRuntimeConfig["jose"], cookie: string, header: string) => Promise<boolean>;
34
-
35
- export { createCSRF, createHash, createPKCE, generateSecure, verifyCSRF };
package/dist/secure.js DELETED
@@ -1,19 +0,0 @@
1
- import {
2
- createCSRF,
3
- createHash,
4
- createPKCE,
5
- generateSecure,
6
- verifyCSRF
7
- } from "./chunk-NUDITUKX.js";
8
- import "./chunk-4EKY7655.js";
9
- import "./chunk-QQVSRXGX.js";
10
- import "./chunk-FRJFWTOY.js";
11
- import "./chunk-4MYWAOLG.js";
12
- import "./chunk-RRLIF4PQ.js";
13
- export {
14
- createCSRF,
15
- createHash,
16
- createPKCE,
17
- generateSecure,
18
- verifyCSRF
19
- };
package/dist/utils.cjs DELETED
@@ -1,223 +0,0 @@
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/utils.ts
21
- var utils_exports = {};
22
- __export(utils_exports, {
23
- createErrorHandler: () => createErrorHandler,
24
- createStructuredData: () => createStructuredData,
25
- equals: () => equals,
26
- extractPath: () => extractPath,
27
- formatZodError: () => formatZodError,
28
- getBaseURL: () => getBaseURL,
29
- getErrorName: () => getErrorName,
30
- toCastCase: () => toCastCase,
31
- toISOString: () => toISOString,
32
- toSnakeCase: () => toSnakeCase,
33
- toUpperCase: () => toUpperCase,
34
- useSecureCookies: () => useSecureCookies
35
- });
36
- module.exports = __toCommonJS(utils_exports);
37
- var import_router = require("@aura-stack/router");
38
-
39
- // src/errors.ts
40
- var OAuthProtocolError = class extends Error {
41
- type = "OAUTH_PROTOCOL_ERROR";
42
- error;
43
- errorURI;
44
- constructor(error, description, errorURI, options) {
45
- super(description, options);
46
- this.error = error;
47
- this.errorURI = errorURI;
48
- this.name = new.target.name;
49
- Error.captureStackTrace(this, new.target);
50
- }
51
- };
52
- var AuthInternalError = class extends Error {
53
- type = "AUTH_INTERNAL_ERROR";
54
- code;
55
- constructor(code, message, options) {
56
- super(message, options);
57
- this.code = code;
58
- this.name = new.target.name;
59
- Error.captureStackTrace(this, new.target);
60
- }
61
- };
62
- var AuthSecurityError = class extends Error {
63
- type = "AUTH_SECURITY_ERROR";
64
- code;
65
- constructor(code, message, options) {
66
- super(message, options);
67
- this.code = code;
68
- this.name = new.target.name;
69
- Error.captureStackTrace(this, new.target);
70
- }
71
- };
72
- var isOAuthProtocolError = (error) => {
73
- return error instanceof OAuthProtocolError;
74
- };
75
- var isAuthInternalError = (error) => {
76
- return error instanceof AuthInternalError;
77
- };
78
- var isAuthSecurityError = (error) => {
79
- return error instanceof AuthSecurityError;
80
- };
81
-
82
- // src/utils.ts
83
- var toSnakeCase = (str) => {
84
- return str.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2").toLowerCase().replace(/^_+/, "");
85
- };
86
- var toUpperCase = (str) => {
87
- return str.toUpperCase();
88
- };
89
- var toCastCase = (obj, type = "snake") => {
90
- return Object.entries(obj).reduce((previous, [key, value]) => {
91
- const newKey = type === "snake" ? toSnakeCase(key) : toUpperCase(key);
92
- return { ...previous, [newKey]: value };
93
- }, {});
94
- };
95
- var equals = (a, b) => {
96
- if (a === null || b === null || a === void 0 || b === void 0) return false;
97
- return a === b;
98
- };
99
- var createErrorHandler = (logger) => {
100
- return (error) => {
101
- if ((0, import_router.isRouterError)(error)) {
102
- const { message, status, statusText } = error;
103
- logger?.log("ROUTER_INTERNAL_ERROR");
104
- return Response.json({ type: "ROUTER_ERROR", code: "ROUTER_INTERNAL_ERROR", message }, { status, statusText });
105
- }
106
- if ((0, import_router.isInvalidZodSchemaError)(error)) {
107
- logger?.log("INVALID_REQUEST");
108
- return Response.json({ type: "ROUTER_ERROR", code: "INVALID_REQUEST", message: error.errors }, { status: 422 });
109
- }
110
- if (isOAuthProtocolError(error)) {
111
- const { error: errorCode, message, type, errorURI } = error;
112
- logger?.log("OAUTH_PROTOCOL_ERROR", {
113
- structuredData: {
114
- error: errorCode,
115
- error_description: message,
116
- error_uri: errorURI ?? ""
117
- }
118
- });
119
- return Response.json(
120
- {
121
- type,
122
- message
123
- },
124
- { status: 400 }
125
- );
126
- }
127
- if (isAuthInternalError(error)) {
128
- const { type, code, message } = error;
129
- logger?.log("INVALID_OAUTH_CONFIGURATION", {
130
- structuredData: {
131
- error: code,
132
- error_description: message
133
- }
134
- });
135
- return Response.json(
136
- {
137
- type,
138
- message
139
- },
140
- { status: 400 }
141
- );
142
- }
143
- if (isAuthSecurityError(error)) {
144
- const { type, code, message } = error;
145
- logger?.log("INVALID_OAUTH_CONFIGURATION", {
146
- structuredData: {
147
- error: code,
148
- error_description: message
149
- }
150
- });
151
- return Response.json(
152
- {
153
- type,
154
- code,
155
- message
156
- },
157
- { status: 400 }
158
- );
159
- }
160
- logger?.log("SERVER_ERROR");
161
- return Response.json(
162
- { type: "SERVER_ERROR", code: "SERVER_ERROR", message: "An unexpected error occurred" },
163
- { status: 500 }
164
- );
165
- };
166
- };
167
- var getBaseURL = (request) => {
168
- const url = new URL(request.url);
169
- return `${url.origin}${url.pathname}`;
170
- };
171
- var toISOString = (date) => {
172
- return new Date(date).toISOString();
173
- };
174
- var useSecureCookies = (request, trustedProxyHeaders) => {
175
- return trustedProxyHeaders ? request.url.startsWith("https://") || request.headers.get("X-Forwarded-Proto") === "https" || (request.headers.get("Forwarded")?.includes("proto=https") ?? false) : request.url.startsWith("https://");
176
- };
177
- var formatZodError = (error) => {
178
- if (!error.issues || error.issues.length === 0) {
179
- return {};
180
- }
181
- return error.issues.reduce((previous, issue) => {
182
- const key = issue.path.join(".");
183
- return {
184
- ...previous,
185
- [key]: {
186
- code: issue.code,
187
- message: issue.message
188
- }
189
- };
190
- }, {});
191
- };
192
- var extractPath = (url) => {
193
- const pathRegex = /^https?:\/\/[a-zA-Z0-9_\-\.]+(:\d+)?(\/.*)$/;
194
- const match = url.match(pathRegex);
195
- return match && match[2] ? match[2] : "/";
196
- };
197
- var createStructuredData = (data, sdID = "metadata") => {
198
- const entries = Object.entries(data);
199
- if (entries.length === 0) return `[${sdID}]`;
200
- const values = entries.map(([key, value]) => `${key}="${String(value).replace(/(["\\\]])/g, "\\$1")}"`).join(" ");
201
- return `[${sdID} ${values}]`;
202
- };
203
- var getErrorName = (error) => {
204
- if (error instanceof Error) {
205
- return error.name;
206
- }
207
- return typeof error === "string" ? error : "UnknownError";
208
- };
209
- // Annotate the CommonJS export names for ESM import in node:
210
- 0 && (module.exports = {
211
- createErrorHandler,
212
- createStructuredData,
213
- equals,
214
- extractPath,
215
- formatZodError,
216
- getBaseURL,
217
- getErrorName,
218
- toCastCase,
219
- toISOString,
220
- toSnakeCase,
221
- toUpperCase,
222
- useSecureCookies
223
- });
package/dist/utils.d.ts DELETED
@@ -1,24 +0,0 @@
1
- import { RouterConfig } from '@aura-stack/router';
2
- import { ZodError } from 'zod';
3
- import { I as InternalLogger, j as APIErrorMap } from './index-CSyIJmCM.js';
4
- import './schemas.js';
5
- import './jose.js';
6
- import '@aura-stack/jose';
7
- import '@aura-stack/jose/jose';
8
- import '@aura-stack/router/cookie';
9
- import './@types/utility.js';
10
-
11
- declare const toSnakeCase: (str: string) => string;
12
- declare const toUpperCase: (str: string) => string;
13
- declare const toCastCase: <Obj extends Record<string, string>, Type extends "snake" | "upper">(obj: Obj, type?: Type) => Type extends "snake" ? { [K in keyof Obj as `${string & K}`]: Obj[K]; } : { [K in keyof Obj as Uppercase<string & K>]: Obj[K]; };
14
- declare const equals: (a: string | number | undefined | null, b: string | number | undefined | null) => boolean;
15
- declare const createErrorHandler: (logger?: InternalLogger) => RouterConfig["onError"];
16
- declare const getBaseURL: (request: Request) => string;
17
- declare const toISOString: (date: Date | string | number) => string;
18
- declare const useSecureCookies: (request: Request, trustedProxyHeaders: boolean) => boolean;
19
- declare const formatZodError: <T extends Record<string, unknown> = Record<string, unknown>>(error: ZodError<T>) => APIErrorMap;
20
- declare const extractPath: (url: string) => string;
21
- declare const createStructuredData: (data: Record<string, string | number | boolean>, sdID?: string) => string;
22
- declare const getErrorName: (error: unknown) => string;
23
-
24
- export { createErrorHandler, createStructuredData, equals, extractPath, formatZodError, getBaseURL, getErrorName, toCastCase, toISOString, toSnakeCase, toUpperCase, useSecureCookies };
package/dist/utils.js DELETED
@@ -1,29 +0,0 @@
1
- import {
2
- createErrorHandler,
3
- createStructuredData,
4
- equals,
5
- extractPath,
6
- formatZodError,
7
- getBaseURL,
8
- getErrorName,
9
- toCastCase,
10
- toISOString,
11
- toSnakeCase,
12
- toUpperCase,
13
- useSecureCookies
14
- } from "./chunk-QQVSRXGX.js";
15
- import "./chunk-RRLIF4PQ.js";
16
- export {
17
- createErrorHandler,
18
- createStructuredData,
19
- equals,
20
- extractPath,
21
- formatZodError,
22
- getBaseURL,
23
- getErrorName,
24
- toCastCase,
25
- toISOString,
26
- toSnakeCase,
27
- toUpperCase,
28
- useSecureCookies
29
- };