@aura-stack/auth 0.1.0-rc.7 → 0.1.0-rc.9

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 (117) hide show
  1. package/dist/@types/index.cjs +15 -15
  2. package/dist/@types/index.d.ts +31 -7
  3. package/dist/@types/index.js +1 -1
  4. package/dist/@types/router.d.cjs +1 -1
  5. package/dist/@types/router.d.d.ts +7 -7
  6. package/dist/@types/utility.cjs +15 -15
  7. package/dist/@types/utility.d.ts +6 -6
  8. package/dist/@types/utility.js +1 -1
  9. package/dist/actions/callback/access-token.cjs +143 -143
  10. package/dist/actions/callback/access-token.d.ts +20 -15
  11. package/dist/actions/callback/access-token.js +4 -8
  12. package/dist/actions/callback/callback.cjs +455 -437
  13. package/dist/actions/callback/callback.d.ts +12 -10
  14. package/dist/actions/callback/callback.js +12 -16
  15. package/dist/actions/callback/userinfo.cjs +134 -131
  16. package/dist/actions/callback/userinfo.d.ts +9 -9
  17. package/dist/actions/callback/userinfo.js +6 -10
  18. package/dist/actions/csrfToken/csrfToken.cjs +171 -162
  19. package/dist/actions/csrfToken/csrfToken.d.ts +3 -3
  20. package/dist/actions/csrfToken/csrfToken.js +8 -12
  21. package/dist/actions/index.cjs +773 -746
  22. package/dist/actions/index.d.ts +13 -13
  23. package/dist/actions/index.js +18 -34
  24. package/dist/actions/session/session.cjs +155 -149
  25. package/dist/actions/session/session.d.ts +3 -3
  26. package/dist/actions/session/session.js +7 -11
  27. package/dist/actions/signIn/authorization.cjs +249 -231
  28. package/dist/actions/signIn/authorization.d.ts +18 -12
  29. package/dist/actions/signIn/authorization.js +6 -16
  30. package/dist/actions/signIn/signIn.cjs +423 -396
  31. package/dist/actions/signIn/signIn.d.ts +10 -10
  32. package/dist/actions/signIn/signIn.js +10 -14
  33. package/dist/actions/signOut/signOut.cjs +440 -417
  34. package/dist/actions/signOut/signOut.d.ts +3 -3
  35. package/dist/actions/signOut/signOut.js +11 -15
  36. package/dist/assert.cjs +36 -35
  37. package/dist/assert.d.ts +4 -4
  38. package/dist/assert.js +2 -10
  39. package/dist/chunk-256KIVJL.js +96 -85
  40. package/dist/chunk-42XB3YCW.js +17 -19
  41. package/dist/chunk-6SM22VVJ.js +10 -13
  42. package/dist/chunk-CAKJT3KS.js +69 -84
  43. package/dist/chunk-E3OXBRYF.js +17 -19
  44. package/dist/chunk-EBPE35JT.js +26 -28
  45. package/dist/chunk-FIPU4MLT.js +16 -18
  46. package/dist/chunk-FJUDBLCP.js +43 -50
  47. package/dist/chunk-FKRDCWBF.js +17 -19
  48. package/dist/chunk-GZU3RBTB.js +40 -51
  49. package/dist/chunk-HGJ4TXY4.js +100 -132
  50. package/dist/chunk-HMRKN75I.js +63 -63
  51. package/dist/chunk-IKHPGFCW.js +9 -11
  52. package/dist/chunk-JAPMIE6S.js +5 -7
  53. package/dist/chunk-KRNOMBXQ.js +17 -19
  54. package/dist/chunk-LLR722CL.js +70 -91
  55. package/dist/chunk-RLT4RFKV.js +30 -39
  56. package/dist/chunk-SJPDVKUS.js +88 -107
  57. package/dist/chunk-SMQO5WD7.js +16 -26
  58. package/dist/chunk-STHEPPUZ.js +6 -8
  59. package/dist/chunk-UJJ7R56J.js +37 -47
  60. package/dist/chunk-UTDLUEEG.js +25 -0
  61. package/dist/chunk-VFTYH33W.js +37 -54
  62. package/dist/chunk-XXJKNKGQ.js +23 -33
  63. package/dist/chunk-ZV4BH47P.js +134 -132
  64. package/dist/cookie.cjs +175 -169
  65. package/dist/cookie.d.ts +51 -23
  66. package/dist/cookie.js +34 -34
  67. package/dist/error.cjs +75 -75
  68. package/dist/error.d.ts +30 -30
  69. package/dist/error.js +8 -15
  70. package/dist/headers.cjs +28 -28
  71. package/dist/headers.d.ts +2 -2
  72. package/dist/headers.js +2 -6
  73. package/dist/index-DpfbvTZ_.d.ts +298 -249
  74. package/dist/index.cjs +969 -933
  75. package/dist/index.d.ts +31 -10
  76. package/dist/index.js +50 -70
  77. package/dist/jose.cjs +67 -52
  78. package/dist/jose.d.ts +8 -8
  79. package/dist/jose.js +5 -9
  80. package/dist/oauth/bitbucket.cjs +38 -38
  81. package/dist/oauth/bitbucket.d.ts +7 -7
  82. package/dist/oauth/bitbucket.js +2 -6
  83. package/dist/oauth/discord.cjs +48 -48
  84. package/dist/oauth/discord.d.ts +7 -7
  85. package/dist/oauth/discord.js +2 -6
  86. package/dist/oauth/figma.cjs +39 -39
  87. package/dist/oauth/figma.d.ts +7 -7
  88. package/dist/oauth/figma.js +2 -6
  89. package/dist/oauth/github.cjs +31 -31
  90. package/dist/oauth/github.d.ts +7 -7
  91. package/dist/oauth/github.js +2 -6
  92. package/dist/oauth/gitlab.cjs +39 -39
  93. package/dist/oauth/gitlab.d.ts +7 -7
  94. package/dist/oauth/gitlab.js +2 -6
  95. package/dist/oauth/index.cjs +180 -180
  96. package/dist/oauth/index.d.ts +26 -7
  97. package/dist/oauth/index.js +9 -36
  98. package/dist/oauth/spotify.cjs +39 -39
  99. package/dist/oauth/spotify.d.ts +7 -7
  100. package/dist/oauth/spotify.js +2 -6
  101. package/dist/oauth/x.cjs +39 -39
  102. package/dist/oauth/x.d.ts +7 -7
  103. package/dist/oauth/x.js +2 -6
  104. package/dist/response.cjs +27 -27
  105. package/dist/response.d.ts +2 -2
  106. package/dist/response.js +2 -6
  107. package/dist/schemas.cjs +91 -91
  108. package/dist/schemas.d.ts +126 -93
  109. package/dist/schemas.js +18 -18
  110. package/dist/secure.cjs +98 -95
  111. package/dist/secure.d.ts +17 -17
  112. package/dist/secure.js +4 -18
  113. package/dist/utils.cjs +132 -119
  114. package/dist/utils.d.ts +26 -11
  115. package/dist/utils.js +21 -21
  116. package/package.json +1 -1
  117. package/dist/chunk-X7M4CQTN.js +0 -25
