@aura-stack/auth 0.1.0-rc.9 → 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.cjs +15 -15
- package/dist/@types/index.d.ts +7 -31
- 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 +4 -8
- package/dist/@types/utility.js +1 -1
- package/dist/actions/callback/access-token.cjs +176 -155
- package/dist/actions/callback/access-token.d.ts +15 -20
- package/dist/actions/callback/access-token.js +10 -4
- package/dist/actions/callback/callback.cjs +394 -490
- package/dist/actions/callback/callback.d.ts +10 -12
- package/dist/actions/callback/callback.js +16 -12
- package/dist/actions/callback/userinfo.cjs +166 -145
- package/dist/actions/callback/userinfo.d.ts +9 -9
- package/dist/actions/callback/userinfo.js +12 -6
- package/dist/actions/csrfToken/csrfToken.cjs +112 -190
- package/dist/actions/csrfToken/csrfToken.d.ts +3 -3
- package/dist/actions/csrfToken/csrfToken.js +12 -8
- package/dist/actions/index.cjs +652 -814
- package/dist/actions/index.d.ts +13 -13
- package/dist/actions/index.js +34 -18
- package/dist/actions/session/session.cjs +86 -176
- package/dist/actions/session/session.d.ts +3 -3
- package/dist/actions/session/session.js +10 -7
- package/dist/actions/signIn/authorization.cjs +254 -263
- package/dist/actions/signIn/authorization.d.ts +12 -18
- package/dist/actions/signIn/authorization.js +16 -6
- package/dist/actions/signIn/signIn.cjs +320 -456
- package/dist/actions/signIn/signIn.d.ts +10 -10
- package/dist/actions/signIn/signIn.js +13 -10
- package/dist/actions/signOut/signOut.cjs +304 -473
- package/dist/actions/signOut/signOut.d.ts +3 -3
- package/dist/actions/signOut/signOut.js +14 -11
- package/dist/assert.cjs +40 -36
- package/dist/assert.d.ts +13 -4
- package/dist/assert.js +12 -2
- package/dist/chunk-3EUWD5BB.js +63 -0
- package/dist/chunk-42XB3YCW.js +19 -17
- package/dist/chunk-6R2YZ4AC.js +22 -0
- package/dist/chunk-A3N4PVAT.js +70 -0
- package/dist/chunk-B737EUJV.js +22 -0
- package/dist/chunk-CXLATHS5.js +143 -0
- package/dist/chunk-E3OXBRYF.js +19 -17
- package/dist/chunk-EIL2FPSS.js +22 -0
- package/dist/chunk-EMKJA2GJ.js +89 -0
- package/dist/chunk-FIPU4MLT.js +18 -16
- package/dist/chunk-FKRDCWBF.js +19 -17
- package/dist/chunk-GA2SMTJO.js +58 -0
- package/dist/chunk-HP34YGGJ.js +22 -0
- package/dist/chunk-HT4YLL7N.js +35 -0
- package/dist/chunk-IKHPGFCW.js +11 -9
- package/dist/chunk-IUYZQTJV.js +30 -0
- package/dist/chunk-IVET23KF.js +58 -0
- package/dist/chunk-JVFTCTTE.js +33 -0
- package/dist/chunk-KRNOMBXQ.js +19 -17
- package/dist/chunk-KSWLO5ZU.js +102 -0
- package/dist/chunk-N2APGLXA.js +71 -0
- package/dist/chunk-N4SX7TZT.js +96 -0
- package/dist/chunk-RRLIF4PQ.js +55 -0
- package/dist/chunk-STHEPPUZ.js +8 -6
- package/dist/chunk-TLE4PXY3.js +39 -0
- package/dist/chunk-W6LG7BFW.js +197 -0
- package/dist/chunk-YRCB5FLE.js +79 -0
- package/dist/chunk-ZNCZVF6U.js +14 -0
- package/dist/cookie.cjs +222 -187
- package/dist/cookie.d.ts +39 -76
- package/dist/cookie.js +27 -34
- package/dist/errors.cjs +85 -0
- package/dist/errors.d.ts +49 -0
- package/dist/errors.js +18 -0
- package/dist/headers.cjs +28 -28
- package/dist/headers.d.ts +2 -2
- package/dist/headers.js +6 -2
- package/dist/index-DkaLJFn8.d.ts +679 -0
- package/dist/index.cjs +1074 -1007
- package/dist/index.d.ts +10 -31
- package/dist/index.js +85 -51
- package/dist/jose.cjs +74 -66
- package/dist/jose.d.ts +11 -8
- package/dist/jose.js +10 -5
- package/dist/oauth/bitbucket.cjs +38 -38
- package/dist/oauth/bitbucket.d.ts +7 -7
- package/dist/oauth/bitbucket.js +6 -2
- package/dist/oauth/discord.cjs +47 -48
- package/dist/oauth/discord.d.ts +7 -7
- package/dist/oauth/discord.js +6 -2
- package/dist/oauth/figma.cjs +39 -39
- package/dist/oauth/figma.d.ts +7 -7
- package/dist/oauth/figma.js +6 -2
- package/dist/oauth/github.cjs +31 -31
- package/dist/oauth/github.d.ts +7 -7
- package/dist/oauth/github.js +6 -2
- package/dist/oauth/gitlab.cjs +39 -39
- package/dist/oauth/gitlab.d.ts +7 -7
- package/dist/oauth/gitlab.js +6 -2
- package/dist/oauth/index.cjs +350 -180
- package/dist/oauth/index.d.ts +7 -26
- package/dist/oauth/index.js +51 -9
- 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.cjs +39 -39
- package/dist/oauth/spotify.d.ts +7 -7
- package/dist/oauth/spotify.js +6 -2
- 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.cjs +39 -39
- package/dist/oauth/x.d.ts +7 -7
- package/dist/oauth/x.js +6 -2
- package/dist/request.cjs +38 -0
- package/dist/request.d.ts +13 -0
- package/dist/request.js +6 -0
- package/dist/schemas.cjs +103 -97
- package/dist/schemas.d.ts +96 -126
- package/dist/schemas.js +20 -18
- package/dist/secure.cjs +106 -101
- package/dist/secure.d.ts +17 -17
- package/dist/secure.js +19 -4
- package/dist/utils.cjs +197 -135
- package/dist/utils.d.ts +20 -26
- package/dist/utils.js +25 -21
- package/package.json +8 -7
- package/dist/chunk-256KIVJL.js +0 -110
- package/dist/chunk-6SM22VVJ.js +0 -15
- package/dist/chunk-CAKJT3KS.js +0 -77
- package/dist/chunk-EBPE35JT.js +0 -29
- package/dist/chunk-FJUDBLCP.js +0 -52
- package/dist/chunk-GZU3RBTB.js +0 -51
- package/dist/chunk-HGJ4TXY4.js +0 -105
- package/dist/chunk-HMRKN75I.js +0 -74
- package/dist/chunk-JAPMIE6S.js +0 -8
- package/dist/chunk-LLR722CL.js +0 -75
- package/dist/chunk-RLT4RFKV.js +0 -36
- package/dist/chunk-SJPDVKUS.js +0 -93
- package/dist/chunk-SMQO5WD7.js +0 -20
- package/dist/chunk-UJJ7R56J.js +0 -42
- package/dist/chunk-UTDLUEEG.js +0 -25
- package/dist/chunk-VFTYH33W.js +0 -44
- package/dist/chunk-XXJKNKGQ.js +0 -27
- package/dist/chunk-ZV4BH47P.js +0 -156
- package/dist/error.cjs +0 -88
- package/dist/error.d.ts +0 -62
- package/dist/error.js +0 -9
- package/dist/index-DpfbvTZ_.d.ts +0 -597
- package/dist/response.cjs +0 -34
- package/dist/response.d.ts +0 -10
- package/dist/response.js +0 -2
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import {
|
|
2
|
+
x
|
|
3
|
+
} from "./chunk-42XB3YCW.js";
|
|
4
|
+
import {
|
|
5
|
+
figma
|
|
6
|
+
} from "./chunk-FKRDCWBF.js";
|
|
7
|
+
import {
|
|
8
|
+
github
|
|
9
|
+
} from "./chunk-IKHPGFCW.js";
|
|
10
|
+
import {
|
|
11
|
+
gitlab
|
|
12
|
+
} from "./chunk-KRNOMBXQ.js";
|
|
13
|
+
import {
|
|
14
|
+
mailchimp
|
|
15
|
+
} from "./chunk-B737EUJV.js";
|
|
16
|
+
import {
|
|
17
|
+
pinterest
|
|
18
|
+
} from "./chunk-HP34YGGJ.js";
|
|
19
|
+
import {
|
|
20
|
+
spotify
|
|
21
|
+
} from "./chunk-E3OXBRYF.js";
|
|
22
|
+
import {
|
|
23
|
+
strava
|
|
24
|
+
} from "./chunk-6R2YZ4AC.js";
|
|
25
|
+
import {
|
|
26
|
+
bitbucket
|
|
27
|
+
} from "./chunk-FIPU4MLT.js";
|
|
28
|
+
import {
|
|
29
|
+
discord
|
|
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";
|
|
40
|
+
|
|
41
|
+
// src/oauth/index.ts
|
|
42
|
+
var builtInOAuthProviders = {
|
|
43
|
+
github,
|
|
44
|
+
bitbucket,
|
|
45
|
+
figma,
|
|
46
|
+
discord,
|
|
47
|
+
gitlab,
|
|
48
|
+
spotify,
|
|
49
|
+
x,
|
|
50
|
+
strava,
|
|
51
|
+
mailchimp,
|
|
52
|
+
pinterest
|
|
53
|
+
};
|
|
54
|
+
var defineOAuthEnvironment = (oauth) => {
|
|
55
|
+
const env = process.env;
|
|
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;
|
|
67
|
+
};
|
|
68
|
+
var defineOAuthProviderConfig = (config) => {
|
|
69
|
+
if (typeof config === "string") {
|
|
70
|
+
const definition = defineOAuthEnvironment(config);
|
|
71
|
+
const oauthConfig = builtInOAuthProviders[config];
|
|
72
|
+
return {
|
|
73
|
+
...oauthConfig,
|
|
74
|
+
...definition
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
return config;
|
|
78
|
+
};
|
|
79
|
+
var createBuiltInOAuthProviders = (oauth = []) => {
|
|
80
|
+
return oauth.reduce((previous, config) => {
|
|
81
|
+
const oauthConfig = defineOAuthProviderConfig(config);
|
|
82
|
+
return { ...previous, [oauthConfig.id]: oauthConfig };
|
|
83
|
+
}, {});
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export {
|
|
87
|
+
builtInOAuthProviders,
|
|
88
|
+
createBuiltInOAuthProviders
|
|
89
|
+
};
|
package/dist/chunk-FIPU4MLT.js
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
// src/oauth/bitbucket.ts
|
|
2
2
|
var bitbucket = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
3
|
+
id: "bitbucket",
|
|
4
|
+
name: "Bitbucket",
|
|
5
|
+
authorizeURL: "https://bitbucket.org/site/oauth2/authorize",
|
|
6
|
+
accessToken: "https://bitbucket.org/site/oauth2/access_token",
|
|
7
|
+
userInfo: "https://api.bitbucket.org/2.0/user",
|
|
8
|
+
scope: "account email",
|
|
9
|
+
responseType: "code",
|
|
10
|
+
profile(profile) {
|
|
11
|
+
return {
|
|
12
|
+
sub: profile.uuid ?? profile.account_id,
|
|
13
|
+
name: profile.display_name ?? profile.nickname,
|
|
14
|
+
image: profile.links.avatar.href
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
18
|
|
|
19
|
-
export {
|
|
19
|
+
export {
|
|
20
|
+
bitbucket
|
|
21
|
+
};
|
package/dist/chunk-FKRDCWBF.js
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
// src/oauth/figma.ts
|
|
2
2
|
var figma = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
3
|
+
id: "figma",
|
|
4
|
+
name: "Figma",
|
|
5
|
+
authorizeURL: "https://www.figma.com/oauth",
|
|
6
|
+
accessToken: "https://api.figma.com/v1/oauth/token",
|
|
7
|
+
userInfo: "https://api.figma.com/v1/me",
|
|
8
|
+
scope: "current_user:read",
|
|
9
|
+
responseType: "code",
|
|
10
|
+
profile(profile) {
|
|
11
|
+
return {
|
|
12
|
+
sub: profile.id,
|
|
13
|
+
name: profile.handle,
|
|
14
|
+
email: profile.email,
|
|
15
|
+
image: profile.img_url
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
19
|
|
|
20
|
-
export {
|
|
20
|
+
export {
|
|
21
|
+
figma
|
|
22
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import {
|
|
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";
|
|
11
|
+
import {
|
|
12
|
+
OAuthAccessToken,
|
|
13
|
+
OAuthAccessTokenErrorResponse,
|
|
14
|
+
OAuthAccessTokenResponse
|
|
15
|
+
} from "./chunk-YRCB5FLE.js";
|
|
16
|
+
|
|
17
|
+
// src/actions/callback/access-token.ts
|
|
18
|
+
var createAccessToken = async (oauthConfig, redirectURI, code, codeVerifier) => {
|
|
19
|
+
const parsed = OAuthAccessToken.safeParse({ ...oauthConfig, redirectURI, code, codeVerifier });
|
|
20
|
+
if (!parsed.success) {
|
|
21
|
+
const msg = JSON.stringify(formatZodError(parsed.error), null, 2);
|
|
22
|
+
throw new AuthInternalError("INVALID_OAUTH_CONFIGURATION", msg);
|
|
23
|
+
}
|
|
24
|
+
const { accessToken, clientId, clientSecret, code: codeParsed, redirectURI: redirectParsed } = parsed.data;
|
|
25
|
+
try {
|
|
26
|
+
const response = await fetchAsync(accessToken, {
|
|
27
|
+
method: "POST",
|
|
28
|
+
headers: {
|
|
29
|
+
Accept: "application/json",
|
|
30
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
31
|
+
},
|
|
32
|
+
body: new URLSearchParams({
|
|
33
|
+
client_id: clientId,
|
|
34
|
+
client_secret: clientSecret,
|
|
35
|
+
code: codeParsed,
|
|
36
|
+
redirect_uri: redirectParsed,
|
|
37
|
+
grant_type: "authorization_code",
|
|
38
|
+
code_verifier: codeVerifier
|
|
39
|
+
}).toString()
|
|
40
|
+
});
|
|
41
|
+
const json = await response.json();
|
|
42
|
+
const token = OAuthAccessTokenResponse.safeParse(json);
|
|
43
|
+
if (!token.success) {
|
|
44
|
+
const { success, data } = OAuthAccessTokenErrorResponse.safeParse(json);
|
|
45
|
+
if (!success) {
|
|
46
|
+
throw new OAuthProtocolError("INVALID_REQUEST", "Invalid access token response format");
|
|
47
|
+
}
|
|
48
|
+
throw new OAuthProtocolError(data.error, data?.error_description ?? "Failed to retrieve access token");
|
|
49
|
+
}
|
|
50
|
+
return token.data;
|
|
51
|
+
} catch (error) {
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export {
|
|
57
|
+
createAccessToken
|
|
58
|
+
};
|
|
@@ -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
|
+
};
|
package/dist/chunk-IKHPGFCW.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
// src/oauth/github.ts
|
|
2
2
|
var github = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
3
|
+
id: "github",
|
|
4
|
+
name: "GitHub",
|
|
5
|
+
authorizeURL: "https://github.com/login/oauth/authorize",
|
|
6
|
+
accessToken: "https://github.com/login/oauth/access_token",
|
|
7
|
+
userInfo: "https://api.github.com/user",
|
|
8
|
+
scope: "read:user user:email",
|
|
9
|
+
responseType: "code"
|
|
10
|
+
};
|
|
11
11
|
|
|
12
|
-
export {
|
|
12
|
+
export {
|
|
13
|
+
github
|
|
14
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// src/oauth/discord.ts
|
|
2
|
+
var discord = {
|
|
3
|
+
id: "discord",
|
|
4
|
+
name: "Discord",
|
|
5
|
+
authorizeURL: "https://discord.com/oauth2/authorize",
|
|
6
|
+
accessToken: "https://discord.com/api/oauth2/token",
|
|
7
|
+
userInfo: "https://discord.com/api/users/@me",
|
|
8
|
+
scope: "identify email",
|
|
9
|
+
responseType: "code",
|
|
10
|
+
profile(profile) {
|
|
11
|
+
let image = "";
|
|
12
|
+
if (profile.avatar === null) {
|
|
13
|
+
const index = profile.discriminator === "0" ? (BigInt(profile.id) >> 22n) % 6n : Number(profile.discriminator) % 5;
|
|
14
|
+
image = `https://cdn.discordapp.com/embed/avatars/${index}.png`;
|
|
15
|
+
} else {
|
|
16
|
+
const format = profile.avatar.startsWith("a_") ? "gif" : "png";
|
|
17
|
+
image = `https://cdn.discordapp.com/avatars/${profile.id}/${profile.avatar}.${format}`;
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
sub: profile.id,
|
|
21
|
+
name: profile.global_name ?? profile.username,
|
|
22
|
+
email: profile.email ?? "",
|
|
23
|
+
image
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export {
|
|
29
|
+
discord
|
|
30
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import {
|
|
2
|
+
generateSecure
|
|
3
|
+
} from "./chunk-N2APGLXA.js";
|
|
4
|
+
import {
|
|
5
|
+
OAuthProtocolError,
|
|
6
|
+
isNativeError,
|
|
7
|
+
isOAuthProtocolError
|
|
8
|
+
} from "./chunk-RRLIF4PQ.js";
|
|
9
|
+
import {
|
|
10
|
+
fetchAsync
|
|
11
|
+
} from "./chunk-ZNCZVF6U.js";
|
|
12
|
+
import {
|
|
13
|
+
OAuthErrorResponse
|
|
14
|
+
} from "./chunk-YRCB5FLE.js";
|
|
15
|
+
|
|
16
|
+
// src/actions/callback/userinfo.ts
|
|
17
|
+
var getDefaultUserInfo = (profile) => {
|
|
18
|
+
const sub = generateSecure(16);
|
|
19
|
+
return {
|
|
20
|
+
sub: profile?.id ?? profile?.sub ?? sub,
|
|
21
|
+
email: profile?.email,
|
|
22
|
+
name: profile?.name ?? profile?.username ?? profile?.nickname,
|
|
23
|
+
image: profile?.image ?? profile?.picture
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
var getUserInfo = async (oauthConfig, accessToken) => {
|
|
27
|
+
const userinfoEndpoint = oauthConfig.userInfo;
|
|
28
|
+
try {
|
|
29
|
+
const response = await fetchAsync(userinfoEndpoint, {
|
|
30
|
+
method: "GET",
|
|
31
|
+
headers: {
|
|
32
|
+
Accept: "application/json",
|
|
33
|
+
Authorization: `Bearer ${accessToken}`
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
const json = await response.json();
|
|
37
|
+
const { success, data } = OAuthErrorResponse.safeParse(json);
|
|
38
|
+
if (success) {
|
|
39
|
+
throw new OAuthProtocolError(
|
|
40
|
+
data.error,
|
|
41
|
+
data?.error_description ?? "An error occurred while fetching user information."
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
return oauthConfig?.profile ? oauthConfig.profile(json) : getDefaultUserInfo(json);
|
|
45
|
+
} catch (error) {
|
|
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 });
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export {
|
|
57
|
+
getUserInfo
|
|
58
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import {
|
|
2
|
+
expiredCookieAttributes,
|
|
3
|
+
getCookie
|
|
4
|
+
} from "./chunk-W6LG7BFW.js";
|
|
5
|
+
import {
|
|
6
|
+
cacheControl
|
|
7
|
+
} from "./chunk-STHEPPUZ.js";
|
|
8
|
+
import {
|
|
9
|
+
toISOString
|
|
10
|
+
} from "./chunk-CXLATHS5.js";
|
|
11
|
+
|
|
12
|
+
// src/actions/session/session.ts
|
|
13
|
+
import { createEndpoint, HeadersBuilder } from "@aura-stack/router";
|
|
14
|
+
var sessionAction = createEndpoint("GET", "/session", async (ctx) => {
|
|
15
|
+
const {
|
|
16
|
+
request,
|
|
17
|
+
context: { jose, cookies }
|
|
18
|
+
} = ctx;
|
|
19
|
+
try {
|
|
20
|
+
const session = getCookie(request, cookies.sessionToken.name);
|
|
21
|
+
const decoded = await jose.decodeJWT(session);
|
|
22
|
+
const { exp, iat, jti, nbf, ...user } = decoded;
|
|
23
|
+
const headers = new Headers(cacheControl);
|
|
24
|
+
return Response.json({ user, expires: toISOString(exp * 1e3) }, { headers });
|
|
25
|
+
} catch (error) {
|
|
26
|
+
const headers = new HeadersBuilder(cacheControl).setCookie(cookies.sessionToken.name, "", expiredCookieAttributes).toHeaders();
|
|
27
|
+
return Response.json({ authenticated: false, message: "Unauthorized" }, { status: 401, headers });
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export {
|
|
32
|
+
sessionAction
|
|
33
|
+
};
|
package/dist/chunk-KRNOMBXQ.js
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
// src/oauth/gitlab.ts
|
|
2
2
|
var gitlab = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
3
|
+
id: "gitlab",
|
|
4
|
+
name: "GitLab",
|
|
5
|
+
authorizeURL: "https://gitlab.com/oauth/authorize",
|
|
6
|
+
accessToken: "https://gitlab.com/oauth/token",
|
|
7
|
+
userInfo: "https://gitlab.com/api/v4/user",
|
|
8
|
+
scope: "read_user",
|
|
9
|
+
responseType: "code",
|
|
10
|
+
profile(profile) {
|
|
11
|
+
return {
|
|
12
|
+
sub: profile.id.toString(),
|
|
13
|
+
name: profile.name ?? profile.username,
|
|
14
|
+
email: profile.email,
|
|
15
|
+
avatar: profile.avatar_url
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
19
|
|
|
20
|
-
export {
|
|
20
|
+
export {
|
|
21
|
+
gitlab
|
|
22
|
+
};
|
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import {
|
|
2
|
+
equals
|
|
3
|
+
} from "./chunk-CXLATHS5.js";
|
|
4
|
+
import {
|
|
5
|
+
isJWTPayloadWithToken
|
|
6
|
+
} from "./chunk-EIL2FPSS.js";
|
|
7
|
+
import {
|
|
8
|
+
AuthSecurityError
|
|
9
|
+
} from "./chunk-RRLIF4PQ.js";
|
|
10
|
+
|
|
11
|
+
// src/secure.ts
|
|
12
|
+
import crypto from "crypto";
|
|
13
|
+
var generateSecure = (length = 32) => {
|
|
14
|
+
return crypto.randomBytes(length).toString("base64url");
|
|
15
|
+
};
|
|
16
|
+
var createHash = (data, base = "hex") => {
|
|
17
|
+
return crypto.createHash("sha256").update(data).digest().toString(base);
|
|
18
|
+
};
|
|
19
|
+
var createPKCE = async (verifier) => {
|
|
20
|
+
const codeVerifier = verifier ?? generateSecure(86);
|
|
21
|
+
const codeChallenge = createHash(codeVerifier, "base64url");
|
|
22
|
+
return { codeVerifier, codeChallenge, method: "S256" };
|
|
23
|
+
};
|
|
24
|
+
var createCSRF = async (jose, csrfCookie) => {
|
|
25
|
+
try {
|
|
26
|
+
const token = generateSecure(32);
|
|
27
|
+
if (csrfCookie) {
|
|
28
|
+
await jose.verifyJWS(csrfCookie);
|
|
29
|
+
return csrfCookie;
|
|
30
|
+
}
|
|
31
|
+
return jose.signJWS({ token });
|
|
32
|
+
} catch {
|
|
33
|
+
const token = generateSecure(32);
|
|
34
|
+
return jose.signJWS({ token });
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var verifyCSRF = async (jose, cookie, header) => {
|
|
38
|
+
try {
|
|
39
|
+
const cookiePayload = await jose.verifyJWS(cookie);
|
|
40
|
+
const headerPayload = await jose.verifyJWS(header);
|
|
41
|
+
if (!isJWTPayloadWithToken(cookiePayload)) {
|
|
42
|
+
throw new AuthSecurityError("CSRF_TOKEN_INVALID", "Cookie payload missing token field.");
|
|
43
|
+
}
|
|
44
|
+
if (!isJWTPayloadWithToken(headerPayload)) {
|
|
45
|
+
throw new AuthSecurityError("CSRF_TOKEN_INVALID", "Header payload missing token field.");
|
|
46
|
+
}
|
|
47
|
+
const cookieBuffer = Buffer.from(cookiePayload.token);
|
|
48
|
+
const headerBuffer = Buffer.from(headerPayload.token);
|
|
49
|
+
if (!equals(headerBuffer.length, cookieBuffer.length)) {
|
|
50
|
+
throw new AuthSecurityError("CSRF_TOKEN_INVALID", "The CSRF tokens do not match.");
|
|
51
|
+
}
|
|
52
|
+
if (!crypto.timingSafeEqual(cookieBuffer, headerBuffer)) {
|
|
53
|
+
throw new AuthSecurityError("CSRF_TOKEN_INVALID", "The CSRF tokens do not match.");
|
|
54
|
+
}
|
|
55
|
+
return true;
|
|
56
|
+
} catch {
|
|
57
|
+
throw new AuthSecurityError("CSRF_TOKEN_INVALID", "The CSRF tokens do not match.");
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
var createDerivedSalt = (secret) => {
|
|
61
|
+
return crypto.createHash("sha256").update(secret).update("aura-auth-salt").digest("hex");
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export {
|
|
65
|
+
generateSecure,
|
|
66
|
+
createHash,
|
|
67
|
+
createPKCE,
|
|
68
|
+
createCSRF,
|
|
69
|
+
verifyCSRF,
|
|
70
|
+
createDerivedSalt
|
|
71
|
+
};
|