@aura-stack/auth 0.5.0 → 0.7.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 (220) hide show
  1. package/README.md +36 -1
  2. package/dist/@types/index.cjs +0 -18
  3. package/dist/@types/index.d.ts +2 -12
  4. package/dist/@types/index.js +0 -1
  5. package/dist/assert-_fBNnaOk.js +3 -0
  6. package/dist/assert-hDwQ_SPO.cjs +3 -0
  7. package/dist/client/index.cjs +1 -135
  8. package/dist/client/index.d.ts +11 -14
  9. package/dist/client/index.js +1 -10
  10. package/dist/crypto-D6_SoGMH.cjs +1 -0
  11. package/dist/crypto-DyrRzBSQ.js +1 -0
  12. package/dist/env-7as-tgzO.cjs +1 -0
  13. package/dist/env-CJtSi1eX.js +1 -0
  14. package/dist/errors-Czt_w1t_.js +1 -0
  15. package/dist/errors-DcK2ELlk.cjs +1 -0
  16. package/dist/identity-b8FCr0Oa.cjs +1 -0
  17. package/dist/index-C9U6ICDT.d.ts +2796 -0
  18. package/dist/index.cjs +1 -2427
  19. package/dist/index.d.ts +2 -14
  20. package/dist/index.js +1 -59
  21. package/dist/logger-DjXkgSn5.js +1 -0
  22. package/dist/logger-G5PinyEc.cjs +1 -0
  23. package/dist/oauth/atlassian.cjs +1 -57
  24. package/dist/oauth/atlassian.d.ts +2 -12
  25. package/dist/oauth/atlassian.js +1 -6
  26. package/dist/oauth/bitbucket.cjs +1 -49
  27. package/dist/oauth/bitbucket.d.ts +2 -12
  28. package/dist/oauth/bitbucket.js +1 -6
  29. package/dist/oauth/click-up.cjs +1 -0
  30. package/dist/oauth/click-up.d.ts +2 -0
  31. package/dist/oauth/click-up.js +1 -0
  32. package/dist/oauth/discord.cjs +1 -57
  33. package/dist/oauth/discord.d.ts +2 -12
  34. package/dist/oauth/discord.js +1 -6
  35. package/dist/oauth/dribbble.cjs +1 -0
  36. package/dist/oauth/dribbble.d.ts +2 -0
  37. package/dist/oauth/dribbble.js +1 -0
  38. package/dist/oauth/dropbox.cjs +1 -53
  39. package/dist/oauth/dropbox.d.ts +2 -12
  40. package/dist/oauth/dropbox.js +1 -6
  41. package/dist/oauth/figma.cjs +1 -49
  42. package/dist/oauth/figma.d.ts +2 -12
  43. package/dist/oauth/figma.js +1 -6
  44. package/dist/oauth/github.cjs +1 -49
  45. package/dist/oauth/github.d.ts +2 -12
  46. package/dist/oauth/github.js +1 -6
  47. package/dist/oauth/gitlab.cjs +1 -49
  48. package/dist/oauth/gitlab.d.ts +2 -12
  49. package/dist/oauth/gitlab.js +1 -6
  50. package/dist/oauth/index.cjs +1 -673
  51. package/dist/oauth/index.d.ts +2 -12
  52. package/dist/oauth/index.js +1 -68
  53. package/dist/oauth/mailchimp.cjs +1 -49
  54. package/dist/oauth/mailchimp.d.ts +2 -12
  55. package/dist/oauth/mailchimp.js +1 -6
  56. package/dist/oauth/notion.cjs +1 -131
  57. package/dist/oauth/notion.d.ts +2 -12
  58. package/dist/oauth/notion.js +1 -9
  59. package/dist/oauth/pinterest.cjs +1 -49
  60. package/dist/oauth/pinterest.d.ts +2 -12
  61. package/dist/oauth/pinterest.js +1 -6
  62. package/dist/oauth/spotify.cjs +1 -49
  63. package/dist/oauth/spotify.d.ts +2 -12
  64. package/dist/oauth/spotify.js +1 -6
  65. package/dist/oauth/strava.cjs +1 -49
  66. package/dist/oauth/strava.d.ts +2 -12
  67. package/dist/oauth/strava.js +1 -6
  68. package/dist/oauth/twitch.cjs +1 -95
  69. package/dist/oauth/twitch.d.ts +2 -12
  70. package/dist/oauth/twitch.js +1 -7
  71. package/dist/oauth/x.cjs +1 -49
  72. package/dist/oauth/x.d.ts +2 -12
  73. package/dist/oauth/x.js +1 -6
  74. package/dist/oauth-D3_mnBOx.js +1 -0
  75. package/dist/oauth-gPiWxjBd.cjs +1 -0
  76. package/dist/shared/crypto.cjs +1 -0
  77. package/dist/shared/crypto.d.ts +71 -0
  78. package/dist/shared/crypto.js +1 -0
  79. package/dist/shared/identity.cjs +1 -0
  80. package/dist/shared/identity.d.ts +2 -0
  81. package/dist/shared/identity.js +1 -0
  82. package/dist/shared/index.cjs +1 -0
  83. package/dist/shared/index.d.ts +5 -0
  84. package/dist/shared/index.js +1 -0
  85. package/package.json +37 -11
  86. package/dist/@types/router.d.cjs +0 -1
  87. package/dist/@types/router.d.d.ts +0 -16
  88. package/dist/@types/router.d.js +0 -0
  89. package/dist/@types/utility.cjs +0 -18
  90. package/dist/@types/utility.d.ts +0 -6
  91. package/dist/@types/utility.js +0 -1
  92. package/dist/actions/callback/access-token.cjs +0 -250
  93. package/dist/actions/callback/access-token.d.ts +0 -33
  94. package/dist/actions/callback/access-token.js +0 -9
  95. package/dist/actions/callback/callback.cjs +0 -715
  96. package/dist/actions/callback/callback.d.ts +0 -42
  97. package/dist/actions/callback/callback.js +0 -18
  98. package/dist/actions/callback/userinfo.cjs +0 -283
  99. package/dist/actions/callback/userinfo.d.ts +0 -25
  100. package/dist/actions/callback/userinfo.js +0 -13
  101. package/dist/actions/csrfToken/csrfToken.cjs +0 -189
  102. package/dist/actions/csrfToken/csrfToken.d.ts +0 -7
  103. package/dist/actions/csrfToken/csrfToken.js +0 -13
  104. package/dist/actions/index.cjs +0 -1161
  105. package/dist/actions/index.d.ts +0 -17
  106. package/dist/actions/index.js +0 -39
  107. package/dist/actions/session/session.cjs +0 -188
  108. package/dist/actions/session/session.d.ts +0 -7
  109. package/dist/actions/session/session.js +0 -12
  110. package/dist/actions/signIn/authorization-url.cjs +0 -288
  111. package/dist/actions/signIn/authorization-url.d.ts +0 -31
  112. package/dist/actions/signIn/authorization-url.js +0 -16
  113. package/dist/actions/signIn/authorization.cjs +0 -281
  114. package/dist/actions/signIn/authorization.d.ts +0 -54
  115. package/dist/actions/signIn/authorization.js +0 -19
  116. package/dist/actions/signIn/signIn.cjs +0 -595
  117. package/dist/actions/signIn/signIn.d.ts +0 -42
  118. package/dist/actions/signIn/signIn.js +0 -16
  119. package/dist/actions/signOut/signOut.cjs +0 -492
  120. package/dist/actions/signOut/signOut.d.ts +0 -16
  121. package/dist/actions/signOut/signOut.js +0 -15
  122. package/dist/api/createApi.cjs +0 -750
  123. package/dist/api/createApi.d.ts +0 -12
  124. package/dist/api/createApi.js +0 -19
  125. package/dist/api/getSession.cjs +0 -141
  126. package/dist/api/getSession.d.ts +0 -16
  127. package/dist/api/getSession.js +0 -10
  128. package/dist/api/signIn.cjs +0 -549
  129. package/dist/api/signIn.d.ts +0 -26
  130. package/dist/api/signIn.js +0 -15
  131. package/dist/api/signOut.cjs +0 -279
  132. package/dist/api/signOut.d.ts +0 -16
  133. package/dist/api/signOut.js +0 -13
  134. package/dist/assert.cjs +0 -194
  135. package/dist/assert.d.ts +0 -37
  136. package/dist/assert.js +0 -26
  137. package/dist/chunk-2A5B7GWR.js +0 -125
  138. package/dist/chunk-2GQLSIJ2.js +0 -40
  139. package/dist/chunk-2IR674WX.js +0 -44
  140. package/dist/chunk-3J5TUH2I.js +0 -50
  141. package/dist/chunk-4RWSYUKX.js +0 -98
  142. package/dist/chunk-4YHJ4IEQ.js +0 -25
  143. package/dist/chunk-54CZPKR4.js +0 -25
  144. package/dist/chunk-5LZ7TOM3.js +0 -25
  145. package/dist/chunk-5X7JZMEF.js +0 -0
  146. package/dist/chunk-7BE46WWS.js +0 -88
  147. package/dist/chunk-7YYXFKLR.js +0 -35
  148. package/dist/chunk-C3A37LQC.js +0 -33
  149. package/dist/chunk-CITNGXDA.js +0 -31
  150. package/dist/chunk-CWX724AG.js +0 -78
  151. package/dist/chunk-D2CSIUKP.js +0 -74
  152. package/dist/chunk-E6G5YCI6.js +0 -25
  153. package/dist/chunk-EBAMFRB7.js +0 -34
  154. package/dist/chunk-EEE7UM5T.js +0 -25
  155. package/dist/chunk-FPCVZUVG.js +0 -37
  156. package/dist/chunk-FW4W3REU.js +0 -25
  157. package/dist/chunk-GNNBM2WJ.js +0 -83
  158. package/dist/chunk-IPKO6UQN.js +0 -25
  159. package/dist/chunk-ITQ7352M.js +0 -0
  160. package/dist/chunk-JOCGX3RP.js +0 -59
  161. package/dist/chunk-KBXWTD6E.js +0 -94
  162. package/dist/chunk-KMMAZFSJ.js +0 -25
  163. package/dist/chunk-LATR3NIV.js +0 -117
  164. package/dist/chunk-LAYPUDQF.js +0 -39
  165. package/dist/chunk-LDU7A2JE.js +0 -25
  166. package/dist/chunk-LX3TJ2TJ.js +0 -294
  167. package/dist/chunk-NHZBQNRR.js +0 -143
  168. package/dist/chunk-OVHNRULD.js +0 -33
  169. package/dist/chunk-PDP3PHB3.js +0 -127
  170. package/dist/chunk-PG7UYFG5.js +0 -0
  171. package/dist/chunk-PHYNROD4.js +0 -47
  172. package/dist/chunk-QQEKY4XP.js +0 -29
  173. package/dist/chunk-U4RK4LKJ.js +0 -348
  174. package/dist/chunk-U5663F2U.js +0 -70
  175. package/dist/chunk-UN7X6SU5.js +0 -53
  176. package/dist/chunk-UZQJJD6A.js +0 -100
  177. package/dist/chunk-V6LLEAR4.js +0 -80
  178. package/dist/chunk-WHNDRO3N.js +0 -50
  179. package/dist/chunk-XY5R3EHH.js +0 -204
  180. package/dist/chunk-ZNCZVF6U.js +0 -14
  181. package/dist/client/client.cjs +0 -135
  182. package/dist/client/client.d.ts +0 -85
  183. package/dist/client/client.js +0 -9
  184. package/dist/context.cjs +0 -1237
  185. package/dist/context.d.ts +0 -16
  186. package/dist/context.js +0 -28
  187. package/dist/cookie.cjs +0 -277
  188. package/dist/cookie.d.ts +0 -89
  189. package/dist/cookie.js +0 -30
  190. package/dist/createAuth.cjs +0 -2320
  191. package/dist/createAuth.d.ts +0 -12
  192. package/dist/createAuth.js +0 -48
  193. package/dist/env.cjs +0 -78
  194. package/dist/env.d.ts +0 -10
  195. package/dist/env.js +0 -12
  196. package/dist/errors.cjs +0 -102
  197. package/dist/errors.d.ts +0 -60
  198. package/dist/errors.js +0 -22
  199. package/dist/headers.cjs +0 -61
  200. package/dist/headers.d.ts +0 -33
  201. package/dist/headers.js +0 -12
  202. package/dist/index-_aXtxb_s.d.ts +0 -1377
  203. package/dist/jose.cjs +0 -166
  204. package/dist/jose.d.ts +0 -12
  205. package/dist/jose.js +0 -20
  206. package/dist/logger.cjs +0 -424
  207. package/dist/logger.d.ts +0 -12
  208. package/dist/logger.js +0 -17
  209. package/dist/request.cjs +0 -38
  210. package/dist/request.d.ts +0 -13
  211. package/dist/request.js +0 -6
  212. package/dist/schemas.cjs +0 -158
  213. package/dist/schemas.d.ts +0 -229
  214. package/dist/schemas.js +0 -24
  215. package/dist/secure.cjs +0 -170
  216. package/dist/secure.d.ts +0 -41
  217. package/dist/secure.js +0 -20
  218. package/dist/utils.cjs +0 -329
  219. package/dist/utils.d.ts +0 -35
  220. package/dist/utils.js +0 -36