@@ -1,112 +1,93 @@
1
- import {
2
- createRedirectTo
3
- } from "./chunk-CAKJT3KS.js";
4
- import {
5
- expireCookie,
6
- getCookie,
7
- secureCookieOptions
8
- } from "./chunk-ZV4BH47P.js";
9
- import {
10
- cacheControl
11
- } from "./chunk-STHEPPUZ.js";
12
- import {
13
- verifyCSRF
14
- } from "./chunk-GZU3RBTB.js";
15
- import {
16
- getNormalizedOriginPath
17
- } from "./chunk-256KIVJL.js";
18
- import {
19
- InvalidCsrfTokenError,
20
- InvalidRedirectToError
21
- } from "./chunk-FJUDBLCP.js";
22
- import {
23
- AuraResponse
24
- } from "./chunk-JAPMIE6S.js";
1
+ import { createRedirectTo } from "./chunk-CAKJT3KS.js"
2
+ import { expireCookie, getCookie, secureCookieOptions } from "./chunk-ZV4BH47P.js"
3
+ import { cacheControl } from "./chunk-STHEPPUZ.js"
4
+ import { verifyCSRF } from "./chunk-GZU3RBTB.js"
5
+ import { getNormalizedOriginPath } from "./chunk-256KIVJL.js"
6
+ import { InvalidCsrfTokenError, InvalidRedirectToError } from "./chunk-FJUDBLCP.js"
7
+ import { AuraResponse } from "./chunk-JAPMIE6S.js"
25
8
 
