@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
@@ -1,250 +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/actions/callback/userinfo.ts
31
- var userinfo_exports = {};
32
- __export(userinfo_exports, {
33
- getUserInfo: () => getUserInfo
34
- });
35
- module.exports = __toCommonJS(userinfo_exports);
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
-
48
- // src/secure.ts
49
- var import_crypto = __toESM(require("crypto"), 1);
50
-
51
- // src/utils.ts
52
- var import_router = require("@aura-stack/router");
53
-
54
- // src/errors.ts
55
- var OAuthProtocolError = class extends Error {
56
- type = "OAUTH_PROTOCOL_ERROR";
57
- error;
58
- errorURI;
59
- constructor(error, description, errorURI, options2) {
60
- super(description, options2);
61
- this.error = error;
62
- this.errorURI = errorURI;
63
- this.name = new.target.name;
64
- Error.captureStackTrace(this, new.target);
65
- }
66
- };
67
- var isNativeError = (error) => {
68
- return error instanceof Error;
69
- };
70
- var isOAuthProtocolError = (error) => {
71
- return error instanceof OAuthProtocolError;
72
- };
73
-
74
- // src/env.ts
75
- var import_meta = {};
76
- var env = new Proxy({}, {
77
- get(_, prop) {
78
- if (typeof prop !== "string") return void 0;
79
- const hasProperty = (process2) => {
80
- return process2 && Object.prototype.hasOwnProperty.call(process2, prop);
81
- };
82
- try {
83
- if (typeof process !== "undefined" && hasProperty(process.env)) {
84
- return process.env[prop];
85
- }
86
- if (typeof import_meta !== "undefined" && hasProperty(import_meta.env)) {
87
- return import_meta.env[prop];
88
- }
89
- if (typeof Deno !== "undefined" && Deno.env?.get) {
90
- return Deno.env.get(prop);
91
- }
92
- if (typeof Bun !== "undefined" && hasProperty(Bun.env)) {
93
- return Bun.env[prop];
94
- }
95
- const globalValue = globalThis[prop];
96
- return typeof globalValue === "string" ? globalValue : void 0;
97
- } catch {
98
- return void 0;
99
- }
100
- }
101
- });
102
-
103
- // src/jose.ts
104
- var import_jose = require("@aura-stack/jose");
105
-
106
- // src/secure.ts
107
- var generateSecure = (length = 32) => {
108
- return import_crypto.default.randomBytes(length).toString("base64url");
109
- };
110
-
111
- // src/schemas.ts
112
- var import_zod = require("zod");
113
- var OAuthProviderCredentialsSchema = (0, import_zod.object)({
114
- id: (0, import_zod.string)(),
115
- name: (0, import_zod.string)(),
116
- authorizeURL: (0, import_zod.string)().url(),
117
- accessToken: (0, import_zod.string)().url(),
118
- scope: (0, import_zod.string)(),
119
- userInfo: (0, import_zod.string)().url(),
120
- responseType: (0, import_zod.enum)(["code", "token", "id_token"]),
121
- clientId: (0, import_zod.string)(),
122
- clientSecret: (0, import_zod.string)(),
123
- profile: import_zod.z.function().optional()
124
- });
125
- var OAuthProviderConfigSchema = (0, import_zod.object)({
126
- authorizeURL: (0, import_zod.string)().url(),
127
- accessToken: (0, import_zod.string)().url(),
128
- scope: (0, import_zod.string)().optional(),
129
- userInfo: (0, import_zod.string)().url(),
130
- responseType: (0, import_zod.enum)(["code", "token", "id_token"]),
131
- clientId: (0, import_zod.string)(),
132
- clientSecret: (0, import_zod.string)()
133
- });
134
- var OAuthAuthorization = OAuthProviderConfigSchema.extend({
135
- redirectURI: (0, import_zod.string)(),
136
- state: (0, import_zod.string)(),
137
- codeChallenge: (0, import_zod.string)(),
138
- codeChallengeMethod: (0, import_zod.enum)(["plain", "S256"])
139
- });
140
- var OAuthAuthorizationResponse = (0, import_zod.object)({
141
- state: (0, import_zod.string)({ message: "Missing state parameter in the OAuth authorization response." }),
142
- code: (0, import_zod.string)({ message: "Missing code parameter in the OAuth authorization response." })
143
- });
144
- var OAuthAuthorizationErrorResponse = (0, import_zod.object)({
145
- error: (0, import_zod.enum)([
146
- "invalid_request",
147
- "unauthorized_client",
148
- "access_denied",
149
- "unsupported_response_type",
150
- "invalid_scope",
151
- "server_error",
152
- "temporarily_unavailable"
153
- ]),
154
- error_description: (0, import_zod.string)().optional(),
155
- error_uri: (0, import_zod.string)().optional(),
156
- state: (0, import_zod.string)()
157
- });
158
- var OAuthAccessToken = OAuthProviderConfigSchema.extend({
159
- redirectURI: (0, import_zod.string)(),
160
- code: (0, import_zod.string)(),
161
- codeVerifier: (0, import_zod.string)().min(43).max(128)
162
- });
163
- var OAuthAccessTokenResponse = (0, import_zod.object)({
164
- access_token: (0, import_zod.string)(),
165
- token_type: (0, import_zod.string)().optional(),
166
- expires_in: (0, import_zod.number)().optional(),
167
- refresh_token: (0, import_zod.string)().optional(),
168
- scope: (0, import_zod.string)().optional().or((0, import_zod.null)())
169
- });
170
- var OAuthAccessTokenErrorResponse = (0, import_zod.object)({
171
- error: (0, import_zod.enum)([
172
- "invalid_request",
173
- "invalid_client",
174
- "invalid_grant",
175
- "unauthorized_client",
176
- "unsupported_grant_type",
177
- "invalid_scope"
178
- ]),
179
- error_description: (0, import_zod.string)().optional(),
180
- error_uri: (0, import_zod.string)().optional()
181
- });
182
- var OAuthErrorResponse = (0, import_zod.object)({
183
- error: (0, import_zod.string)(),
184
- error_description: (0, import_zod.string)().optional()
185
- });
186
- var OAuthEnvSchema = (0, import_zod.object)({
187
- clientId: import_zod.z.string().min(1, "OAuth Client ID is required in the environment variables."),
188
- clientSecret: import_zod.z.string().min(1, "OAuth Client Secret is required in the environment variables.")
189
- });
190
-
191
- // src/actions/callback/userinfo.ts
192
- var getDefaultUserInfo = (profile) => {
193
- const sub = generateSecure(16);
194
- return {
195
- sub: profile?.id ?? profile?.sub ?? sub,
196
- email: profile?.email,
197
- name: profile?.name ?? profile?.username ?? profile?.nickname,
198
- image: profile?.image ?? profile?.picture
199
- };
200
- };
201
- var getUserInfo = async (oauthConfig, accessToken, logger) => {
202
- const userinfoEndpoint = oauthConfig.userInfo;
203
- try {
204
- logger?.log("OAUTH_USERINFO_REQUEST_INITIATED", {
205
- structuredData: {
206
- endpoint: userinfoEndpoint
207
- }
208
- });
209
- const response = await fetchAsync(userinfoEndpoint, {
210
- method: "GET",
211
- headers: {
212
- Accept: "application/json",
213
- Authorization: `Bearer ${accessToken}`
214
- }
215
- });
216
- if (!response.ok) {
217
- logger?.log("OAUTH_USERINFO_INVALID_RESPONSE");
218
- throw new OAuthProtocolError("INVALID_REQUEST", "Invalid userinfo response format");
219
- }
220
- const json = await response.json();
221
- const { success, data } = OAuthErrorResponse.safeParse(json);
222
- if (success) {
223
- logger?.log("OAUTH_USERINFO_ERROR", {
224
- message: "Error response received from OAuth userinfo endpoint",
225
- structuredData: {
226
- error: data.error,
227
- error_description: data.error_description ?? ""
228
- }
229
- });
230
- throw new OAuthProtocolError("INVALID_REQUEST", "An error was received from the OAuth userinfo endpoint.");
231
- }
232
- logger?.log("OAUTH_USERINFO_SUCCESS");
233
- return oauthConfig?.profile ? oauthConfig.profile(json) : getDefaultUserInfo(json);
234
- } catch (error) {
235
- if (isOAuthProtocolError(error)) {
236
- throw error;
237
- }
238
- logger?.log("OAUTH_USERINFO_REQUEST_FAILED");
239
- if (isNativeError(error)) {
240
- throw new OAuthProtocolError("SERVER_ERROR", "Failed to fetch user information from OAuth provider", "", {
241
- cause: error
242
- });
243
- }
244
- throw new OAuthProtocolError("SERVER_ERROR", "Failed to fetch user information", "", { cause: error });
245
- }
246
- };
247
- // Annotate the CommonJS export names for ESM import in node:
248
- 0 && (module.exports = {
249
- getUserInfo
250
- });
@@ -1,21 +0,0 @@
1
- import { h as OAuthProviderCredentials, I as InternalLogger, U as User } 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
- /**
11
- * Get user information from the OAuth provider's userinfo endpoint using the provided access token.
12
- * The response by default is mapped to the standardized `User` format unless a custom
13
- * `profile` function is provided in the `oauthConfig`.
14
- *
15
- * @param oauthConfig - OAuth provider configuration
16
- * @param accessToken - Access Token to access the userinfo endpoint
17
- * @returns The user information retrieved from the userinfo endpoint
18
- */
19
- declare const getUserInfo: (oauthConfig: OAuthProviderCredentials, accessToken: string, logger?: InternalLogger) => Promise<User>;
20
-
21
- export { getUserInfo };
@@ -1,14 +0,0 @@
1
- import {
2
- getUserInfo
3
- } from "../../chunk-XGLBNXL4.js";
4
- import "../../chunk-ZNCZVF6U.js";
5
- import "../../chunk-KJBAQZX2.js";
6
- import "../../chunk-NUDITUKX.js";
7
- import "../../chunk-4EKY7655.js";
8
- import "../../chunk-QQVSRXGX.js";
9
- import "../../chunk-FRJFWTOY.js";
10
- import "../../chunk-4MYWAOLG.js";
11
- import "../../chunk-RRLIF4PQ.js";
12
- export {
13
- getUserInfo
14
- };
@@ -1,197 +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/actions/csrfToken/csrfToken.ts
31
- var csrfToken_exports = {};
32
- __export(csrfToken_exports, {
33
- csrfTokenAction: () => csrfTokenAction
34
- });
35
- module.exports = __toCommonJS(csrfToken_exports);
36
- var import_router2 = require("@aura-stack/router");
37
-
38
- // src/secure.ts
39
- var import_crypto = __toESM(require("crypto"), 1);
40
-
41
- // src/utils.ts
42
- var import_router = require("@aura-stack/router");
43
-
44
- // src/errors.ts
45
- var AuthInternalError = class extends Error {
46
- type = "AUTH_INTERNAL_ERROR";
47
- code;
48
- constructor(code, message, options) {
49
- super(message, options);
50
- this.code = code;
51
- this.name = new.target.name;
52
- Error.captureStackTrace(this, new.target);
53
- }
54
- };
55
-
56
- // src/env.ts
57
- var import_meta = {};
58
- var env = new Proxy({}, {
59
- get(_, prop) {
60
- if (typeof prop !== "string") return void 0;
61
- const hasProperty = (process2) => {
62
- return process2 && Object.prototype.hasOwnProperty.call(process2, prop);
63
- };
64
- try {
65
- if (typeof process !== "undefined" && hasProperty(process.env)) {
66
- return process.env[prop];
67
- }
68
- if (typeof import_meta !== "undefined" && hasProperty(import_meta.env)) {
69
- return import_meta.env[prop];
70
- }
71
- if (typeof Deno !== "undefined" && Deno.env?.get) {
72
- return Deno.env.get(prop);
73
- }
74
- if (typeof Bun !== "undefined" && hasProperty(Bun.env)) {
75
- return Bun.env[prop];
76
- }
77
- const globalValue = globalThis[prop];
78
- return typeof globalValue === "string" ? globalValue : void 0;
79
- } catch {
80
- return void 0;
81
- }
82
- }
83
- });
84
-
85
- // src/jose.ts
86
- var import_jose = require("@aura-stack/jose");
87
- var jwtVerificationOptions = {
88
- algorithms: ["HS256"],
89
- typ: "JWT"
90
- };
91
-
92
- // src/secure.ts
93
- var generateSecure = (length = 32) => {
94
- return import_crypto.default.randomBytes(length).toString("base64url");
95
- };
96
- var createCSRF = async (jose, csrfCookie) => {
97
- try {
98
- const token = generateSecure(32);
99
- if (csrfCookie) {
100
- await jose.verifyJWS(csrfCookie, jwtVerificationOptions);
101
- return csrfCookie;
102
- }
103
- return jose.signJWS({ token });
104
- } catch {
105
- const token = generateSecure(32);
106
- return jose.signJWS({ token });
107
- }
108
- };
109
-
110
- // src/headers.ts
111
- var cacheControl = {
112
- "Cache-Control": "no-store",
113
- Pragma: "no-cache",
114
- Expires: "0",
115
- Vary: "Cookie"
116
- };
117
- var contentSecurityPolicy = {
118
- "Content-Security-Policy": [
119
- "default-src 'none'",
120
- "script-src 'self'",
121
- "frame-src 'none'",
122
- "object-src 'none'",
123
- "frame-ancestors 'none'",
124
- "base-uri 'none'"
125
- ].join("; ")
126
- };
127
- var secureHeaders = {
128
- "X-Content-Type-Options": "nosniff",
129
- "X-Frame-Options": "DENY",
130
- "Referrer-Policy": "strict-origin-when-cross-origin"
131
- };
132
- var secureApiHeaders = {
133
- ...cacheControl,
134
- ...contentSecurityPolicy,
135
- ...secureHeaders
136
- };
137
-
138
- // src/cookie.ts
139
- var import_cookie = require("@aura-stack/router/cookie");
140
- var defaultCookieOptions = {
141
- httpOnly: true,
142
- sameSite: "lax",
143
- path: "/",
144
- maxAge: 60 * 60 * 24 * 15
145
- };
146
- var oauthCookieOptions = {
147
- httpOnly: true,
148
- maxAge: 5 * 60,
149
- sameSite: "lax",
150
- expires: new Date(Date.now() + 5 * 60 * 1e3)
151
- };
152
- var setCookie = (cookieName, value, options) => {
153
- return (0, import_cookie.serialize)(cookieName, value, options);
154
- };
155
- var expiredCookieAttributes = {
156
- ...defaultCookieOptions,
157
- expires: /* @__PURE__ */ new Date(0),
158
- maxAge: 0,
159
- secure: true
160
- };
161
- var getCookie = (request, cookieName) => {
162
- const cookies = request.headers.get("Cookie");
163
- if (!cookies) {
164
- throw new AuthInternalError("COOKIE_NOT_FOUND", "No cookies found. There is no active session");
165
- }
166
- const value = (0, import_cookie.parse)(cookies)[cookieName];
167
- if (!value) {
168
- throw new AuthInternalError("COOKIE_NOT_FOUND", `Cookie "${cookieName}" not found. There is no active session`);
169
- }
170
- return value;
171
- };
172
-
173
- // src/actions/csrfToken/csrfToken.ts
174
- var getCSRFToken = (request, cookieName) => {
175
- try {
176
- return getCookie(request, cookieName);
177
- } catch {
178
- return void 0;
179
- }
180
- };
181
- var csrfTokenAction = (0, import_router2.createEndpoint)("GET", "/csrfToken", async (ctx) => {
182
- const {
183
- request,
184
- context: { jose, cookies, logger }
185
- } = ctx;
186
- const token = getCSRFToken(request, cookies.csrfToken.name);
187
- logger?.log("CSRF_TOKEN_REQUESTED", { structuredData: { has_token: Boolean(token) } });
188
- const csrfToken = await createCSRF(jose, token);
189
- logger?.log("CSRF_TOKEN_ISSUED", { structuredData: { issued: Boolean(csrfToken) } });
190
- const headers = new Headers(secureApiHeaders);
191
- headers.append("Set-Cookie", setCookie(cookies.csrfToken.name, csrfToken, cookies.csrfToken.attributes));
192
- return Response.json({ csrfToken }, { headers });
193
- });
194
- // Annotate the CommonJS export names for ESM import in node:
195
- 0 && (module.exports = {
196
- csrfTokenAction
197
- });
@@ -1,5 +0,0 @@
1
- import * as _aura_stack_router from '@aura-stack/router';
2
-
3
- declare const csrfTokenAction: _aura_stack_router.RouteEndpoint<"GET", "/csrfToken", {}>;
4
-
5
- export { csrfTokenAction };
@@ -1,14 +0,0 @@
1
- import {
2
- csrfTokenAction
3
- } from "../../chunk-ICAZ4OVS.js";
4
- import "../../chunk-NUDITUKX.js";
5
- import "../../chunk-4EKY7655.js";
6
- import "../../chunk-QQVSRXGX.js";
7
- import "../../chunk-5W4BRQYG.js";
8
- import "../../chunk-EBAMFRB7.js";
9
- import "../../chunk-FRJFWTOY.js";
10
- import "../../chunk-4MYWAOLG.js";
11
- import "../../chunk-RRLIF4PQ.js";
12
- export {
13
- csrfTokenAction
14
- };