@aura-stack/auth 0.1.0 → 0.2.0-rc.1
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.d.ts +5 -5
- package/dist/@types/router.d.d.ts +5 -5
- package/dist/@types/utility.d.ts +1 -5
- package/dist/actions/callback/access-token.cjs +95 -74
- package/dist/actions/callback/access-token.d.ts +7 -7
- package/dist/actions/callback/access-token.js +5 -3
- package/dist/actions/callback/callback.cjs +171 -249
- package/dist/actions/callback/callback.d.ts +6 -6
- package/dist/actions/callback/callback.js +10 -10
- package/dist/actions/callback/userinfo.cjs +81 -57
- package/dist/actions/callback/userinfo.d.ts +5 -5
- package/dist/actions/callback/userinfo.js +7 -5
- package/dist/actions/csrfToken/csrfToken.cjs +36 -105
- package/dist/actions/csrfToken/csrfToken.js +6 -6
- package/dist/actions/index.cjs +309 -444
- package/dist/actions/index.d.ts +5 -5
- package/dist/actions/index.js +19 -19
- package/dist/actions/session/session.cjs +25 -109
- package/dist/actions/session/session.js +4 -5
- package/dist/actions/signIn/authorization.cjs +96 -87
- package/dist/actions/signIn/authorization.d.ts +5 -5
- package/dist/actions/signIn/authorization.js +5 -5
- package/dist/actions/signIn/signIn.cjs +133 -242
- package/dist/actions/signIn/signIn.d.ts +6 -6
- package/dist/actions/signIn/signIn.js +8 -9
- package/dist/actions/signOut/signOut.cjs +136 -282
- package/dist/actions/signOut/signOut.js +8 -9
- package/dist/assert.cjs +5 -0
- package/dist/assert.d.ts +10 -1
- package/dist/assert.js +3 -1
- package/dist/chunk-3EUWD5BB.js +63 -0
- package/dist/chunk-6R2YZ4AC.js +22 -0
- package/dist/chunk-A3N4PVAT.js +70 -0
- package/dist/chunk-B737EUJV.js +22 -0
- package/dist/{chunk-256KIVJL.js → chunk-CXLATHS5.js} +53 -9
- package/dist/{chunk-6SM22VVJ.js → chunk-EIL2FPSS.js} +5 -1
- package/dist/{chunk-VFTYH33W.js → chunk-EMKJA2GJ.js} +36 -8
- package/dist/{chunk-UJJ7R56J.js → chunk-GA2SMTJO.js} +16 -10
- package/dist/chunk-HP34YGGJ.js +22 -0
- package/dist/chunk-HT4YLL7N.js +35 -0
- package/dist/{chunk-EBPE35JT.js → chunk-IUYZQTJV.js} +0 -1
- package/dist/{chunk-RLT4RFKV.js → chunk-IVET23KF.js} +21 -8
- package/dist/{chunk-XXJKNKGQ.js → chunk-JVFTCTTE.js} +9 -13
- package/dist/chunk-KSWLO5ZU.js +102 -0
- package/dist/{chunk-GZU3RBTB.js → chunk-N2APGLXA.js} +19 -10
- package/dist/{chunk-CAKJT3KS.js → chunk-N4SX7TZT.js} +21 -17
- package/dist/chunk-RRLIF4PQ.js +55 -0
- package/dist/chunk-TLE4PXY3.js +39 -0
- package/dist/chunk-W6LG7BFW.js +197 -0
- package/dist/{chunk-HMRKN75I.js → chunk-YRCB5FLE.js} +14 -9
- package/dist/chunk-ZNCZVF6U.js +14 -0
- package/dist/cookie.cjs +140 -99
- package/dist/cookie.d.ts +35 -44
- package/dist/cookie.js +10 -17
- package/dist/errors.cjs +85 -0
- package/dist/errors.d.ts +49 -0
- package/dist/errors.js +18 -0
- package/dist/{index-DpfbvTZ_.d.ts → index-DkaLJFn8.d.ts} +192 -61
- package/dist/index.cjs +543 -443
- package/dist/index.d.ts +6 -6
- package/dist/index.js +42 -28
- package/dist/jose.cjs +25 -14
- package/dist/jose.d.ts +4 -1
- package/dist/jose.js +5 -4
- package/dist/oauth/bitbucket.d.ts +5 -5
- package/dist/oauth/discord.cjs +0 -1
- package/dist/oauth/discord.d.ts +5 -5
- package/dist/oauth/discord.js +1 -1
- package/dist/oauth/figma.d.ts +5 -5
- package/dist/oauth/github.d.ts +5 -5
- package/dist/oauth/gitlab.d.ts +5 -5
- package/dist/oauth/index.cjs +176 -6
- package/dist/oauth/index.d.ts +5 -5
- package/dist/oauth/index.js +19 -4
- package/dist/oauth/mailchimp.cjs +46 -0
- package/dist/oauth/mailchimp.d.ts +7 -0
- package/dist/oauth/mailchimp.js +6 -0
- package/dist/oauth/pinterest.cjs +46 -0
- package/dist/oauth/pinterest.d.ts +7 -0
- package/dist/oauth/pinterest.js +6 -0
- package/dist/oauth/spotify.d.ts +5 -5
- package/dist/oauth/strava.cjs +46 -0
- package/dist/oauth/strava.d.ts +7 -0
- package/dist/oauth/strava.js +6 -0
- package/dist/oauth/x.d.ts +5 -5
- package/dist/{response.cjs → request.cjs} +14 -10
- package/dist/request.d.ts +13 -0
- package/dist/request.js +6 -0
- package/dist/schemas.cjs +43 -37
- package/dist/schemas.d.ts +67 -64
- package/dist/schemas.js +3 -1
- package/dist/secure.cjs +32 -24
- package/dist/secure.d.ts +5 -5
- package/dist/secure.js +4 -3
- package/dist/utils.cjs +90 -15
- package/dist/utils.d.ts +11 -2
- package/dist/utils.js +8 -4
- package/package.json +8 -7
- package/dist/chunk-FJUDBLCP.js +0 -59
- package/dist/chunk-HGJ4TXY4.js +0 -137
- package/dist/chunk-JAPMIE6S.js +0 -10
- package/dist/chunk-LLR722CL.js +0 -96
- package/dist/chunk-SJPDVKUS.js +0 -112
- package/dist/chunk-SMQO5WD7.js +0 -30
- package/dist/chunk-UTDLUEEG.js +0 -31
- package/dist/chunk-ZV4BH47P.js +0 -154
- package/dist/error.cjs +0 -88
- package/dist/error.d.ts +0 -62
- package/dist/error.js +0 -16
- package/dist/response.d.ts +0 -10
- package/dist/response.js +0 -6
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createAuthorizationURL,
|
|
3
|
+
createRedirectTo,
|
|
4
|
+
createRedirectURI
|
|
5
|
+
} from "./chunk-N4SX7TZT.js";
|
|
6
|
+
import {
|
|
7
|
+
cacheControl
|
|
8
|
+
} from "./chunk-STHEPPUZ.js";
|
|
9
|
+
import {
|
|
10
|
+
createPKCE,
|
|
11
|
+
generateSecure
|
|
12
|
+
} from "./chunk-N2APGLXA.js";
|
|
13
|
+
|
|
14
|
+
// src/actions/signIn/signIn.ts
|
|
15
|
+
import { z } from "zod";
|
|
16
|
+
import { createEndpoint, createEndpointConfig, HeadersBuilder } from "@aura-stack/router";
|
|
17
|
+
var signInConfig = (oauth) => {
|
|
18
|
+
return createEndpointConfig("/signIn/:oauth", {
|
|
19
|
+
schemas: {
|
|
20
|
+
params: z.object({
|
|
21
|
+
oauth: z.enum(
|
|
22
|
+
Object.keys(oauth),
|
|
23
|
+
"The OAuth provider is not supported or invalid."
|
|
24
|
+
)
|
|
25
|
+
}),
|
|
26
|
+
searchParams: z.object({
|
|
27
|
+
redirectTo: z.string().optional()
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
var signInAction = (oauth) => {
|
|
33
|
+
return createEndpoint(
|
|
34
|
+
"GET",
|
|
35
|
+
"/signIn/:oauth",
|
|
36
|
+
async (ctx) => {
|
|
37
|
+
const {
|
|
38
|
+
request,
|
|
39
|
+
params: { oauth: oauth2 },
|
|
40
|
+
searchParams: { redirectTo },
|
|
41
|
+
context: { oauth: providers, cookies, trustedProxyHeaders, basePath }
|
|
42
|
+
} = ctx;
|
|
43
|
+
const state = generateSecure();
|
|
44
|
+
const redirectURI = createRedirectURI(request, oauth2, basePath, trustedProxyHeaders);
|
|
45
|
+
const redirectToValue = createRedirectTo(request, redirectTo, trustedProxyHeaders);
|
|
46
|
+
const { codeVerifier, codeChallenge, method } = await createPKCE();
|
|
47
|
+
const authorization = createAuthorizationURL(providers[oauth2], redirectURI, state, codeChallenge, method);
|
|
48
|
+
const headers = new HeadersBuilder(cacheControl).setHeader("Location", authorization).setCookie(cookies.state.name, state, cookies.state.attributes).setCookie(cookies.redirectURI.name, redirectURI, cookies.redirectURI.attributes).setCookie(cookies.redirectTo.name, redirectToValue, cookies.redirectTo.attributes).setCookie(cookies.codeVerifier.name, codeVerifier, cookies.codeVerifier.attributes).toHeaders();
|
|
49
|
+
return Response.json(
|
|
50
|
+
{ oauth: oauth2 },
|
|
51
|
+
{
|
|
52
|
+
status: 302,
|
|
53
|
+
headers
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
},
|
|
57
|
+
signInConfig(oauth)
|
|
58
|
+
);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export {
|
|
62
|
+
signInAction
|
|
63
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// src/oauth/strava.ts
|
|
2
|
+
var strava = {
|
|
3
|
+
id: "strava",
|
|
4
|
+
name: "Strava",
|
|
5
|
+
authorizeURL: "https://www.strava.com/oauth/authorize",
|
|
6
|
+
accessToken: "https://www.strava.com/oauth/token",
|
|
7
|
+
userInfo: "https://www.strava.com/api/v3/athlete",
|
|
8
|
+
scope: "read",
|
|
9
|
+
responseType: "code",
|
|
10
|
+
profile(profile) {
|
|
11
|
+
return {
|
|
12
|
+
sub: profile.id.toString(),
|
|
13
|
+
name: `${profile.firstname} ${profile.lastname}`,
|
|
14
|
+
image: profile.profile,
|
|
15
|
+
email: ""
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export {
|
|
21
|
+
strava
|
|
22
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createRedirectTo
|
|
3
|
+
} from "./chunk-N4SX7TZT.js";
|
|
4
|
+
import {
|
|
5
|
+
expiredCookieAttributes
|
|
6
|
+
} from "./chunk-W6LG7BFW.js";
|
|
7
|
+
import {
|
|
8
|
+
cacheControl
|
|
9
|
+
} from "./chunk-STHEPPUZ.js";
|
|
10
|
+
import {
|
|
11
|
+
verifyCSRF
|
|
12
|
+
} from "./chunk-N2APGLXA.js";
|
|
13
|
+
import {
|
|
14
|
+
getNormalizedOriginPath
|
|
15
|
+
} from "./chunk-CXLATHS5.js";
|
|
16
|
+
import {
|
|
17
|
+
AuthSecurityError
|
|
18
|
+
} from "./chunk-RRLIF4PQ.js";
|
|
19
|
+
|
|
20
|
+
// src/actions/signOut/signOut.ts
|
|
21
|
+
import { z } from "zod";
|
|
22
|
+
import { createEndpoint, createEndpointConfig, HeadersBuilder, statusCode } from "@aura-stack/router";
|
|
23
|
+
var config = createEndpointConfig({
|
|
24
|
+
schemas: {
|
|
25
|
+
searchParams: z.object({
|
|
26
|
+
token_type_hint: z.literal("session_token"),
|
|
27
|
+
redirectTo: z.string().optional()
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
var signOutAction = createEndpoint(
|
|
32
|
+
"POST",
|
|
33
|
+
"/signOut",
|
|
34
|
+
async (ctx) => {
|
|
35
|
+
const {
|
|
36
|
+
request,
|
|
37
|
+
headers,
|
|
38
|
+
searchParams: { redirectTo },
|
|
39
|
+
context: { jose, cookies }
|
|
40
|
+
} = ctx;
|
|
41
|
+
const session = headers.getCookie(cookies.sessionToken.name);
|
|
42
|
+
const csrfToken = headers.getCookie(cookies.csrfToken.name);
|
|
43
|
+
const header = headers.getHeader("X-CSRF-Token");
|
|
44
|
+
if (!session) {
|
|
45
|
+
throw new AuthSecurityError("SESSION_TOKEN_MISSING", "The sessionToken is missing.");
|
|
46
|
+
}
|
|
47
|
+
if (!csrfToken) {
|
|
48
|
+
throw new AuthSecurityError("CSRF_TOKEN_MISSING", "The CSRF token is missing.");
|
|
49
|
+
}
|
|
50
|
+
if (!header) {
|
|
51
|
+
throw new AuthSecurityError("CSRF_TOKEN_MISSING", "The CSRF header is missing.");
|
|
52
|
+
}
|
|
53
|
+
await verifyCSRF(jose, csrfToken, header);
|
|
54
|
+
await jose.decodeJWT(session);
|
|
55
|
+
const normalizedOriginPath = getNormalizedOriginPath(request.url);
|
|
56
|
+
const location = createRedirectTo(
|
|
57
|
+
new Request(normalizedOriginPath, {
|
|
58
|
+
headers: headers.toHeaders()
|
|
59
|
+
}),
|
|
60
|
+
redirectTo
|
|
61
|
+
);
|
|
62
|
+
const headersList = new HeadersBuilder(cacheControl).setHeader("Location", location).setCookie(cookies.csrfToken.name, "", expiredCookieAttributes).setCookie(cookies.sessionToken.name, "", expiredCookieAttributes).toHeaders();
|
|
63
|
+
return Response.json({ message: "Signed out successfully" }, { status: statusCode.ACCEPTED, headers: headersList });
|
|
64
|
+
},
|
|
65
|
+
config
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
export {
|
|
69
|
+
signOutAction
|
|
70
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// src/oauth/mailchimp.ts
|
|
2
|
+
var mailchimp = {
|
|
3
|
+
id: "mailchimp",
|
|
4
|
+
name: "Mailchimp",
|
|
5
|
+
authorizeURL: "https://login.mailchimp.com/oauth2/authorize",
|
|
6
|
+
accessToken: "https://login.mailchimp.com/oauth2/token",
|
|
7
|
+
userInfo: "https://login.mailchimp.com/oauth2/metadata",
|
|
8
|
+
scope: "",
|
|
9
|
+
responseType: "code",
|
|
10
|
+
profile(profile) {
|
|
11
|
+
return {
|
|
12
|
+
sub: profile.user_id,
|
|
13
|
+
name: profile.accountname,
|
|
14
|
+
email: profile.login.login_email,
|
|
15
|
+
image: null
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export {
|
|
21
|
+
mailchimp
|
|
22
|
+
};
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
isAuthInternalError,
|
|
3
|
+
isAuthSecurityError,
|
|
4
|
+
isOAuthProtocolError
|
|
5
|
+
} from "./chunk-RRLIF4PQ.js";
|
|
4
6
|
|
|
5
7
|
// src/utils.ts
|
|
6
|
-
import { isRouterError } from "@aura-stack/router";
|
|
8
|
+
import { isInvalidZodSchemaError, isRouterError } from "@aura-stack/router";
|
|
7
9
|
var toSnakeCase = (str) => {
|
|
8
10
|
return str.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2").toLowerCase().replace(/^_+/, "");
|
|
9
11
|
};
|
|
@@ -64,13 +66,35 @@ var isValidRelativePath = (path) => {
|
|
|
64
66
|
var onErrorHandler = (error) => {
|
|
65
67
|
if (isRouterError(error)) {
|
|
66
68
|
const { message, status, statusText } = error;
|
|
67
|
-
return Response.json({
|
|
69
|
+
return Response.json({ type: "ROUTER_ERROR", code: "ROUTER_INTERNAL_ERROR", message }, { status, statusText });
|
|
68
70
|
}
|
|
69
|
-
if (
|
|
70
|
-
|
|
71
|
-
return Response.json({ error: type, error_description: message }, { status: 400 });
|
|
71
|
+
if (isInvalidZodSchemaError(error)) {
|
|
72
|
+
return Response.json({ type: "ROUTER_ERROR", code: "INVALID_REQUEST", message: error.errors }, { status: 422 });
|
|
72
73
|
}
|
|
73
|
-
|
|
74
|
+
if (isOAuthProtocolError(error)) {
|
|
75
|
+
const { error: errorCode, message, type, errorURI } = error;
|
|
76
|
+
return Response.json(
|
|
77
|
+
{
|
|
78
|
+
type,
|
|
79
|
+
error: errorCode,
|
|
80
|
+
error_description: message,
|
|
81
|
+
error_uri: errorURI
|
|
82
|
+
},
|
|
83
|
+
{ status: 400 }
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
if (isAuthInternalError(error) || isAuthSecurityError(error)) {
|
|
87
|
+
const { type, code, message } = error;
|
|
88
|
+
return Response.json(
|
|
89
|
+
{
|
|
90
|
+
type,
|
|
91
|
+
code,
|
|
92
|
+
message
|
|
93
|
+
},
|
|
94
|
+
{ status: 400 }
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
return Response.json({ type: "SERVER_ERROR", code: "server_error", message: "An unexpected error occurred" }, { status: 500 });
|
|
74
98
|
};
|
|
75
99
|
var getNormalizedOriginPath = (path) => {
|
|
76
100
|
try {
|
|
@@ -85,6 +109,24 @@ var getNormalizedOriginPath = (path) => {
|
|
|
85
109
|
var toISOString = (date) => {
|
|
86
110
|
return new Date(date).toISOString();
|
|
87
111
|
};
|
|
112
|
+
var useSecureCookies = (request, trustedProxyHeaders) => {
|
|
113
|
+
return trustedProxyHeaders ? request.url.startsWith("https://") || request.headers.get("X-Forwarded-Proto") === "https" || (request.headers.get("Forwarded")?.includes("proto=https") ?? false) : request.url.startsWith("https://");
|
|
114
|
+
};
|
|
115
|
+
var formatZodError = (error) => {
|
|
116
|
+
if (!error.issues || error.issues.length === 0) {
|
|
117
|
+
return {};
|
|
118
|
+
}
|
|
119
|
+
return error.issues.reduce((previous, issue) => {
|
|
120
|
+
const key = issue.path.join(".");
|
|
121
|
+
return {
|
|
122
|
+
...previous,
|
|
123
|
+
[key]: {
|
|
124
|
+
code: issue.code,
|
|
125
|
+
message: issue.message
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
}, {});
|
|
129
|
+
};
|
|
88
130
|
|
|
89
131
|
export {
|
|
90
132
|
toSnakeCase,
|
|
@@ -95,5 +137,7 @@ export {
|
|
|
95
137
|
isValidRelativePath,
|
|
96
138
|
onErrorHandler,
|
|
97
139
|
getNormalizedOriginPath,
|
|
98
|
-
toISOString
|
|
140
|
+
toISOString,
|
|
141
|
+
useSecureCookies,
|
|
142
|
+
formatZodError
|
|
99
143
|
};
|
|
@@ -10,9 +10,13 @@ var isValidURL = (value) => {
|
|
|
10
10
|
const regex = /^https?:\/\/(?:[a-zA-Z0-9._-]+|localhost|\[[0-9a-fA-F:]+\])(?::\d{1,5})?(?:\/[a-zA-Z0-9._~!$&'()*+,;=:@-]*)*\/?$/;
|
|
11
11
|
return regex.test(value);
|
|
12
12
|
};
|
|
13
|
+
var isJWTPayloadWithToken = (payload) => {
|
|
14
|
+
return typeof payload === "object" && payload !== null && "token" in payload && typeof payload?.token === "string";
|
|
15
|
+
};
|
|
13
16
|
|
|
14
17
|
export {
|
|
15
18
|
isFalsy,
|
|
16
19
|
isRequest,
|
|
17
|
-
isValidURL
|
|
20
|
+
isValidURL,
|
|
21
|
+
isJWTPayloadWithToken
|
|
18
22
|
};
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {
|
|
2
|
+
x
|
|
3
|
+
} from "./chunk-42XB3YCW.js";
|
|
1
4
|
import {
|
|
2
5
|
figma
|
|
3
6
|
} from "./chunk-FKRDCWBF.js";
|
|
@@ -7,18 +10,33 @@ import {
|
|
|
7
10
|
import {
|
|
8
11
|
gitlab
|
|
9
12
|
} from "./chunk-KRNOMBXQ.js";
|
|
13
|
+
import {
|
|
14
|
+
mailchimp
|
|
15
|
+
} from "./chunk-B737EUJV.js";
|
|
16
|
+
import {
|
|
17
|
+
pinterest
|
|
18
|
+
} from "./chunk-HP34YGGJ.js";
|
|
10
19
|
import {
|
|
11
20
|
spotify
|
|
12
21
|
} from "./chunk-E3OXBRYF.js";
|
|
13
22
|
import {
|
|
14
|
-
|
|
15
|
-
} from "./chunk-
|
|
23
|
+
strava
|
|
24
|
+
} from "./chunk-6R2YZ4AC.js";
|
|
16
25
|
import {
|
|
17
26
|
bitbucket
|
|
18
27
|
} from "./chunk-FIPU4MLT.js";
|
|
19
28
|
import {
|
|
20
29
|
discord
|
|
21
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-IUYZQTJV.js";
|
|
31
|
+
import {
|
|
32
|
+
formatZodError
|
|
33
|
+
} from "./chunk-CXLATHS5.js";
|
|
34
|
+
import {
|
|
35
|
+
AuthInternalError
|
|
36
|
+
} from "./chunk-RRLIF4PQ.js";
|
|
37
|
+
import {
|
|
38
|
+
OAuthEnvSchema
|
|
39
|
+
} from "./chunk-YRCB5FLE.js";
|
|
22
40
|
|
|
23
41
|
// src/oauth/index.ts
|
|
24
42
|
var builtInOAuthProviders = {
|
|
@@ -28,14 +46,24 @@ var builtInOAuthProviders = {
|
|
|
28
46
|
discord,
|
|
29
47
|
gitlab,
|
|
30
48
|
spotify,
|
|
31
|
-
x
|
|
49
|
+
x,
|
|
50
|
+
strava,
|
|
51
|
+
mailchimp,
|
|
52
|
+
pinterest
|
|
32
53
|
};
|
|
33
54
|
var defineOAuthEnvironment = (oauth) => {
|
|
34
55
|
const env = process.env;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
56
|
+
const clientIdSuffix = `${oauth.toUpperCase()}_CLIENT_ID`;
|
|
57
|
+
const clientSecretSuffix = `${oauth.toUpperCase()}_CLIENT_SECRET`;
|
|
58
|
+
const loadEnvs = OAuthEnvSchema.safeParse({
|
|
59
|
+
clientId: env[`AURA_AUTH_${clientIdSuffix}`] ?? env[`AUTH_${clientIdSuffix}`] ?? env[`${clientIdSuffix}`],
|
|
60
|
+
clientSecret: env[`AURA_AUTH_${clientSecretSuffix}`] ?? env[`AUTH_${clientSecretSuffix}`] ?? env[`${clientSecretSuffix}`]
|
|
61
|
+
});
|
|
62
|
+
if (!loadEnvs.success) {
|
|
63
|
+
const msg = JSON.stringify(formatZodError(loadEnvs.error), null, 2);
|
|
64
|
+
throw new AuthInternalError("INVALID_ENVIRONMENT_CONFIGURATION", msg);
|
|
65
|
+
}
|
|
66
|
+
return loadEnvs.data;
|
|
39
67
|
};
|
|
40
68
|
var defineOAuthProviderConfig = (config) => {
|
|
41
69
|
if (typeof config === "string") {
|
|
@@ -1,23 +1,29 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
formatZodError
|
|
3
|
+
} from "./chunk-CXLATHS5.js";
|
|
4
|
+
import {
|
|
5
|
+
AuthInternalError,
|
|
6
|
+
OAuthProtocolError
|
|
7
|
+
} from "./chunk-RRLIF4PQ.js";
|
|
8
|
+
import {
|
|
9
|
+
fetchAsync
|
|
10
|
+
} from "./chunk-ZNCZVF6U.js";
|
|
6
11
|
import {
|
|
7
12
|
OAuthAccessToken,
|
|
8
13
|
OAuthAccessTokenErrorResponse,
|
|
9
14
|
OAuthAccessTokenResponse
|
|
10
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-YRCB5FLE.js";
|
|
11
16
|
|
|
12
17
|
// src/actions/callback/access-token.ts
|
|
13
18
|
var createAccessToken = async (oauthConfig, redirectURI, code, codeVerifier) => {
|
|
14
19
|
const parsed = OAuthAccessToken.safeParse({ ...oauthConfig, redirectURI, code, codeVerifier });
|
|
15
20
|
if (!parsed.success) {
|
|
16
|
-
|
|
21
|
+
const msg = JSON.stringify(formatZodError(parsed.error), null, 2);
|
|
22
|
+
throw new AuthInternalError("INVALID_OAUTH_CONFIGURATION", msg);
|
|
17
23
|
}
|
|
18
24
|
const { accessToken, clientId, clientSecret, code: codeParsed, redirectURI: redirectParsed } = parsed.data;
|
|
19
25
|
try {
|
|
20
|
-
const response = await
|
|
26
|
+
const response = await fetchAsync(accessToken, {
|
|
21
27
|
method: "POST",
|
|
22
28
|
headers: {
|
|
23
29
|
Accept: "application/json",
|
|
@@ -37,13 +43,13 @@ var createAccessToken = async (oauthConfig, redirectURI, code, codeVerifier) =>
|
|
|
37
43
|
if (!token.success) {
|
|
38
44
|
const { success, data } = OAuthAccessTokenErrorResponse.safeParse(json);
|
|
39
45
|
if (!success) {
|
|
40
|
-
throw new
|
|
46
|
+
throw new OAuthProtocolError("INVALID_REQUEST", "Invalid access token response format");
|
|
41
47
|
}
|
|
42
|
-
throw new
|
|
48
|
+
throw new OAuthProtocolError(data.error, data?.error_description ?? "Failed to retrieve access token");
|
|
43
49
|
}
|
|
44
50
|
return token.data;
|
|
45
51
|
} catch (error) {
|
|
46
|
-
throw
|
|
52
|
+
throw error;
|
|
47
53
|
}
|
|
48
54
|
};
|
|
49
55
|
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// src/oauth/pinterest.ts
|
|
2
|
+
var pinterest = {
|
|
3
|
+
id: "pinterest",
|
|
4
|
+
name: "Pinterest",
|
|
5
|
+
authorizeURL: "https://api.pinterest.com/oauth/",
|
|
6
|
+
accessToken: "https://api.pinterest.com/v5/oauth/token",
|
|
7
|
+
userInfo: "https://api.pinterest.com/v5/user_account",
|
|
8
|
+
scope: "user_accounts:read",
|
|
9
|
+
responseType: "code",
|
|
10
|
+
profile(profile) {
|
|
11
|
+
return {
|
|
12
|
+
sub: profile.id,
|
|
13
|
+
name: profile.username,
|
|
14
|
+
email: null,
|
|
15
|
+
image: profile.profile_image
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export {
|
|
21
|
+
pinterest
|
|
22
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getCookie,
|
|
3
|
+
setCookie
|
|
4
|
+
} from "./chunk-W6LG7BFW.js";
|
|
5
|
+
import {
|
|
6
|
+
cacheControl
|
|
7
|
+
} from "./chunk-STHEPPUZ.js";
|
|
8
|
+
import {
|
|
9
|
+
createCSRF
|
|
10
|
+
} from "./chunk-N2APGLXA.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 }
|
|
25
|
+
} = ctx;
|
|
26
|
+
const token = getCSRFToken(request, cookies.csrfToken.name);
|
|
27
|
+
const csrfToken = await createCSRF(jose, token);
|
|
28
|
+
const headers = new Headers(cacheControl);
|
|
29
|
+
headers.append("Set-Cookie", setCookie(cookies.csrfToken.name, csrfToken, cookies.csrfToken.attributes));
|
|
30
|
+
return Response.json({ csrfToken }, { headers });
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
export {
|
|
34
|
+
csrfTokenAction
|
|
35
|
+
};
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import {
|
|
2
2
|
generateSecure
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-N2APGLXA.js";
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
OAuthProtocolError,
|
|
6
|
+
isNativeError,
|
|
7
|
+
isOAuthProtocolError
|
|
8
|
+
} from "./chunk-RRLIF4PQ.js";
|
|
9
|
+
import {
|
|
10
|
+
fetchAsync
|
|
11
|
+
} from "./chunk-ZNCZVF6U.js";
|
|
8
12
|
import {
|
|
9
13
|
OAuthErrorResponse
|
|
10
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-YRCB5FLE.js";
|
|
11
15
|
|
|
12
16
|
// src/actions/callback/userinfo.ts
|
|
13
17
|
var getDefaultUserInfo = (profile) => {
|
|
@@ -22,7 +26,7 @@ var getDefaultUserInfo = (profile) => {
|
|
|
22
26
|
var getUserInfo = async (oauthConfig, accessToken) => {
|
|
23
27
|
const userinfoEndpoint = oauthConfig.userInfo;
|
|
24
28
|
try {
|
|
25
|
-
const response = await
|
|
29
|
+
const response = await fetchAsync(userinfoEndpoint, {
|
|
26
30
|
method: "GET",
|
|
27
31
|
headers: {
|
|
28
32
|
Accept: "application/json",
|
|
@@ -32,11 +36,20 @@ var getUserInfo = async (oauthConfig, accessToken) => {
|
|
|
32
36
|
const json = await response.json();
|
|
33
37
|
const { success, data } = OAuthErrorResponse.safeParse(json);
|
|
34
38
|
if (success) {
|
|
35
|
-
throw new
|
|
39
|
+
throw new OAuthProtocolError(
|
|
40
|
+
data.error,
|
|
41
|
+
data?.error_description ?? "An error occurred while fetching user information."
|
|
42
|
+
);
|
|
36
43
|
}
|
|
37
44
|
return oauthConfig?.profile ? oauthConfig.profile(json) : getDefaultUserInfo(json);
|
|
38
45
|
} catch (error) {
|
|
39
|
-
|
|
46
|
+
if (isOAuthProtocolError(error)) {
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
if (isNativeError(error)) {
|
|
50
|
+
throw new OAuthProtocolError("invalid_request", error.message, "", { cause: error });
|
|
51
|
+
}
|
|
52
|
+
throw new OAuthProtocolError("invalid_request", "Failed to fetch user information.", "", { cause: error });
|
|
40
53
|
}
|
|
41
54
|
};
|
|
42
55
|
|
|
@@ -1,33 +1,29 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
getCookie
|
|
4
|
-
|
|
5
|
-
} from "./chunk-ZV4BH47P.js";
|
|
2
|
+
expiredCookieAttributes,
|
|
3
|
+
getCookie
|
|
4
|
+
} from "./chunk-W6LG7BFW.js";
|
|
6
5
|
import {
|
|
7
6
|
cacheControl
|
|
8
7
|
} from "./chunk-STHEPPUZ.js";
|
|
9
8
|
import {
|
|
10
9
|
toISOString
|
|
11
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-CXLATHS5.js";
|
|
12
11
|
|
|
13
12
|
// src/actions/session/session.ts
|
|
14
|
-
import { createEndpoint } from "@aura-stack/router";
|
|
13
|
+
import { createEndpoint, HeadersBuilder } from "@aura-stack/router";
|
|
15
14
|
var sessionAction = createEndpoint("GET", "/session", async (ctx) => {
|
|
16
15
|
const {
|
|
17
16
|
request,
|
|
18
|
-
context: {
|
|
17
|
+
context: { jose, cookies }
|
|
19
18
|
} = ctx;
|
|
20
|
-
const cookieOptions = secureCookieOptions(request, cookies, trustedProxyHeaders);
|
|
21
19
|
try {
|
|
22
|
-
const session = getCookie(request,
|
|
20
|
+
const session = getCookie(request, cookies.sessionToken.name);
|
|
23
21
|
const decoded = await jose.decodeJWT(session);
|
|
24
22
|
const { exp, iat, jti, nbf, ...user } = decoded;
|
|
25
23
|
const headers = new Headers(cacheControl);
|
|
26
24
|
return Response.json({ user, expires: toISOString(exp * 1e3) }, { headers });
|
|
27
|
-
} catch {
|
|
28
|
-
const headers = new
|
|
29
|
-
const sessionCookie = expireCookie("sessionToken", cookieOptions);
|
|
30
|
-
headers.set("Set-Cookie", sessionCookie);
|
|
25
|
+
} catch (error) {
|
|
26
|
+
const headers = new HeadersBuilder(cacheControl).setCookie(cookies.sessionToken.name, "", expiredCookieAttributes).toHeaders();
|
|
31
27
|
return Response.json({ authenticated: false, message: "Unauthorized" }, { status: 401, headers });
|
|
32
28
|
}
|
|
33
29
|
});
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createAccessToken
|
|
3
|
+
} from "./chunk-GA2SMTJO.js";
|
|
4
|
+
import {
|
|
5
|
+
getUserInfo
|
|
6
|
+
} from "./chunk-IVET23KF.js";
|
|
7
|
+
import {
|
|
8
|
+
createSessionCookie,
|
|
9
|
+
expiredCookieAttributes,
|
|
10
|
+
getCookie
|
|
11
|
+
} from "./chunk-W6LG7BFW.js";
|
|
12
|
+
import {
|
|
13
|
+
cacheControl
|
|
14
|
+
} from "./chunk-STHEPPUZ.js";
|
|
15
|
+
import {
|
|
16
|
+
createCSRF
|
|
17
|
+
} from "./chunk-N2APGLXA.js";
|
|
18
|
+
import {
|
|
19
|
+
equals,
|
|
20
|
+
isValidRelativePath,
|
|
21
|
+
sanitizeURL
|
|
22
|
+
} from "./chunk-CXLATHS5.js";
|
|
23
|
+
import {
|
|
24
|
+
AuthSecurityError,
|
|
25
|
+
OAuthProtocolError
|
|
26
|
+
} from "./chunk-RRLIF4PQ.js";
|
|
27
|
+
import {
|
|
28
|
+
OAuthAuthorizationErrorResponse
|
|
29
|
+
} from "./chunk-YRCB5FLE.js";
|
|
30
|
+
|
|
31
|
+
// src/actions/callback/callback.ts
|
|
32
|
+
import { z } from "zod";
|
|
33
|
+
import { createEndpoint, createEndpointConfig, HeadersBuilder } from "@aura-stack/router";
|
|
34
|
+
var callbackConfig = (oauth) => {
|
|
35
|
+
return createEndpointConfig("/callback/:oauth", {
|
|
36
|
+
schemas: {
|
|
37
|
+
params: z.object({
|
|
38
|
+
oauth: z.enum(
|
|
39
|
+
Object.keys(oauth),
|
|
40
|
+
"The OAuth provider is not supported or invalid."
|
|
41
|
+
)
|
|
42
|
+
}),
|
|
43
|
+
searchParams: z.object({
|
|
44
|
+
code: z.string("Missing code parameter in the OAuth authorization response."),
|
|
45
|
+
state: z.string("Missing state parameter in the OAuth authorization response.")
|
|
46
|
+
})
|
|
47
|
+
},
|
|
48
|
+
middlewares: [
|
|
49
|
+
(ctx) => {
|
|
50
|
+
const response = OAuthAuthorizationErrorResponse.safeParse(ctx.searchParams);
|
|
51
|
+
if (response.success) {
|
|
52
|
+
const { error, error_description } = response.data;
|
|
53
|
+
throw new OAuthProtocolError(error, error_description ?? "OAuth Authorization Error");
|
|
54
|
+
}
|
|
55
|
+
return ctx;
|
|
56
|
+
}
|
|
57
|
+
]
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
var callbackAction = (oauth) => {
|
|
61
|
+
return createEndpoint(
|
|
62
|
+
"GET",
|
|
63
|
+
"/callback/:oauth",
|
|
64
|
+
async (ctx) => {
|
|
65
|
+
const {
|
|
66
|
+
request,
|
|
67
|
+
params: { oauth: oauth2 },
|
|
68
|
+
searchParams: { code, state },
|
|
69
|
+
context: { oauth: providers, cookies, jose }
|
|
70
|
+
} = ctx;
|
|
71
|
+
const oauthConfig = providers[oauth2];
|
|
72
|
+
const cookieState = getCookie(request, cookies.state.name);
|
|
73
|
+
const cookieRedirectTo = getCookie(request, cookies.redirectTo.name);
|
|
74
|
+
const cookieRedirectURI = getCookie(request, cookies.redirectURI.name);
|
|
75
|
+
const codeVerifier = getCookie(request, cookies.codeVerifier.name);
|
|
76
|
+
if (!equals(cookieState, state)) {
|
|
77
|
+
throw new AuthSecurityError(
|
|
78
|
+
"MISMATCHING_STATE",
|
|
79
|
+
"The provided state passed in the OAuth response does not match the stored state."
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
const accessToken = await createAccessToken(oauthConfig, cookieRedirectURI, code, codeVerifier);
|
|
83
|
+
const sanitized = sanitizeURL(cookieRedirectTo);
|
|
84
|
+
if (!isValidRelativePath(sanitized)) {
|
|
85
|
+
throw new AuthSecurityError(
|
|
86
|
+
"POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED",
|
|
87
|
+
"Invalid redirect path. Potential open redirect attack detected."
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
const userInfo = await getUserInfo(oauthConfig, accessToken.access_token);
|
|
91
|
+
const sessionCookie = await createSessionCookie(jose, userInfo);
|
|
92
|
+
const csrfToken = await createCSRF(jose);
|
|
93
|
+
const headers = new HeadersBuilder(cacheControl).setHeader("Location", sanitized).setCookie(cookies.sessionToken.name, sessionCookie, cookies.sessionToken.attributes).setCookie(cookies.csrfToken.name, csrfToken, cookies.csrfToken.attributes).setCookie(cookies.state.name, "", expiredCookieAttributes).setCookie(cookies.redirectURI.name, "", expiredCookieAttributes).setCookie(cookies.redirectTo.name, "", expiredCookieAttributes).setCookie(cookies.codeVerifier.name, "", expiredCookieAttributes).toHeaders();
|
|
94
|
+
return Response.json({ oauth: oauth2 }, { status: 302, headers });
|
|
95
|
+
},
|
|
96
|
+
callbackConfig(oauth)
|
|
97
|
+
);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
export {
|
|
101
|
+
callbackAction
|
|
102
|
+
};
|