26
9
  // src/actions/signOut/signOut.ts
27
- import z from "zod";
28
- import { createEndpoint, createEndpointConfig, statusCode } from "@aura-stack/router";
10
+ import z from "zod"
11
+ import { createEndpoint, createEndpointConfig, statusCode } from "@aura-stack/router"
29
12
  var config = createEndpointConfig({
30
- schemas: {
31
- searchParams: z.object({
32
- token_type_hint: z.literal("session_token"),
33
- redirectTo: z.string().optional()
34
- })
35
- }
36
- });
37
- var signOutAction = createEndpoint(
38
- "POST",
39
- "/signOut",
40
- async (ctx) => {
41
- const {
42
- request,
43
- headers,
44
- searchParams: { redirectTo },
45
- context: { cookies, jose, trustedProxyHeaders }
46
- } = ctx;
47
- try {
48
- const cookiesOptions = secureCookieOptions(request, cookies, trustedProxyHeaders);
49
- const session = getCookie(request, "sessionToken", cookiesOptions);
50
- const csrfToken = getCookie(request, "csrfToken", {
51
- ...cookiesOptions,
52
- prefix: cookiesOptions.secure ? "__Host-" : ""
53
- });
54
- const header = headers.get("X-CSRF-Token");
55
- if (!header || !session || !csrfToken) {
56
- throw new Error("Missing CSRF token or session token");
57
- }
58
- await verifyCSRF(jose, csrfToken, header);
59
- await jose.decodeJWT(session);
60
- const normalizedOriginPath = getNormalizedOriginPath(request.url);
61
- const location = createRedirectTo(
62
- new Request(normalizedOriginPath, {
63
- headers
13
+ schemas: {
14
+ searchParams: z.object({
15
+ token_type_hint: z.literal("session_token"),
16
+ redirectTo: z.string().optional(),
64
17
  }),
65
- redirectTo
66
- );
67
- const responseHeaders = new Headers(cacheControl);
68
- responseHeaders.append("Set-Cookie", expireCookie("sessionToken", cookiesOptions));
69
- responseHeaders.append(
70
- "Set-Cookie",
71
- expireCookie("csrfToken", { ...cookiesOptions, prefix: cookiesOptions.secure ? "__Host-" : "" })
72
- );
73
- responseHeaders.append("Location", location);
74
- return Response.json(
75
- { message: "Signed out successfully" },
76
- { status: statusCode.ACCEPTED, headers: responseHeaders }
77
- );
78
- } catch (error) {
79
- if (error instanceof InvalidCsrfTokenError) {
80
- return AuraResponse.json(
81
- {
82
- error: "invalid_csrf_token",
83
- error_description: "The provided CSRF token is invalid or has expired"
84
- },
85
- { status: statusCode.UNAUTHORIZED }
86
- );
87
- }
88
- if (error instanceof InvalidRedirectToError) {
89
- const { type, message } = error;
90
- return AuraResponse.json(
91
- {
92
- error: type,
93
- error_description: message
94
- },
95
- { status: statusCode.BAD_REQUEST }
96
- );
97
- }
98
- return AuraResponse.json(
99
- {
100
- error: "invalid_session_token",
101
- error_description: "The provided sessionToken is invalid or has already expired"
102
- },
103
- { status: statusCode.UNAUTHORIZED }
104
- );
105
- }
106
- },
107
- config
108
- );
18
+ },
19
+ })
20
+ var signOutAction = createEndpoint(
21
+ "POST",
22
+ "/signOut",
23
+ async (ctx) => {
24
+ const {
25
+ request,
26
+ headers,
27
+ searchParams: { redirectTo },
28
+ context: { cookies, jose, trustedProxyHeaders },
29
+ } = ctx
30
+ try {
31
+ const cookiesOptions = secureCookieOptions(request, cookies, trustedProxyHeaders)
32
+ const session = getCookie(request, "sessionToken", cookiesOptions)
33
+ const csrfToken = getCookie(request, "csrfToken", {
34
+ ...cookiesOptions,
35
+ prefix: cookiesOptions.secure ? "__Host-" : "",
36
+ })
37
+ const header = headers.get("X-CSRF-Token")
38
+ if (!header || !session || !csrfToken) {
39
+ throw new Error("Missing CSRF token or session token")
40
+ }
41
+ await verifyCSRF(jose, csrfToken, header)
42
+ await jose.decodeJWT(session)
43
+ const normalizedOriginPath = getNormalizedOriginPath(request.url)
44
+ const location = createRedirectTo(
45
+ new Request(normalizedOriginPath, {
46
+ headers,
47
+ }),
48
+ redirectTo
49
+ )
50
+ const responseHeaders = new Headers(cacheControl)
51
+ responseHeaders.append("Set-Cookie", expireCookie("sessionToken", cookiesOptions))
52
+ responseHeaders.append(
53
+ "Set-Cookie",
54
+ expireCookie("csrfToken", { ...cookiesOptions, prefix: cookiesOptions.secure ? "__Host-" : "" })
55
+ )
56
+ responseHeaders.append("Location", location)
57
+ return Response.json(
58
+ { message: "Signed out successfully" },
59
+ { status: statusCode.ACCEPTED, headers: responseHeaders }
60
+ )
61
+ } catch (error) {
62
+ if (error instanceof InvalidCsrfTokenError) {
63
+ return AuraResponse.json(
64
+ {
65
+ error: "invalid_csrf_token",
66
+ error_description: "The provided CSRF token is invalid or has expired",
67
+ },
68
+ { status: statusCode.UNAUTHORIZED }
69
+ )
70
+ }
71
+ if (error instanceof InvalidRedirectToError) {
72
+ const { type, message } = error
73
+ return AuraResponse.json(
74
+ {
75
+ error: type,
76
+ error_description: message,
77
+ },
78
+ { status: statusCode.BAD_REQUEST }
79
+ )
80
+ }
81
+ return AuraResponse.json(
82
+ {
83
+ error: "invalid_session_token",
84
+ error_description: "The provided sessionToken is invalid or has already expired",
85
+ },
86
+ { status: statusCode.UNAUTHORIZED }
87
+ )
88
+ }
89
+ },
90
+ config
91
+ )
109
92
 