@@ -1,34 +0,0 @@
1
- // src/headers.ts
2
- var cacheControl = {
3
- "Cache-Control": "no-store",
4
- Pragma: "no-cache",
5
- Expires: "0",
6
- Vary: "Cookie"
7
- };
8
- var contentSecurityPolicy = {
9
- "Content-Security-Policy": [
10
- "default-src 'none'",
11
- "script-src 'self'",
12
- "frame-src 'none'",
13
- "object-src 'none'",
14
- "frame-ancestors 'none'",
15
- "base-uri 'none'"
16
- ].join("; ")
17
- };
18
- var secureHeaders = {
19
- "X-Content-Type-Options": "nosniff",
20
- "X-Frame-Options": "DENY",
21
- "Referrer-Policy": "strict-origin-when-cross-origin"
22
- };
23
- var secureApiHeaders = {
24
- ...cacheControl,
25
- ...contentSecurityPolicy,
26
- ...secureHeaders
27
- };
28
-
29
- export {
30
- cacheControl,
31
- contentSecurityPolicy,
32
- secureHeaders,
33
- secureApiHeaders
34
- };
@@ -1,25 +0,0 @@
1
- // src/oauth/x.ts
2
- var x = (options) => {
3
- return {
4
- id: "x",
5
- name: "X",
6
- authorizeURL: "https://twitter.com/i/oauth2/authorize",
7
- accessToken: "https://api.twitter.com/2/oauth2/token",
8
- userInfo: "https://api.twitter.com/2/users/me?user.fields=profile_image_url",
9
- scope: "tweet.read users.read offline.access",
10
- responseType: "code",
11
- profile(profile) {
12
- return {
13
- sub: profile.data.id,
14
- name: profile.data.name,
15
- image: profile.data.profile_image_url,
16
- email: void 0
17
- };
18
- },
19
- ...options
20
- };
21
- };
22
-
23
- export {
24
- x
25
- };
@@ -1,37 +0,0 @@
1
- import {
2
- createCSRF
3
- } from "./chunk-V6LLEAR4.js";
4
- import {
5
- getCookie,
6
- setCookie
7
- } from "./chunk-XY5R3EHH.js";
8
- import {
9
- secureApiHeaders
10
- } from "./chunk-EBAMFRB7.js";
11
-
12
- // src/actions/csrfToken/csrfToken.ts
13
- import { createEndpoint } from "@aura-stack/router";
14
- var getCSRFToken = (request, cookieName) => {
15
- try {
16
- return getCookie(request, cookieName);
17
- } catch {
18
- return void 0;
19
- }
20
- };
21
- var csrfTokenAction = createEndpoint("GET", "/csrfToken", async (ctx) => {
22
- const {
23
- request,
24
- context: { jose, cookies, logger }
25
- } = ctx;
26
- const token = getCSRFToken(request, cookies.csrfToken.name);
27
- logger?.log("CSRF_TOKEN_REQUESTED", { structuredData: { has_token: Boolean(token) } });
28
- const csrfToken = await createCSRF(jose, token);
29
- logger?.log("CSRF_TOKEN_ISSUED", { structuredData: { issued: Boolean(csrfToken) } });
30
- const headers = new Headers(secureApiHeaders);
31
- headers.append("Set-Cookie", setCookie(cookies.csrfToken.name, csrfToken, cookies.csrfToken.attributes));
32
- return Response.json({ csrfToken }, { headers });
33
- });
34
-
35
- export {
36
- csrfTokenAction
37
- };
@@ -1,25 +0,0 @@
1
- // src/oauth/github.ts
2
- var github = (options) => {
3
- return {
4
- id: "github",
5
- name: "GitHub",
6
- authorizeURL: "https://github.com/login/oauth/authorize",
7
- accessToken: "https://github.com/login/oauth/access_token",
8
- userInfo: "https://api.github.com/user",
9
- scope: "read:user user:email",
10
- responseType: "code",
11
- profile: (profile) => {
12
- return {
13
- sub: profile.id.toString(),
14
- name: profile.name ?? profile.login,
15
- email: profile.email ?? void 0,
16
- image: profile.avatar_url
17
- };
18
- },
19
- ...options
20
- };
21
- };
22
-
23
- export {
24
- github
25
- };
@@ -1,83 +0,0 @@
1
- import {
2
- fetchAsync
3
- } from "./chunk-ZNCZVF6U.js";
4
- import {
5
- generateSecure
6
- } from "./chunk-V6LLEAR4.js";
7
- import {
8
- OAuthErrorResponse
9
- } from "./chunk-2A5B7GWR.js";
10
- import {
11
- AURA_AUTH_VERSION
12
- } from "./chunk-LX3TJ2TJ.js";
13
- import {
14
- OAuthProtocolError,
15
- isNativeError,
16
- isOAuthProtocolError
17
- } from "./chunk-U5663F2U.js";
18
-
19
- // src/actions/callback/userinfo.ts
20
- var getDefaultUserInfo = (profile) => {
21
- const sub = generateSecure(16);
22
- return {
23
- sub: profile?.id ?? profile?.sub ?? sub,
24
- email: profile?.email,
25
- name: profile?.name ?? profile?.username ?? profile?.nickname,
26
- image: profile?.image ?? profile?.picture
27
- };
28
- };
29
- var getUserInfo = async (oauthConfig, accessToken, logger) => {
30
- const userInfoConfig = oauthConfig.userInfo;
31
- const userinfoURL = typeof userInfoConfig === "string" ? userInfoConfig : userInfoConfig.url;
32
- const extraHeaders = typeof userInfoConfig === "string" ? void 0 : userInfoConfig.headers;
33
- const method = typeof userInfoConfig === "string" ? "GET" : (userInfoConfig.method ?? "GET").toUpperCase();
34
- try {
35
- logger?.log("OAUTH_USERINFO_REQUEST_INITIATED", {
36
- structuredData: {
37
- endpoint: userinfoURL
38
- }
39
- });
40
- const response = await fetchAsync(userinfoURL, {
41
- method,
42
- headers: {
43
- "User-Agent": `Aura Auth/${AURA_AUTH_VERSION}`,
44
- Accept: "application/json",
45
- Authorization: `Bearer ${accessToken}`,
46
- ...extraHeaders ?? {}
47
- }
48
- });
49
- if (!response.ok) {
50
- logger?.log("OAUTH_USERINFO_INVALID_RESPONSE");
51
- throw new OAuthProtocolError("INVALID_REQUEST", "Invalid userinfo response format");
52
- }
53
- const json = await response.json();
54
- const { success, data } = OAuthErrorResponse.safeParse(json);
55
- if (success) {
56
- logger?.log("OAUTH_USERINFO_ERROR", {
57
- message: "Error response received from OAuth userinfo endpoint",
58
- structuredData: {
59
- error: data.error,
60
- error_description: data.error_description ?? ""
61
- }
62
- });
63
- throw new OAuthProtocolError("INVALID_REQUEST", "An error was received from the OAuth userinfo endpoint.");
64
- }
65
- logger?.log("OAUTH_USERINFO_SUCCESS");
66
- return oauthConfig?.profile ? oauthConfig.profile(json) : getDefaultUserInfo(json);
67
- } catch (error) {
68
- if (isOAuthProtocolError(error)) {
69
- throw error;
70
- }
71
- logger?.log("OAUTH_USERINFO_REQUEST_FAILED");
72
- if (isNativeError(error)) {
73
- throw new OAuthProtocolError("SERVER_ERROR", "Failed to fetch user information from OAuth provider", "", {
74
- cause: error
75
- });
76
- }
77
- throw new OAuthProtocolError("SERVER_ERROR", "Failed to fetch user information", "", { cause: error });
78
- }
79
- };
80
-
81
- export {
82
- getUserInfo
83
- };
@@ -1,25 +0,0 @@
1
- // src/oauth/spotify.ts
2
- var spotify = (options) => {
3
- return {
4
- id: "spotify",
5
- name: "Spotify",
6
- authorizeURL: "https://accounts.spotify.com/authorize",
7
- accessToken: "https://accounts.spotify.com/api/token",
8
- userInfo: "https://api.spotify.com/v1/me",
9
- scope: "user-read-private user-read-email",
10
- responseType: "code",
11
- profile(profile) {
12
- return {
13
- sub: profile.id,
14
- name: profile.display_name,
15
- email: profile.email,
16
- image: profile.images[0]?.url ?? void 0
17
- };
18
- },
19
- ...options
20
- };
21
- };
22
-
23
- export {
24
- spotify
25
- };
File without changes
@@ -1,59 +0,0 @@
1
- import {
2
- createAuthorizationURL
3
- } from "./chunk-D2CSIUKP.js";
4
- import {
5
- createRedirectTo,
6
- createRedirectURI,
7
- createSignInURL,
8
- getBaseURL
9
- } from "./chunk-LATR3NIV.js";
10
- import {
11
- AuthInternalError
12
- } from "./chunk-U5663F2U.js";
13
- import {
14
- cacheControl
15
- } from "./chunk-EBAMFRB7.js";
16
-
17
- // src/api/signIn.ts
18
- import { HeadersBuilder } from "@aura-stack/router";
19
- var signIn = async (oauth, {
20
- ctx,
21
- headers: headersInit,
22
- redirectTo = "/",
23
- redirect,
24
- request: requestInit
25
- }) => {
26
- const headers = new Headers(headersInit);
27
- const provider = ctx.oauth[oauth];
28
- if (!provider) {
29
- throw new AuthInternalError("INVALID_OAUTH_CONFIGURATION", `The OAuth provider "${oauth}" is not configured.`);
30
- }
31
- let request = requestInit;
32
- if (!request) {
33
- const origin = await getBaseURL({ ctx, headers });
34
- const url = `${origin}${ctx.basePath}/signIn/${oauth}`;
35
- request = new Request(url, { headers });
36
- }
37
- if (redirect === false) {
38
- const signInURL = await createSignInURL({ request, oauth, ctx, redirectTo });
39
- return { redirect: false, signInURL };
40
- }
41
- const redirectURI = await createRedirectURI(request, oauth, ctx);
42
- const redirectToValue = await createRedirectTo(request, redirectTo, ctx);
43
- const { authorization, state, codeVerifier } = await createAuthorizationURL(provider, redirectURI, ctx);
44
- ctx?.logger?.log("SIGN_IN_INITIATED", {
45
- structuredData: { oauth_provider: oauth }
46
- });
47
- const headersList = new HeadersBuilder(cacheControl).setHeader("Location", authorization).setCookie(ctx.cookies.state.name, state, ctx.cookies.state.attributes).setCookie(ctx.cookies.redirectURI.name, redirectURI, ctx.cookies.redirectURI.attributes).setCookie(ctx.cookies.redirectTo.name, redirectToValue, ctx.cookies.redirectTo.attributes).setCookie(ctx.cookies.codeVerifier.name, codeVerifier, ctx.cookies.codeVerifier.attributes).toHeaders();
48
- return Response.json(
49
- { redirect: redirect ?? true, signInURL: authorization },
50
- {
51
- status: redirect ?? true ? 302 : 200,
52
- headers: headersList
53
- }
54
- );
55
- };
56
-
57
- export {
58
- signIn
59
- };
@@ -1,94 +0,0 @@
1
- import {
2
- verifyCSRF
3
- } from "./chunk-V6LLEAR4.js";
4
- import {
5
- getErrorName
6
- } from "./chunk-LX3TJ2TJ.js";
7
- import {
8
- expiredCookieAttributes,
9
- getCookie
10
- } from "./chunk-XY5R3EHH.js";
11
- import {
12
- AuthSecurityError
13
- } from "./chunk-U5663F2U.js";
14
- import {
15
- secureApiHeaders
16
- } from "./chunk-EBAMFRB7.js";
17
-
18
- // src/api/signOut.ts
19
- import { HeadersBuilder } from "@aura-stack/router";
20
- var signOut = async ({
21
- ctx,
22
- headers: headersInit,
23
- redirectTo = "/",
24
- skipCSRFCheck = false
25
- }) => {
26
- const headers = new Headers(headersInit);
27
- const header = headers.get("X-CSRF-Token");
28
- let session = null;
29
- let csrfToken = null;
30
- try {
31
- session = getCookie(headers, ctx.cookies.sessionToken.name);
32
- } catch {
33
- throw new AuthSecurityError("SESSION_TOKEN_MISSING", "The sessionToken is missing.");
34
- }
35
- try {
36
- csrfToken = getCookie(headers, ctx.cookies.csrfToken.name);
37
- } catch {
38
- throw new AuthSecurityError("CSRF_TOKEN_MISSING", "The CSRF token is missing.");
39
- }
40
- ctx?.logger?.log("SIGN_OUT_ATTEMPT", {
41
- structuredData: {
42
- has_session: Boolean(session),
43
- has_csrf_token: Boolean(csrfToken),
44
- has_csrf_header: Boolean(header),
45
- skip_csrf_check: skipCSRFCheck
46
- }
47
- });
48
- if (!session) {
49
- ctx?.logger?.log("SESSION_TOKEN_MISSING");
50
- throw new AuthSecurityError("SESSION_TOKEN_MISSING", "The sessionToken is missing.");
51
- }
52
- if (!skipCSRFCheck) {
53
- if (!csrfToken) {
54
- ctx?.logger?.log("CSRF_TOKEN_MISSING");
55
- throw new AuthSecurityError("CSRF_TOKEN_MISSING", "The CSRF token is missing.");
56
- }
57
- if (!header) {
58
- ctx?.logger?.log("CSRF_HEADER_MISSING");
59
- throw new AuthSecurityError("CSRF_HEADER_MISSING", "The CSRF header is missing.");
60
- }
61
- try {
62
- await verifyCSRF(ctx.jose, csrfToken, header);
63
- } catch (error) {
64
- ctx?.logger?.log("CSRF_TOKEN_INVALID", { structuredData: { error_type: getErrorName(error) } });
65
- throw new AuthSecurityError("CSRF_TOKEN_INVALID", "CSRF token verification failed");
66
- }
67
- ctx?.logger?.log("SIGN_OUT_CSRF_VERIFIED");
68
- } else {
69
- try {
70
- await ctx.jose.verifyJWS(csrfToken);
71
- } catch (error) {
72
- ctx?.logger?.log("CSRF_TOKEN_INVALID", { structuredData: { error_type: getErrorName(error) } });
73
- throw new AuthSecurityError("CSRF_TOKEN_INVALID", "CSRF token verification failed");
74
- }
75
- }
76
- try {
77
- await ctx.jose.decodeJWT(session);
78
- ctx?.logger?.log("SIGN_OUT_SUCCESS");
79
- } catch (error) {
80
- ctx?.logger?.log("INVALID_JWT_TOKEN", { structuredData: { error_type: getErrorName(error) } });
81
- }
82
- const headersList = new HeadersBuilder(secureApiHeaders).setHeader("Location", redirectTo).setCookie(ctx.cookies.csrfToken.name, "", expiredCookieAttributes).setCookie(ctx.cookies.sessionToken.name, "", expiredCookieAttributes).toHeaders();
83
- return Response.json(
84
- { redirect: Boolean(redirectTo), url: redirectTo },
85
- {
86
- status: 202,
87
- headers: headersList
88
- }
89
- );
90
- };
91
-
92
- export {
93
- signOut
94
- };
@@ -1,25 +0,0 @@
1
- // src/oauth/figma.ts
2
- var figma = (options) => {
3
- return {
4
- id: "figma",
5
- name: "Figma",
6
- authorizeURL: "https://www.figma.com/oauth",
7
- accessToken: "https://api.figma.com/v1/oauth/token",
8
- userInfo: "https://api.figma.com/v1/me",
9
- scope: "current_user:read",
10
- responseType: "code",
11
- profile(profile) {
12
- return {
13
- sub: profile.id,
14
- name: profile.handle,
15
- email: profile.email,
16
- image: profile.img_url
17
- };
18
- },
19
- ...options
20
- };
21
- };
22
-
23
- export {
24
- figma
25
- };
@@ -1,117 +0,0 @@
1
- import {
2
- equals,
3
- extractPath,
4
- isRelativeURL,
5
- isSameOrigin,
6
- isTrustedOrigin,
7
- isValidURL,
8
- patternToRegex
9
- } from "./chunk-LX3TJ2TJ.js";
10
- import {
11
- getEnv
12
- } from "./chunk-WHNDRO3N.js";
13
- import {
14
- AuthInternalError
15
- } from "./chunk-U5663F2U.js";
16
-
17
- // src/actions/signIn/authorization.ts
18
- var getTrustedOrigins = async (request, trustedOrigins) => {
19
- if (!trustedOrigins) return [];
20
- const raw = typeof trustedOrigins === "function" ? await trustedOrigins(request) : trustedOrigins;
21
- return Array.isArray(raw) ? raw : typeof raw === "string" ? [raw] : [];
22
- };
23
- var getBaseURL = async ({
24
- ctx,
25
- request,
26
- headers: headersInit
27
- }) => {
28
- const origin = getEnv("BASE_URL") || ctx?.baseURL;
29
- if (origin && origin !== "/") return origin;
30
- if (ctx?.trustedProxyHeaders) {
31
- const headers = headersInit && new Headers(headersInit) || request?.headers;
32
- const protocol = headers?.get("Forwarded")?.match(/proto=([^;]+)/i)?.[1] ?? headers?.get("X-Forwarded-Proto") ?? "http";
33
- const host = headers?.get("Host") ?? headers?.get("Forwarded")?.match(/host=([^;]+)/i)?.[1] ?? headers?.get("X-Forwarded-Host") ?? null;
34
- if (host) return `${protocol}://${host}`;
35
- throw new AuthInternalError(
36
- "INVALID_OAUTH_CONFIGURATION",
37
- "The URL cannot be constructed. Please set the BASE_URL environment variable or provide trusted proxy host headers."
38
- );
39
- }
40
- try {
41
- return new URL(request?.url ?? "not-found").origin;
42
- } catch (error) {
43
- throw new AuthInternalError(
44
- "INVALID_OAUTH_CONFIGURATION",
45
- "The URL cannot be constructed. Please set the BASE_URL environment variable or enable trustedProxyHeaders.",
46
- { cause: error }
47
- );
48
- }
49
- };
50
- var getOriginURL = async (request, context) => {
51
- const trustedOrigins = await getTrustedOrigins(request, context?.trustedOrigins);
52
- trustedOrigins.push(new URL(request.url).origin);
53
- const origin = await getBaseURL({ request, ctx: context });
54
- if (!isTrustedOrigin(origin, trustedOrigins)) {
55
- context?.logger?.log("UNTRUSTED_ORIGIN", { structuredData: { origin } });
56
- throw new AuthInternalError("UNTRUSTED_ORIGIN", "The constructed origin URL is not trusted.");
57
- }
58
- return origin;
59
- };
60
- var createRedirectURI = async (request, oauth, context) => {
61
- const origin = await getOriginURL(request, context);
62
- return `${origin}${context.basePath}/callback/${oauth}`;
63
- };
64
- var createSignInURL = async ({
65
- request,
66
- oauth,
67
- ctx,
68
- redirectTo
69
- }) => {
70
- const origin = await getOriginURL(request, ctx);
71
- const searchParams = new URLSearchParams();
72
- if (redirectTo !== void 0) searchParams.set("redirectTo", String(redirectTo));
73
- return `${origin}${ctx.basePath}/signIn/${oauth}?${searchParams.toString()}`;
74
- };
75
- var createRedirectTo = async (request, redirectTo, context) => {
76
- try {
77
- const headers = request.headers;
78
- const requestOrigin = await getOriginURL(request, context);
79
- const origins = await getTrustedOrigins(request, context?.trustedOrigins);
80
- const validateURL = (url) => {
81
- if (!isRelativeURL(url) && !isValidURL(url)) return "/";
82
- if (isRelativeURL(url)) return url;
83
- if (origins.length > 0) {
84
- if (isTrustedOrigin(url, origins)) {
85
- const urlOrigin = new URL(url).origin;
86
- for (const pattern of origins) {
87
- const regex = patternToRegex(pattern);
88
- if (regex?.test(urlOrigin)) {
89
- return isSameOrigin(url, request.url) ? extractPath(url) : url;
90
- }
91
- if (isValidURL(pattern) && equals(new URL(pattern).origin, urlOrigin)) return url;
92
- }
93
- }
94
- context?.logger?.log("OPEN_REDIRECT_ATTACK");
95
- return "/";
96
- }
97
- if (isSameOrigin(url, requestOrigin)) {
98
- return extractPath(url);
99
- }
100
- context?.logger?.log("OPEN_REDIRECT_ATTACK");
101
- return "/";
102
- };
103
- return validateURL(redirectTo ?? headers.get("Referer") ?? headers.get("Origin") ?? "/");
104
- } catch (error) {
105
- context?.logger?.log("POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED");
106
- return "/";
107
- }
108
- };
109
-
110
- export {
111
- getTrustedOrigins,
112
- getBaseURL,
113
- getOriginURL,
114
- createRedirectURI,
115
- createSignInURL,
116
- createRedirectTo
117
- };
@@ -1,39 +0,0 @@
1
- import {
2
- getSession
3
- } from "./chunk-CITNGXDA.js";
4
- import {
5
- signIn
6
- } from "./chunk-JOCGX3RP.js";
7
- import {
8
- signOut
9
- } from "./chunk-KBXWTD6E.js";
10
- import {
11
- validateRedirectTo
12
- } from "./chunk-LX3TJ2TJ.js";
13
-
14
- // src/api/createApi.ts
15
- var createAuthAPI = (ctx) => {
16
- return {
17
- getSession: async (options) => {
18
- const session = await getSession({ ctx, headers: options.headers });
19
- return session;
20
- },
21
- signIn: async (oauth, options) => {
22
- return signIn(oauth, {
23
- ctx,
24
- headers: options?.headers,
25
- request: options?.request,
26
- redirect: options?.redirect,
27
- redirectTo: options?.redirectTo
28
- });
29
- },
30
- signOut: async (options) => {
31
- const redirectTo = validateRedirectTo(options?.redirectTo ?? "/");
32
- return signOut({ ctx, headers: options.headers, redirectTo, skipCSRFCheck: true });
33
- }
34
- };
35
- };
36
-
37
- export {
38
- createAuthAPI
39
- };
@@ -1,25 +0,0 @@
1
- // src/oauth/mailchimp.ts
2
- var mailchimp = (options) => {
3
- return {
4
- id: "mailchimp",
5
- name: "Mailchimp",
6
- authorizeURL: "https://login.mailchimp.com/oauth2/authorize",
7
- accessToken: "https://login.mailchimp.com/oauth2/token",
8
- userInfo: "https://login.mailchimp.com/oauth2/metadata",
9
- scope: "",
10
- responseType: "code",
11
- profile(profile) {
12
- return {
13
- sub: profile.user_id,
14
- name: profile.accountname,
15
- email: profile.login.email,
16
- image: profile.login.avatar
17
- };
18
- },
19
- ...options
20
- };
21
- };
22
-
23
- export {
24
- mailchimp
25
- };