@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.
- package/dist/@types/index.cjs +15 -15
- package/dist/@types/index.d.ts +31 -7
- package/dist/@types/index.js +1 -1
- package/dist/@types/router.d.cjs +1 -1
- package/dist/@types/router.d.d.ts +7 -7
- package/dist/@types/utility.cjs +15 -15
- package/dist/@types/utility.d.ts +6 -6
- package/dist/@types/utility.js +1 -1
- package/dist/actions/callback/access-token.cjs +143 -143
- package/dist/actions/callback/access-token.d.ts +20 -15
- package/dist/actions/callback/access-token.js +4 -8
- package/dist/actions/callback/callback.cjs +455 -437
- package/dist/actions/callback/callback.d.ts +12 -10
- package/dist/actions/callback/callback.js +12 -16
- package/dist/actions/callback/userinfo.cjs +134 -131
- package/dist/actions/callback/userinfo.d.ts +9 -9
- package/dist/actions/callback/userinfo.js +6 -10
- package/dist/actions/csrfToken/csrfToken.cjs +171 -162
- package/dist/actions/csrfToken/csrfToken.d.ts +3 -3
- package/dist/actions/csrfToken/csrfToken.js +8 -12
- package/dist/actions/index.cjs +773 -746
- package/dist/actions/index.d.ts +13 -13
- package/dist/actions/index.js +18 -34
- package/dist/actions/session/session.cjs +155 -149
- package/dist/actions/session/session.d.ts +3 -3
- package/dist/actions/session/session.js +7 -11
- package/dist/actions/signIn/authorization.cjs +249 -231
- package/dist/actions/signIn/authorization.d.ts +18 -12
- package/dist/actions/signIn/authorization.js +6 -16
- package/dist/actions/signIn/signIn.cjs +423 -396
- package/dist/actions/signIn/signIn.d.ts +10 -10
- package/dist/actions/signIn/signIn.js +10 -14
- package/dist/actions/signOut/signOut.cjs +440 -417
- package/dist/actions/signOut/signOut.d.ts +3 -3
- package/dist/actions/signOut/signOut.js +11 -15
- package/dist/assert.cjs +36 -35
- package/dist/assert.d.ts +4 -4
- package/dist/assert.js +2 -10
- package/dist/chunk-256KIVJL.js +96 -85
- package/dist/chunk-42XB3YCW.js +17 -19
- package/dist/chunk-6SM22VVJ.js +10 -13
- package/dist/chunk-CAKJT3KS.js +69 -84
- package/dist/chunk-E3OXBRYF.js +17 -19
- package/dist/chunk-EBPE35JT.js +26 -28
- package/dist/chunk-FIPU4MLT.js +16 -18
- package/dist/chunk-FJUDBLCP.js +43 -50
- package/dist/chunk-FKRDCWBF.js +17 -19
- package/dist/chunk-GZU3RBTB.js +40 -51
- package/dist/chunk-HGJ4TXY4.js +100 -132
- package/dist/chunk-HMRKN75I.js +63 -63
- package/dist/chunk-IKHPGFCW.js +9 -11
- package/dist/chunk-JAPMIE6S.js +5 -7
- package/dist/chunk-KRNOMBXQ.js +17 -19
- package/dist/chunk-LLR722CL.js +70 -91
- package/dist/chunk-RLT4RFKV.js +30 -39
- package/dist/chunk-SJPDVKUS.js +88 -107
- package/dist/chunk-SMQO5WD7.js +16 -26
- package/dist/chunk-STHEPPUZ.js +6 -8
- package/dist/chunk-UJJ7R56J.js +37 -47
- package/dist/chunk-UTDLUEEG.js +25 -0
- package/dist/chunk-VFTYH33W.js +37 -54
- package/dist/chunk-XXJKNKGQ.js +23 -33
- package/dist/chunk-ZV4BH47P.js +134 -132
- package/dist/cookie.cjs +175 -169
- package/dist/cookie.d.ts +51 -23
- package/dist/cookie.js +34 -34
- package/dist/error.cjs +75 -75
- package/dist/error.d.ts +30 -30
- package/dist/error.js +8 -15
- package/dist/headers.cjs +28 -28
- package/dist/headers.d.ts +2 -2
- package/dist/headers.js +2 -6
- package/dist/index-DpfbvTZ_.d.ts +298 -249
- package/dist/index.cjs +969 -933
- package/dist/index.d.ts +31 -10
- package/dist/index.js +50 -70
- package/dist/jose.cjs +67 -52
- package/dist/jose.d.ts +8 -8
- package/dist/jose.js +5 -9
- package/dist/oauth/bitbucket.cjs +38 -38
- package/dist/oauth/bitbucket.d.ts +7 -7
- package/dist/oauth/bitbucket.js +2 -6
- package/dist/oauth/discord.cjs +48 -48
- package/dist/oauth/discord.d.ts +7 -7
- package/dist/oauth/discord.js +2 -6
- package/dist/oauth/figma.cjs +39 -39
- package/dist/oauth/figma.d.ts +7 -7
- package/dist/oauth/figma.js +2 -6
- package/dist/oauth/github.cjs +31 -31
- package/dist/oauth/github.d.ts +7 -7
- package/dist/oauth/github.js +2 -6
- package/dist/oauth/gitlab.cjs +39 -39
- package/dist/oauth/gitlab.d.ts +7 -7
- package/dist/oauth/gitlab.js +2 -6
- package/dist/oauth/index.cjs +180 -180
- package/dist/oauth/index.d.ts +26 -7
- package/dist/oauth/index.js +9 -36
- package/dist/oauth/spotify.cjs +39 -39
- package/dist/oauth/spotify.d.ts +7 -7
- package/dist/oauth/spotify.js +2 -6
- package/dist/oauth/x.cjs +39 -39
- package/dist/oauth/x.d.ts +7 -7
- package/dist/oauth/x.js +2 -6
- package/dist/response.cjs +27 -27
- package/dist/response.d.ts +2 -2
- package/dist/response.js +2 -6
- package/dist/schemas.cjs +91 -91
- package/dist/schemas.d.ts +126 -93
- package/dist/schemas.js +18 -18
- package/dist/secure.cjs +98 -95
- package/dist/secure.d.ts +17 -17
- package/dist/secure.js +4 -18
- package/dist/utils.cjs +132 -119
- package/dist/utils.d.ts +26 -11
- package/dist/utils.js +21 -21
- package/package.json +1 -1
- package/dist/chunk-X7M4CQTN.js +0 -25
package/dist/chunk-SJPDVKUS.js
CHANGED
|
@@ -1,112 +1,93 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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 }
|
package/dist/chunk-SMQO5WD7.js
CHANGED
|
@@ -1,30 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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 }
|
package/dist/chunk-STHEPPUZ.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
// src/headers.ts
|
|
2
2
|
var cacheControl = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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 }
|
package/dist/chunk-UJJ7R56J.js
CHANGED
|
@@ -1,52 +1,42 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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 }
|
package/dist/chunk-VFTYH33W.js
CHANGED
|
@@ -1,61 +1,44 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
} from "./chunk-
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
11
|
+
github,
|
|
12
|
+
bitbucket,
|
|
13
|
+
figma,
|
|
14
|
+
discord,
|
|
15
|
+
gitlab,
|
|
16
|
+
spotify,
|
|
17
|
+
x,
|
|
18
|
+
}
|
|
33
19
|
var defineOAuthEnvironment = (oauth) => {
|
|
34
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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 }
|
package/dist/chunk-XXJKNKGQ.js
CHANGED
|
@@ -1,37 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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 }
|