110
- export {
111
- signOutAction
112
- };
93
+ export { signOutAction }
@@ -1,30 +1,20 @@
1
- import {
2
- getCookie,
3
- secureCookieOptions,
4
- setCookie
5
- } from "./chunk-ZV4BH47P.js";
6
- import {
7
- cacheControl
8
- } from "./chunk-STHEPPUZ.js";
9
- import {
10
- createCSRF
11
- } from "./chunk-GZU3RBTB.js";
1
+ import { getCookie, secureCookieOptions, setCookie } from "./chunk-ZV4BH47P.js"
2
+ import { cacheControl } from "./chunk-STHEPPUZ.js"
3
+ import { createCSRF } from "./chunk-GZU3RBTB.js"
12
4
 
13
5
  // src/actions/csrfToken/csrfToken.ts
14
- import { createEndpoint } from "@aura-stack/router";
6
+ import { createEndpoint } from "@aura-stack/router"
15
7
  var csrfTokenAction = createEndpoint("GET", "/csrfToken", async (ctx) => {
16
- const {
17
- request,
18
- context: { cookies, jose, trustedProxyHeaders }
19
- } = ctx;
20
- const cookieOptions = secureCookieOptions(request, { ...cookies, strategy: "host" }, trustedProxyHeaders);
21
- const existingCSRFToken = getCookie(request, "csrfToken", cookieOptions, true);
22
- const csrfToken = await createCSRF(jose, existingCSRFToken);
23
- const headers = new Headers(cacheControl);
24
- headers.set("Set-Cookie", setCookie("csrfToken", csrfToken, cookieOptions));
25
- return Response.json({ csrfToken }, { headers });
26
- });
8
+ const {
9
+ request,
10
+ context: { cookies, jose, trustedProxyHeaders },
11
+ } = ctx
12
+ const cookieOptions = secureCookieOptions(request, { ...cookies, strategy: "host" }, trustedProxyHeaders)
13
+ const existingCSRFToken = getCookie(request, "csrfToken", cookieOptions, true)
14
+ const csrfToken = await createCSRF(jose, existingCSRFToken)
15
+ const headers = new Headers(cacheControl)
16
+ headers.set("Set-Cookie", setCookie("csrfToken", csrfToken, cookieOptions))
17
+ return Response.json({ csrfToken }, { headers })
18
+ })
27
19
 
