@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,14 +0,0 @@
1
- export { signInAction } from './signIn/signIn.js';
2
- export { callbackAction } from './callback/callback.js';
3
- export { sessionAction } from './session/session.js';
4
- export { signOutAction } from './signOut/signOut.js';
5
- export { csrfTokenAction } from './csrfToken/csrfToken.js';
6
- import '@aura-stack/router';
7
- import '../index-CSyIJmCM.js';
8
- import 'zod';
9
- import '../schemas.js';
10
- import '../jose.js';
11
- import '@aura-stack/jose';
12
- import '@aura-stack/jose/jose';
13
- import '@aura-stack/router/cookie';
14
- import '../@types/utility.js';
@@ -1,36 +0,0 @@
1
- import "../chunk-ITQ7352M.js";
2
- import {
3
- signInAction
4
- } from "../chunk-7QF22LHP.js";
5
- import {
6
- csrfTokenAction
7
- } from "../chunk-ICAZ4OVS.js";
8
- import {
9
- signOutAction
10
- } from "../chunk-ALG3GIV4.js";
11
- import {
12
- callbackAction
13
- } from "../chunk-6MXFPFR3.js";
14
- import "../chunk-TZB6MUXN.js";
15
- import "../chunk-XGLBNXL4.js";
16
- import {
17
- sessionAction
18
- } from "../chunk-PHFH2MGS.js";
19
- import "../chunk-XUP6KKNG.js";
20
- import "../chunk-ZNCZVF6U.js";
21
- import "../chunk-KJBAQZX2.js";
22
- import "../chunk-NUDITUKX.js";
23
- import "../chunk-4EKY7655.js";
24
- import "../chunk-QQVSRXGX.js";
25
- import "../chunk-5W4BRQYG.js";
26
- import "../chunk-EBAMFRB7.js";
27
- import "../chunk-FRJFWTOY.js";
28
- import "../chunk-4MYWAOLG.js";
29
- import "../chunk-RRLIF4PQ.js";
30
- export {
31
- callbackAction,
32
- csrfTokenAction,
33
- sessionAction,
34
- signInAction,
35
- signOutAction
36
- };
@@ -1,136 +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/actions/session/session.ts
21
- var session_exports = {};
22
- __export(session_exports, {
23
- sessionAction: () => sessionAction
24
- });
25
- module.exports = __toCommonJS(session_exports);
26
- var import_router2 = require("@aura-stack/router");
27
-
28
- // src/headers.ts
29
- var cacheControl = {
30
- "Cache-Control": "no-store",
31
- Pragma: "no-cache",
32
- Expires: "0",
33
- Vary: "Cookie"
34
- };
35
- var contentSecurityPolicy = {
36
- "Content-Security-Policy": [
37
- "default-src 'none'",
38
- "script-src 'self'",
39
- "frame-src 'none'",
40
- "object-src 'none'",
41
- "frame-ancestors 'none'",
42
- "base-uri 'none'"
43
- ].join("; ")
44
- };
45
- var secureHeaders = {
46
- "X-Content-Type-Options": "nosniff",
47
- "X-Frame-Options": "DENY",
48
- "Referrer-Policy": "strict-origin-when-cross-origin"
49
- };
50
- var secureApiHeaders = {
51
- ...cacheControl,
52
- ...contentSecurityPolicy,
53
- ...secureHeaders
54
- };
55
-
56
- // src/utils.ts
57
- var import_router = require("@aura-stack/router");
58
-
59
- // src/errors.ts
60
- var AuthInternalError = class extends Error {
61
- type = "AUTH_INTERNAL_ERROR";
62
- code;
63
- constructor(code, message, options) {
64
- super(message, options);
65
- this.code = code;
66
- this.name = new.target.name;
67
- Error.captureStackTrace(this, new.target);
68
- }
69
- };
70
-
71
- // src/utils.ts
72
- var toISOString = (date) => {
73
- return new Date(date).toISOString();
74
- };
75
- var getErrorName = (error) => {
76
- if (error instanceof Error) {
77
- return error.name;
78
- }
79
- return typeof error === "string" ? error : "UnknownError";
80
- };
81
-
82
- // src/cookie.ts
83
- var import_cookie = require("@aura-stack/router/cookie");
84
- var defaultCookieOptions = {
85
- httpOnly: true,
86
- sameSite: "lax",
87
- path: "/",
88
- maxAge: 60 * 60 * 24 * 15
89
- };
90
- var oauthCookieOptions = {
91
- httpOnly: true,
92
- maxAge: 5 * 60,
93
- sameSite: "lax",
94
- expires: new Date(Date.now() + 5 * 60 * 1e3)
95
- };
96
- var expiredCookieAttributes = {
97
- ...defaultCookieOptions,
98
- expires: /* @__PURE__ */ new Date(0),
99
- maxAge: 0,
100
- secure: true
101
- };
102
- var getCookie = (request, cookieName) => {
103
- const cookies = request.headers.get("Cookie");
104
- if (!cookies) {
105
- throw new AuthInternalError("COOKIE_NOT_FOUND", "No cookies found. There is no active session");
106
- }
107
- const value = (0, import_cookie.parse)(cookies)[cookieName];
108
- if (!value) {
109
- throw new AuthInternalError("COOKIE_NOT_FOUND", `Cookie "${cookieName}" not found. There is no active session`);
110
- }
111
- return value;
112
- };
113
-
114
- // src/actions/session/session.ts
115
- var sessionAction = (0, import_router2.createEndpoint)("GET", "/session", async (ctx) => {
116
- const {
117
- request,
118
- context: { jose, cookies, logger }
119
- } = ctx;
120
- try {
121
- const session = getCookie(request, cookies.sessionToken.name);
122
- const decoded = await jose.decodeJWT(session);
123
- logger?.log("AUTH_SESSION_VALID");
124
- const { exp, iat, jti, nbf, ...user } = decoded;
125
- const headers = new Headers(secureApiHeaders);
126
- return Response.json({ user, expires: toISOString(exp * 1e3) }, { headers });
127
- } catch (error) {
128
- logger?.log("AUTH_SESSION_INVALID", { structuredData: { error_type: getErrorName(error) } });
129
- const headers = new import_router2.HeadersBuilder(secureApiHeaders).setCookie(cookies.sessionToken.name, "", expiredCookieAttributes).toHeaders();
130
- return Response.json({ authenticated: false, message: "Unauthorized" }, { status: 401, headers });
131
- }
132
- });
133
- // Annotate the CommonJS export names for ESM import in node:
134
- 0 && (module.exports = {
135
- sessionAction
136
- });
@@ -1,5 +0,0 @@
1
- import * as _aura_stack_router from '@aura-stack/router';
2
-
3
- declare const sessionAction: _aura_stack_router.RouteEndpoint<"GET", "/session", {}>;
4
-
5
- export { sessionAction };
@@ -1,10 +0,0 @@
1
- import {
2
- sessionAction
3
- } from "../../chunk-PHFH2MGS.js";
4
- import "../../chunk-QQVSRXGX.js";
5
- import "../../chunk-5W4BRQYG.js";
6
- import "../../chunk-EBAMFRB7.js";
7
- import "../../chunk-RRLIF4PQ.js";
8
- export {
9
- sessionAction
10
- };
@@ -1,322 +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/actions/signIn/authorization.ts
21
- var authorization_exports = {};
22
- __export(authorization_exports, {
23
- createAuthorizationURL: () => createAuthorizationURL,
24
- createRedirectTo: () => createRedirectTo,
25
- createRedirectURI: () => createRedirectURI,
26
- getOriginURL: () => getOriginURL,
27
- getTrustedOrigins: () => getTrustedOrigins
28
- });
29
- module.exports = __toCommonJS(authorization_exports);
30
-
31
- // src/errors.ts
32
- var AuthInternalError = class extends Error {
33
- type = "AUTH_INTERNAL_ERROR";
34
- code;
35
- constructor(code, message, options2) {
36
- super(message, options2);
37
- this.code = code;
38
- this.name = new.target.name;
39
- Error.captureStackTrace(this, new.target);
40
- }
41
- };
42
-
43
- // src/schemas.ts
44
- var import_zod = require("zod");
45
- var OAuthProviderCredentialsSchema = (0, import_zod.object)({
46
- id: (0, import_zod.string)(),
47
- name: (0, import_zod.string)(),
48
- authorizeURL: (0, import_zod.string)().url(),
49
- accessToken: (0, import_zod.string)().url(),
50
- scope: (0, import_zod.string)(),
51
- userInfo: (0, import_zod.string)().url(),
52
- responseType: (0, import_zod.enum)(["code", "token", "id_token"]),
53
- clientId: (0, import_zod.string)(),
54
- clientSecret: (0, import_zod.string)(),
55
- profile: import_zod.z.function().optional()
56
- });
57
- var OAuthProviderConfigSchema = (0, import_zod.object)({
58
- authorizeURL: (0, import_zod.string)().url(),
59
- accessToken: (0, import_zod.string)().url(),
60
- scope: (0, import_zod.string)().optional(),
61
- userInfo: (0, import_zod.string)().url(),
62
- responseType: (0, import_zod.enum)(["code", "token", "id_token"]),
63
- clientId: (0, import_zod.string)(),
64
- clientSecret: (0, import_zod.string)()
65
- });
66
- var OAuthAuthorization = OAuthProviderConfigSchema.extend({
67
- redirectURI: (0, import_zod.string)(),
68
- state: (0, import_zod.string)(),
69
- codeChallenge: (0, import_zod.string)(),
70
- codeChallengeMethod: (0, import_zod.enum)(["plain", "S256"])
71
- });
72
- var OAuthAuthorizationResponse = (0, import_zod.object)({
73
- state: (0, import_zod.string)({ message: "Missing state parameter in the OAuth authorization response." }),
74
- code: (0, import_zod.string)({ message: "Missing code parameter in the OAuth authorization response." })
75
- });
76
- var OAuthAuthorizationErrorResponse = (0, import_zod.object)({
77
- error: (0, import_zod.enum)([
78
- "invalid_request",
79
- "unauthorized_client",
80
- "access_denied",
81
- "unsupported_response_type",
82
- "invalid_scope",
83
- "server_error",
84
- "temporarily_unavailable"
85
- ]),
86
- error_description: (0, import_zod.string)().optional(),
87
- error_uri: (0, import_zod.string)().optional(),
88
- state: (0, import_zod.string)()
89
- });
90
- var OAuthAccessToken = OAuthProviderConfigSchema.extend({
91
- redirectURI: (0, import_zod.string)(),
92
- code: (0, import_zod.string)(),
93
- codeVerifier: (0, import_zod.string)().min(43).max(128)
94
- });
95
- var OAuthAccessTokenResponse = (0, import_zod.object)({
96
- access_token: (0, import_zod.string)(),
97
- token_type: (0, import_zod.string)().optional(),
98
- expires_in: (0, import_zod.number)().optional(),
99
- refresh_token: (0, import_zod.string)().optional(),
100
- scope: (0, import_zod.string)().optional().or((0, import_zod.null)())
101
- });
102
- var OAuthAccessTokenErrorResponse = (0, import_zod.object)({
103
- error: (0, import_zod.enum)([
104
- "invalid_request",
105
- "invalid_client",
106
- "invalid_grant",
107
- "unauthorized_client",
108
- "unsupported_grant_type",
109
- "invalid_scope"
110
- ]),
111
- error_description: (0, import_zod.string)().optional(),
112
- error_uri: (0, import_zod.string)().optional()
113
- });
114
- var OAuthErrorResponse = (0, import_zod.object)({
115
- error: (0, import_zod.string)(),
116
- error_description: (0, import_zod.string)().optional()
117
- });
118
- var OAuthEnvSchema = (0, import_zod.object)({
119
- clientId: import_zod.z.string().min(1, "OAuth Client ID is required in the environment variables."),
120
- clientSecret: import_zod.z.string().min(1, "OAuth Client Secret is required in the environment variables.")
121
- });
122
-
123
- // src/utils.ts
124
- var import_router = require("@aura-stack/router");
125
- var toSnakeCase = (str) => {
126
- return str.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2").toLowerCase().replace(/^_+/, "");
127
- };
128
- var toUpperCase = (str) => {
129
- return str.toUpperCase();
130
- };
131
- var toCastCase = (obj, type = "snake") => {
132
- return Object.entries(obj).reduce((previous, [key, value]) => {
133
- const newKey = type === "snake" ? toSnakeCase(key) : toUpperCase(key);
134
- return { ...previous, [newKey]: value };
135
- }, {});
136
- };
137
- var equals = (a, b) => {
138
- if (a === null || b === null || a === void 0 || b === void 0) return false;
139
- return a === b;
140
- };
141
- var extractPath = (url) => {
142
- const pathRegex = /^https?:\/\/[a-zA-Z0-9_\-\.]+(:\d+)?(\/.*)$/;
143
- const match = url.match(pathRegex);
144
- return match && match[2] ? match[2] : "/";
145
- };
146
-
147
- // src/assert.ts
148
- var unsafeChars = [
149
- "<",
150
- ">",
151
- '"',
152
- "`",
153
- " ",
154
- "\r",
155
- "\n",
156
- " ",
157
- "\\",
158
- "%2F",
159
- "%5C",
160
- "%2f",
161
- "%5c",
162
- "\r\n",
163
- "%0A",
164
- "%0D",
165
- "%0a",
166
- "%0d",
167
- "..",
168
- "//",
169
- "///",
170
- "...",
171
- "%20",
172
- "\0"
173
- ];
174
- var isValidURL = (value) => {
175
- if (!new RegExp(/^https?:\/\/[^/]/).test(value)) {
176
- return false;
177
- }
178
- const match = value.match(/^(https?:\/\/)(.*)$/);
179
- if (!match) return false;
180
- const rest = match[2];
181
- for (const char of unsafeChars) {
182
- if (rest.includes(char)) return false;
183
- }
184
- const regex = /^https?:\/\/(?:[a-zA-Z0-9._-]+|localhost|\[[0-9a-fA-F:]+\])(?::\d{1,5})?(?:\/[a-zA-Z0-9._~!$&'()?#*+,;=:@-]*)*\/?$/;
185
- return regex.test(match[0]);
186
- };
187
- var isRelativeURL = (value) => {
188
- if (value.length > 100) return false;
189
- for (const char of unsafeChars) {
190
- if (value.includes(char)) return false;
191
- }
192
- const regex = /^\/[a-zA-Z0-9\-_\/.?&=#]*\/?$/;
193
- return regex.test(value);
194
- };
195
- var isSameOrigin = (origin, expected) => {
196
- const originURL = new URL(origin);
197
- const expectedURL = new URL(expected);
198
- return equals(originURL.origin, expectedURL.origin);
199
- };
200
- var patternToRegex = (pattern) => {
201
- try {
202
- if (pattern.length > 2048) return null;
203
- pattern = pattern.replace(/\\/g, "");
204
- const match = pattern.match(/^(https?):\/\/([a-zA-Z0-9.*-]{1,253})(?::(\d{1,5}|\*))?(?:\/.*)?$/);
205
- if (!match) return null;
206
- const [, protocol, host, port] = match;
207
- const hasWildcard = host.includes("*");
208
- if (hasWildcard && !host.startsWith("*.")) return null;
209
- if (hasWildcard && host.slice(2).includes("*")) return null;
210
- const domain = hasWildcard ? host.slice(2) : host;
211
- const escapedDomain = domain.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
212
- const hostRegex = hasWildcard ? `[^.]+\\.${escapedDomain}` : escapedDomain;
213
- const portRegex = port === "*" ? ":\\d{1,5}" : port ? `:${port}` : "";
214
- return new RegExp(`^${protocol}:\\/\\/${hostRegex}${portRegex}$`);
215
- } catch {
216
- return null;
217
- }
218
- };
219
- var isTrustedOrigin = (url, trustedOrigins) => {
220
- if (!isValidURL(url) || trustedOrigins.length === 0) return false;
221
- try {
222
- const urlOrigin = new URL(url).origin;
223
- for (const pattern of trustedOrigins) {
224
- const regex = patternToRegex(pattern);
225
- if (regex?.test(urlOrigin)) return true;
226
- try {
227
- if (isValidURL(pattern) && equals(new URL(pattern).origin, urlOrigin)) return true;
228
- } catch {
229
- }
230
- }
231
- } catch {
232
- }
233
- return false;
234
- };
235
-
236
- // src/actions/signIn/authorization.ts
237
- var createAuthorizationURL = (oauthConfig, redirectURI, state, codeChallenge, codeChallengeMethod, logger) => {
238
- const parsed = OAuthAuthorization.safeParse({ ...oauthConfig, redirectURI, state, codeChallenge, codeChallengeMethod });
239
- if (!parsed.success) {
240
- logger?.log("INVALID_OAUTH_CONFIGURATION", {
241
- structuredData: {
242
- scope: oauthConfig.scope,
243
- redirect_uri: redirectURI,
244
- has_state: Boolean(state),
245
- has_code_challenge: Boolean(codeChallenge),
246
- code_challenge_method: codeChallengeMethod
247
- }
248
- });
249
- throw new AuthInternalError("INVALID_OAUTH_CONFIGURATION", "The OAuth provider configuration is invalid.");
250
- }
251
- const { authorizeURL, ...options2 } = parsed.data;
252
- const { userInfo, accessToken, clientSecret, ...required } = options2;
253
- const searchParams = new URLSearchParams(toCastCase(required));
254
- return `${authorizeURL}?${searchParams}`;
255
- };
256
- var getTrustedOrigins = async (request, trustedOrigins) => {
257
- if (!trustedOrigins) return [];
258
- const raw = typeof trustedOrigins === "function" ? await trustedOrigins(request) : trustedOrigins;
259
- return Array.isArray(raw) ? raw : typeof raw === "string" ? [raw] : [];
260
- };
261
- var getOriginURL = async (request, context) => {
262
- const headers = request.headers;
263
- let origin = new URL(request.url).origin;
264
- const trustedOrigins = await getTrustedOrigins(request, context?.trustedOrigins);
265
- trustedOrigins.push(origin);
266
- if (context?.trustedProxyHeaders) {
267
- const protocol = headers.get("Forwarded")?.match(/proto=([^;]+)/i)?.[1] ?? headers.get("X-Forwarded-Proto") ?? "http";
268
- const host = headers.get("Host") ?? headers.get("Forwarded")?.match(/host=([^;]+)/i)?.[1] ?? headers.get("X-Forwarded-Host") ?? null;
269
- origin = `${protocol}://${host}`;
270
- }
271
- if (!isTrustedOrigin(origin, trustedOrigins)) {
272
- context?.logger?.log("UNTRUSTED_ORIGIN", { structuredData: { origin } });
273
- throw new AuthInternalError("UNTRUSTED_ORIGIN", "The constructed origin URL is not trusted.");
274
- }
275
- return origin;
276
- };
277
- var createRedirectURI = async (request, oauth, context) => {
278
- const origin = await getOriginURL(request, context);
279
- return `${origin}${context.basePath}/callback/${oauth}`;
280
- };
281
- var createRedirectTo = async (request, redirectTo, context) => {
282
- try {
283
- const headers = request.headers;
284
- const requestOrigin = await getOriginURL(request, context);
285
- const origins = await getTrustedOrigins(request, context?.trustedOrigins);
286
- const validateURL = (url) => {
287
- if (!isRelativeURL(url) && !isValidURL(url)) return "/";
288
- if (isRelativeURL(url)) return url;
289
- if (origins.length > 0) {
290
- if (isTrustedOrigin(url, origins)) {
291
- const urlOrigin = new URL(url).origin;
292
- for (const pattern of origins) {
293
- const regex = patternToRegex(pattern);
294
- if (regex?.test(urlOrigin)) {
295
- return isSameOrigin(url, request.url) ? extractPath(url) : url;
296
- }
297
- if (isValidURL(pattern) && equals(new URL(pattern).origin, urlOrigin)) return url;
298
- }
299
- }
300
- context?.logger?.log("OPEN_REDIRECT_ATTACK");
301
- return "/";
302
- }
303
- if (isSameOrigin(url, requestOrigin)) {
304
- return extractPath(url);
305
- }
306
- context?.logger?.log("OPEN_REDIRECT_ATTACK");
307
- return "/";
308
- };
309
- return validateURL(redirectTo ?? headers.get("Referer") ?? headers.get("Origin") ?? "/");
310
- } catch (error) {
311
- context?.logger?.log("POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED");
312
- return "/";
313
- }
314
- };
315
- // Annotate the CommonJS export names for ESM import in node:
316
- 0 && (module.exports = {
317
- createAuthorizationURL,
318
- createRedirectTo,
319
- createRedirectURI,
320
- getOriginURL,
321
- getTrustedOrigins
322
- });
@@ -1,53 +0,0 @@
1
- import { GlobalContext } from '@aura-stack/router';
2
- import { h as OAuthProviderCredentials, I as InternalLogger, d as AuthConfig } from '../../index-CSyIJmCM.js';
3
- import 'zod';
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
- /**
12
- * Constructs the request URI for the Authorization Request to the third-party OAuth service. It includes
13
- * the necessary query parameters such as `client_id`, `redirect_uri`, `response_type`, `scope`, `state`,
14
- * `code_challenge`, and `code_challenge_method`.
15
- *
16
- * @see https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.1
17
- * @see https://datatracker.ietf.org/doc/html/rfc7636#section-4
18
- *
19
- * @param oauthConfig - The OAuth configuration for the third-party service.
20
- * @param redirectURI - The redirect URI where the OAuth service will send the user after authorization.
21
- * @param state - A unique string used to maintain state between the request and callback.
22
- */
23
- declare const createAuthorizationURL: (oauthConfig: OAuthProviderCredentials, redirectURI: string, state: string, codeChallenge: string, codeChallengeMethod: string, logger?: InternalLogger) => string;
24
- /**
25
- * Resolves trusted origins from config (array or function).
26
- */
27
- declare const getTrustedOrigins: (request: Request, trustedOrigins: AuthConfig["trustedOrigins"]) => Promise<string[]>;
28
- declare const getOriginURL: (request: Request, context?: GlobalContext) => Promise<string>;
29
- /**
30
- * Creates the redirect URI for the OAuth callback based on the original request URL and the OAuth provider.
31
- *
32
- * @param requestURL - the original request URL
33
- * @param oauth - OAuth provider name
34
- * @param context - Global context containing configuration and utilities
35
- * @returns The redirect URI for the OAuth callback.
36
- */
37
- declare const createRedirectURI: (request: Request, oauth: string, context: GlobalContext) => Promise<string>;
38
- /**
39
- * Verifies if the request's origin matches the expected origin. It accepts the redirectTo search
40
- * parameter for redirection. It checks the Referer and Origin headers and the request URL against
41
- * the trusted origins list. If they do not match, it returns "/" to avoid potential open redirect attacks.
42
- *
43
- * When `trustedOrigins` is provided, URLs are validated against that list. When not provided,
44
- * the request's derived origin (from request.url or proxy headers) is used as the only trusted origin.
45
- *
46
- * @param request The incoming request object
47
- * @param redirectTo Optional redirectTo parameter to override the referer
48
- * @param context Global context containing configuration and utilities
49
- * @returns A safe URL to redirect to after authentication, or "/" if the URL is not considered safe.
50
- */
51
- declare const createRedirectTo: (request: Request, redirectTo?: string, context?: GlobalContext) => Promise<string>;
52
-
53
- export { createAuthorizationURL, createRedirectTo, createRedirectURI, getOriginURL, getTrustedOrigins };
@@ -1,18 +0,0 @@
1
- import {
2
- createAuthorizationURL,
3
- createRedirectTo,
4
- createRedirectURI,
5
- getOriginURL,
6
- getTrustedOrigins
7
- } from "../../chunk-XUP6KKNG.js";
8
- import "../../chunk-KJBAQZX2.js";
9
- import "../../chunk-4EKY7655.js";
10
- import "../../chunk-QQVSRXGX.js";
11
- import "../../chunk-RRLIF4PQ.js";
12
- export {
13
- createAuthorizationURL,
14
- createRedirectTo,
15
- createRedirectURI,
16
- getOriginURL,
17
- getTrustedOrigins
18
- };