28
- export {
29
- csrfTokenAction
30
- };
20
+ export { csrfTokenAction }
@@ -1,11 +1,9 @@
1
1
  // src/headers.ts
2
2
  var cacheControl = {
3
- "Cache-Control": "no-store",
4
- Pragma: "no-cache",
5
- Expires: "0",
6
- Vary: "Cookie"
7
- };
3
+ "Cache-Control": "no-store",
4
+ Pragma: "no-cache",
5
+ Expires: "0",
6
+ Vary: "Cookie",
7
+ }
8
8
 
9
- export {
10
- cacheControl
11
- };
9
+ export { cacheControl }
@@ -1,52 +1,42 @@
1
- import {
2
- AuthError,
3
- ERROR_RESPONSE,
4
- throwAuthError
5
- } from "./chunk-FJUDBLCP.js";
6
- import {
7
- OAuthAccessToken,
8
- OAuthAccessTokenErrorResponse,
9
- OAuthAccessTokenResponse
10
- } from "./chunk-HMRKN75I.js";
1
+ import { AuthError, ERROR_RESPONSE, throwAuthError } from "./chunk-FJUDBLCP.js"
2
+ import { OAuthAccessToken, OAuthAccessTokenErrorResponse, OAuthAccessTokenResponse } from "./chunk-HMRKN75I.js"
11
3
 
12
4
  // src/actions/callback/access-token.ts
13
5
  var createAccessToken = async (oauthConfig, redirectURI, code, codeVerifier) => {
14
- const parsed = OAuthAccessToken.safeParse({ ...oauthConfig, redirectURI, code, codeVerifier });
15
- if (!parsed.success) {
16
- throw new AuthError(ERROR_RESPONSE.ACCESS_TOKEN.INVALID_REQUEST, "Invalid OAuth configuration");
17
- }
18
- const { accessToken, clientId, clientSecret, code: codeParsed, redirectURI: redirectParsed } = parsed.data;
19
- try {
20
- const response = await fetch(accessToken, {
21
- method: "POST",
22
- headers: {
23
- Accept: "application/json",
24
- "Content-Type": "application/x-www-form-urlencoded"
25
- },
26
- body: new URLSearchParams({
27
- client_id: clientId,
28
- client_secret: clientSecret,
29
- code: codeParsed,
30
- redirect_uri: redirectParsed,
31
- grant_type: "authorization_code",
32
- code_verifier: codeVerifier
33
- }).toString()
34
- });
35
- const json = await response.json();
36
- const token = OAuthAccessTokenResponse.safeParse(json);
37
- if (!token.success) {
38
- const { success, data } = OAuthAccessTokenErrorResponse.safeParse(json);
39
- if (!success) {
40
- throw new AuthError(ERROR_RESPONSE.ACCESS_TOKEN.INVALID_GRANT, "Invalid access token response format");
41
- }
42
- throw new AuthError(data.error, data?.error_description ?? "Failed to retrieve access token");
6
+ const parsed = OAuthAccessToken.safeParse({ ...oauthConfig, redirectURI, code, codeVerifier })
7
+ if (!parsed.success) {
8
+ throw new AuthError(ERROR_RESPONSE.ACCESS_TOKEN.INVALID_REQUEST, "Invalid OAuth configuration")
43
9
  }
44
- return token.data;
45
- } catch (error) {
46
- throw throwAuthError(error, "Failed to create access token");
47
- }
48
- };
10
+ const { accessToken, clientId, clientSecret, code: codeParsed, redirectURI: redirectParsed } = parsed.data
11
+ try {
12
+ const response = await fetch(accessToken, {
13
+ method: "POST",
14
+ headers: {
15
+ Accept: "application/json",
16
+ "Content-Type": "application/x-www-form-urlencoded",
17
+ },
18
+ body: new URLSearchParams({
19
+ client_id: clientId,
20
+ client_secret: clientSecret,
21
+ code: codeParsed,
22
+ redirect_uri: redirectParsed,
23
+ grant_type: "authorization_code",
24
+ code_verifier: codeVerifier,
25
+ }).toString(),
26
+ })
27
+ const json = await response.json()
28
+ const token = OAuthAccessTokenResponse.safeParse(json)
29
+ if (!token.success) {
30
+ const { success, data } = OAuthAccessTokenErrorResponse.safeParse(json)
31
+ if (!success) {
32
+ throw new AuthError(ERROR_RESPONSE.ACCESS_TOKEN.INVALID_GRANT, "Invalid access token response format")
33
+ }
34
+ throw new AuthError(data.error, data?.error_description ?? "Failed to retrieve access token")
35
+ }
36
+ return token.data
37
+ } catch (error) {
38
+ throw throwAuthError(error, "Failed to create access token")
39
+ }
40
+ }
49
41
 
50
- export {
51
- createAccessToken
52
- };
42
+ export { createAccessToken }
@@ -0,0 +1,25 @@
1
+ import { createDerivedSalt } from "./chunk-GZU3RBTB.js"
2
+ import { AuthError } from "./chunk-FJUDBLCP.js"
3
+
4
+ // src/jose.ts
5
+ import "dotenv/config"
6
+ import { createJWT, createJWS, createDeriveKey } from "@aura-stack/jose"
7
+ var createJoseInstance = (secret) => {
8
+ secret ?? (secret = process.env.AURA_AUTH_SECRET)
9
+ if (!secret) {
10
+ throw new AuthError("JOSE_INIT_ERROR", "AURA_AUTH_SECRET environment variable is not set and no secret was provided.")
11
+ }
12
+ const salt = process.env.AURA_AUTH_SALT ?? createDerivedSalt(secret)
13
+ const { derivedKey: derivedSessionKey } = createDeriveKey(secret, salt, "session")
14
+ const { derivedKey: derivedCsrfTokenKey } = createDeriveKey(secret, salt, "csrfToken")
15
+ const { decodeJWT, encodeJWT } = createJWT(derivedSessionKey)
16
+ const { signJWS, verifyJWS } = createJWS(derivedCsrfTokenKey)
17
+ return {
18
+ decodeJWT,
19
+ encodeJWT,
20
+ signJWS,
21
+ verifyJWS,
22
+ }
23
+ }
24
+
25
+ export { createJoseInstance }
@@ -1,61 +1,44 @@
1
- import {
2
- figma
3
- } from "./chunk-FKRDCWBF.js";
4
- import {
5
- github
6
- } from "./chunk-IKHPGFCW.js";
7
- import {
8
- gitlab
9
- } from "./chunk-KRNOMBXQ.js";
10
- import {
11
- spotify
12
- } from "./chunk-E3OXBRYF.js";
13
- import {
14
- x
15
- } from "./chunk-42XB3YCW.js";
16
- import {
17
- bitbucket
18
- } from "./chunk-FIPU4MLT.js";
19
- import {
20
- discord
21
- } from "./chunk-EBPE35JT.js";
1
+ import { figma } from "./chunk-FKRDCWBF.js"
2
+ import { github } from "./chunk-IKHPGFCW.js"
3
+ import { gitlab } from "./chunk-KRNOMBXQ.js"
4
+ import { spotify } from "./chunk-E3OXBRYF.js"
5
+ import { x } from "./chunk-42XB3YCW.js"
6
+ import { bitbucket } from "./chunk-FIPU4MLT.js"
7
+ import { discord } from "./chunk-EBPE35JT.js"
22
8
 
23
9
  // src/oauth/index.ts
24
10
  var builtInOAuthProviders = {
25
- github,
26
- bitbucket,
27
- figma,
28
- discord,
29
- gitlab,
30
- spotify,
31
- x
32
- };
11
+ github,
12
+ bitbucket,
13
+ figma,
14
+ discord,
15
+ gitlab,
16
+ spotify,
17
+ x,
18
+ }
33
19
  var defineOAuthEnvironment = (oauth) => {
34
- const env = process.env;
35
- return {
36
- clientId: env[`AURA_AUTH_${oauth.toUpperCase()}_CLIENT_ID`],
37
- clientSecret: env[`AURA_AUTH_${oauth.toUpperCase()}_CLIENT_SECRET`]
38
- };
39
- };
40
- var defineOAuthProviderConfig = (config) => {
41
- if (typeof config === "string") {
42
- const definition = defineOAuthEnvironment(config);
43
- const oauthConfig = builtInOAuthProviders[config];
20
+ const env = process.env
44
21
  return {
45
- ...oauthConfig,
46
- ...definition
47
- };
48
- }
49
- return config;
50
- };
22
+ clientId: env[`AURA_AUTH_${oauth.toUpperCase()}_CLIENT_ID`],
23
+ clientSecret: env[`AURA_AUTH_${oauth.toUpperCase()}_CLIENT_SECRET`],
24
+ }
25
+ }
26
+ var defineOAuthProviderConfig = (config) => {
27
+ if (typeof config === "string") {
28
+ const definition = defineOAuthEnvironment(config)
29
+ const oauthConfig = builtInOAuthProviders[config]
30
+ return {
31
+ ...oauthConfig,
32
+ ...definition,
33
+ }
34
+ }
35
+ return config
36
+ }
51
37
  var createBuiltInOAuthProviders = (oauth = []) => {
52
- return oauth.reduce((previous, config) => {
53
- const oauthConfig = defineOAuthProviderConfig(config);
54
- return { ...previous, [oauthConfig.id]: oauthConfig };
55
- }, {});
56
- };
38
+ return oauth.reduce((previous, config) => {
39
+ const oauthConfig = defineOAuthProviderConfig(config)
40
+ return { ...previous, [oauthConfig.id]: oauthConfig }
41
+ }, {})
42
+ }
57
43
 
58
- export {
59
- builtInOAuthProviders,
60
- createBuiltInOAuthProviders
61
- };
44
+ export { builtInOAuthProviders, createBuiltInOAuthProviders }
@@ -1,37 +1,27 @@
1
- import {
2
- expireCookie,
3
- getCookie,
4
- secureCookieOptions
5
- } from "./chunk-ZV4BH47P.js";
6
- import {
7
- cacheControl
8
- } from "./chunk-STHEPPUZ.js";
9
- import {
10
- toISOString
11
- } from "./chunk-256KIVJL.js";
1
+ import { expireCookie, getCookie, secureCookieOptions } from "./chunk-ZV4BH47P.js"
2
+ import { cacheControl } from "./chunk-STHEPPUZ.js"
3
+ import { toISOString } from "./chunk-256KIVJL.js"
12
4
 
13
5
  // src/actions/session/session.ts
14
- import { createEndpoint } from "@aura-stack/router";
6
+ import { createEndpoint } from "@aura-stack/router"
15
7
  var sessionAction = createEndpoint("GET", "/session", async (ctx) => {
16
- const {
17
- request,
18
- context: { cookies, jose, trustedProxyHeaders }
19
- } = ctx;
20
- const cookieOptions = secureCookieOptions(request, cookies, trustedProxyHeaders);
21
- try {
22
- const session = getCookie(request, "sessionToken", cookieOptions);
23
- const decoded = await jose.decodeJWT(session);
24
- const { exp, iat, jti, nbf, ...user } = decoded;
25
- const headers = new Headers(cacheControl);
26
- return Response.json({ user, expires: toISOString(exp * 1e3) }, { headers });
27
- } catch {
28
- const headers = new Headers(cacheControl);
29
- const sessionCookie = expireCookie("sessionToken", cookieOptions);
30
- headers.set("Set-Cookie", sessionCookie);
31
- return Response.json({ authenticated: false, message: "Unauthorized" }, { status: 401, headers });
32
- }
33
- });
8
+ const {
9
+ request,
10
+ context: { cookies, jose, trustedProxyHeaders },
11
+ } = ctx
12
+ const cookieOptions = secureCookieOptions(request, cookies, trustedProxyHeaders)
13
+ try {
14
+ const session = getCookie(request, "sessionToken", cookieOptions)
15
+ const decoded = await jose.decodeJWT(session)
16
+ const { exp, iat, jti, nbf, ...user } = decoded
17
+ const headers = new Headers(cacheControl)
18
+ return Response.json({ user, expires: toISOString(exp * 1e3) }, { headers })
19
+ } catch {
20
+ const headers = new Headers(cacheControl)
21
+ const sessionCookie = expireCookie("sessionToken", cookieOptions)
22
+ headers.set("Set-Cookie", sessionCookie)
23
+ return Response.json({ authenticated: false, message: "Unauthorized" }, { status: 401, headers })
24
+ }
25
+ })
34
26
 
35
- export {
36
- sessionAction
37
- };
27
+ export { sessionAction }