@aura-stack/auth 0.4.0-rc.4 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/@types/index.d.ts +4 -3
- package/dist/@types/router.d.cjs +0 -17
- package/dist/@types/router.d.d.ts +3 -2
- package/dist/@types/router.d.js +0 -1
- package/dist/actions/callback/access-token.cjs +40 -25
- package/dist/actions/callback/access-token.d.ts +4 -3
- package/dist/actions/callback/access-token.js +3 -4
- package/dist/actions/callback/callback.cjs +287 -77
- package/dist/actions/callback/callback.d.ts +5 -26
- package/dist/actions/callback/callback.js +13 -10
- package/dist/actions/callback/userinfo.cjs +68 -7
- package/dist/actions/callback/userinfo.d.ts +4 -3
- package/dist/actions/callback/userinfo.js +8 -6
- package/dist/actions/csrfToken/csrfToken.cjs +63 -4
- package/dist/actions/csrfToken/csrfToken.d.ts +1 -3
- package/dist/actions/csrfToken/csrfToken.js +8 -6
- package/dist/actions/index.cjs +400 -175
- package/dist/actions/index.d.ts +3 -2
- package/dist/actions/index.js +21 -19
- package/dist/actions/session/session.cjs +40 -11
- package/dist/actions/session/session.d.ts +1 -3
- package/dist/actions/session/session.js +4 -4
- package/dist/actions/signIn/authorization.cjs +171 -132
- package/dist/actions/signIn/authorization.d.ts +21 -11
- package/dist/actions/signIn/authorization.js +8 -6
- package/dist/actions/signIn/signIn.cjs +220 -113
- package/dist/actions/signIn/signIn.d.ts +5 -25
- package/dist/actions/signIn/signIn.js +9 -7
- package/dist/actions/signOut/signOut.cjs +268 -119
- package/dist/actions/signOut/signOut.d.ts +1 -9
- package/dist/actions/signOut/signOut.js +10 -8
- package/dist/assert.cjs +117 -5
- package/dist/assert.d.ts +22 -3
- package/dist/assert.js +17 -3
- package/dist/chunk-4EKY7655.js +123 -0
- package/dist/chunk-4MYWAOLG.js +31 -0
- package/dist/chunk-4YHJ4IEQ.js +25 -0
- package/dist/chunk-54CZPKR4.js +25 -0
- package/dist/chunk-5LZ7TOM3.js +25 -0
- package/dist/{chunk-W6LG7BFW.js → chunk-5W4BRQYG.js} +24 -20
- package/dist/chunk-6MXFPFR3.js +143 -0
- package/dist/{chunk-3EUWD5BB.js → chunk-7QF22LHP.js} +13 -9
- package/dist/chunk-ALG3GIV4.js +95 -0
- package/dist/chunk-E6G5YCI6.js +25 -0
- package/dist/chunk-EBAMFRB7.js +34 -0
- package/dist/chunk-EEE7UM5T.js +25 -0
- package/dist/{chunk-TLE4PXY3.js → chunk-FRJFWTOY.js} +38 -7
- package/dist/chunk-FW4W3REU.js +25 -0
- package/dist/{chunk-HT4YLL7N.js → chunk-ICAZ4OVS.js} +10 -8
- package/dist/chunk-IPKO6UQN.js +25 -0
- package/dist/{chunk-YRCB5FLE.js → chunk-KJBAQZX2.js} +13 -0
- package/dist/chunk-KMMAZFSJ.js +25 -0
- package/dist/chunk-LDU7A2JE.js +25 -0
- package/dist/{chunk-N2APGLXA.js → chunk-NUDITUKX.js} +18 -16
- package/dist/chunk-OVHNRULD.js +33 -0
- package/dist/{chunk-JVFTCTTE.js → chunk-PHFH2MGS.js} +12 -9
- package/dist/chunk-QQVSRXGX.js +149 -0
- package/dist/chunk-TM5IPSNF.js +113 -0
- package/dist/{chunk-GA2SMTJO.js → chunk-TZB6MUXN.js} +33 -13
- package/dist/chunk-VNCNJKS2.js +267 -0
- package/dist/{chunk-IVET23KF.js → chunk-XGLBNXL4.js} +31 -14
- package/dist/chunk-XUP6KKNG.js +106 -0
- package/dist/cookie.cjs +24 -20
- package/dist/cookie.d.ts +4 -3
- package/dist/cookie.js +1 -1
- package/dist/env.cjs +56 -0
- package/dist/env.d.ts +7 -0
- package/dist/env.js +6 -0
- package/dist/errors.d.ts +4 -3
- package/dist/headers.cjs +28 -2
- package/dist/headers.d.ts +25 -1
- package/dist/headers.js +9 -3
- package/dist/{index-DkaLJFn8.d.ts → index-CSyIJmCM.d.ts} +373 -45
- package/dist/index.cjs +1128 -483
- package/dist/index.d.ts +6 -10
- package/dist/index.js +83 -42
- package/dist/jose.cjs +62 -25
- package/dist/jose.d.ts +7 -5
- package/dist/jose.js +8 -6
- package/dist/logger.cjs +292 -0
- package/dist/logger.d.ts +8 -0
- package/dist/logger.js +8 -0
- package/dist/oauth/bitbucket.cjs +19 -15
- package/dist/oauth/bitbucket.d.ts +3 -2
- package/dist/oauth/bitbucket.js +1 -1
- package/dist/oauth/discord.cjs +27 -24
- package/dist/oauth/discord.d.ts +3 -2
- package/dist/oauth/discord.js +1 -1
- package/dist/oauth/figma.cjs +19 -16
- package/dist/oauth/figma.d.ts +3 -2
- package/dist/oauth/figma.js +1 -1
- package/dist/oauth/github.cjs +19 -8
- package/dist/oauth/github.d.ts +3 -2
- package/dist/oauth/github.js +1 -1
- package/dist/oauth/gitlab.cjs +19 -16
- package/dist/oauth/gitlab.d.ts +3 -2
- package/dist/oauth/gitlab.js +1 -1
- package/dist/oauth/index.cjs +266 -166
- package/dist/oauth/index.d.ts +3 -2
- package/dist/oauth/index.js +22 -21
- package/dist/oauth/mailchimp.cjs +19 -16
- package/dist/oauth/mailchimp.d.ts +3 -2
- package/dist/oauth/mailchimp.js +1 -1
- package/dist/oauth/pinterest.cjs +19 -16
- package/dist/oauth/pinterest.d.ts +3 -2
- package/dist/oauth/pinterest.js +1 -1
- package/dist/oauth/spotify.cjs +19 -16
- package/dist/oauth/spotify.d.ts +3 -2
- package/dist/oauth/spotify.js +1 -1
- package/dist/oauth/strava.cjs +19 -16
- package/dist/oauth/strava.d.ts +3 -2
- package/dist/oauth/strava.js +1 -1
- package/dist/oauth/x.cjs +19 -16
- package/dist/oauth/x.d.ts +3 -2
- package/dist/oauth/x.js +1 -1
- package/dist/schemas.cjs +16 -2
- package/dist/schemas.d.ts +17 -1
- package/dist/schemas.js +5 -3
- package/dist/secure.cjs +58 -16
- package/dist/secure.d.ts +4 -10
- package/dist/secure.js +5 -5
- package/dist/utils.cjs +94 -87
- package/dist/utils.d.ts +9 -39
- package/dist/utils.js +11 -9
- package/package.json +3 -4
- package/dist/chunk-42XB3YCW.js +0 -22
- package/dist/chunk-6R2YZ4AC.js +0 -22
- package/dist/chunk-A3N4PVAT.js +0 -70
- package/dist/chunk-B737EUJV.js +0 -22
- package/dist/chunk-CXLATHS5.js +0 -143
- package/dist/chunk-DIVDFNAP.js +0 -0
- package/dist/chunk-E3OXBRYF.js +0 -22
- package/dist/chunk-EIL2FPSS.js +0 -22
- package/dist/chunk-EMKJA2GJ.js +0 -89
- package/dist/chunk-FIPU4MLT.js +0 -21
- package/dist/chunk-FKRDCWBF.js +0 -22
- package/dist/chunk-HP34YGGJ.js +0 -22
- package/dist/chunk-IKHPGFCW.js +0 -14
- package/dist/chunk-IUYZQTJV.js +0 -30
- package/dist/chunk-KRNOMBXQ.js +0 -22
- package/dist/chunk-KSWLO5ZU.js +0 -102
- package/dist/chunk-N4SX7TZT.js +0 -96
- package/dist/chunk-STHEPPUZ.js +0 -11
package/dist/chunk-EMKJA2GJ.js
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
// src/oauth/bitbucket.ts
|
|
2
|
-
var bitbucket = {
|
|
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
|
-
|
|
19
|
-
export {
|
|
20
|
-
bitbucket
|
|
21
|
-
};
|
package/dist/chunk-FKRDCWBF.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
// src/oauth/figma.ts
|
|
2
|
-
var figma = {
|
|
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
|
-
|
|
20
|
-
export {
|
|
21
|
-
figma
|
|
22
|
-
};
|
package/dist/chunk-HP34YGGJ.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
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
|
-
};
|
package/dist/chunk-IKHPGFCW.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
// src/oauth/github.ts
|
|
2
|
-
var github = {
|
|
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
|
-
|
|
12
|
-
export {
|
|
13
|
-
github
|
|
14
|
-
};
|
package/dist/chunk-IUYZQTJV.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
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
|
-
};
|
package/dist/chunk-KRNOMBXQ.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
// src/oauth/gitlab.ts
|
|
2
|
-
var gitlab = {
|
|
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
|
-
|
|
20
|
-
export {
|
|
21
|
-
gitlab
|
|
22
|
-
};
|
package/dist/chunk-KSWLO5ZU.js
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
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
|
-
};
|
package/dist/chunk-N4SX7TZT.js
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
equals,
|
|
3
|
-
formatZodError,
|
|
4
|
-
getNormalizedOriginPath,
|
|
5
|
-
sanitizeURL,
|
|
6
|
-
toCastCase
|
|
7
|
-
} from "./chunk-CXLATHS5.js";
|
|
8
|
-
import {
|
|
9
|
-
isValidURL
|
|
10
|
-
} from "./chunk-EIL2FPSS.js";
|
|
11
|
-
import {
|
|
12
|
-
AuthInternalError,
|
|
13
|
-
AuthSecurityError,
|
|
14
|
-
isAuthSecurityError
|
|
15
|
-
} from "./chunk-RRLIF4PQ.js";
|
|
16
|
-
import {
|
|
17
|
-
OAuthAuthorization
|
|
18
|
-
} from "./chunk-YRCB5FLE.js";
|
|
19
|
-
|
|
20
|
-
// src/actions/signIn/authorization.ts
|
|
21
|
-
var createAuthorizationURL = (oauthConfig, redirectURI, state, codeChallenge, codeChallengeMethod) => {
|
|
22
|
-
const parsed = OAuthAuthorization.safeParse({ ...oauthConfig, redirectURI, state, codeChallenge, codeChallengeMethod });
|
|
23
|
-
if (!parsed.success) {
|
|
24
|
-
const msg = JSON.stringify(formatZodError(parsed.error), null, 2);
|
|
25
|
-
throw new AuthInternalError("INVALID_OAUTH_CONFIGURATION", msg);
|
|
26
|
-
}
|
|
27
|
-
const { authorizeURL, ...options } = parsed.data;
|
|
28
|
-
const { userInfo, accessToken, clientSecret, ...required } = options;
|
|
29
|
-
const searchParams = new URLSearchParams(toCastCase(required));
|
|
30
|
-
return `${authorizeURL}?${searchParams}`;
|
|
31
|
-
};
|
|
32
|
-
var getOriginURL = (request, trustedProxyHeaders) => {
|
|
33
|
-
const headers = request.headers;
|
|
34
|
-
if (trustedProxyHeaders) {
|
|
35
|
-
const protocol = headers.get("X-Forwarded-Proto") ?? headers.get("Forwarded")?.match(/proto=([^;]+)/i)?.[1] ?? "http";
|
|
36
|
-
const host = headers.get("X-Forwarded-Host") ?? headers.get("Host") ?? headers.get("Forwarded")?.match(/host=([^;]+)/i)?.[1] ?? null;
|
|
37
|
-
return new URL(`${protocol}://${host}${getNormalizedOriginPath(new URL(request.url).pathname)}`);
|
|
38
|
-
} else {
|
|
39
|
-
return new URL(getNormalizedOriginPath(request.url));
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
var createRedirectURI = (request, oauth, basePath, trustedProxyHeaders) => {
|
|
43
|
-
const url = getOriginURL(request, trustedProxyHeaders);
|
|
44
|
-
return `${url.origin}${basePath}/callback/${oauth}`;
|
|
45
|
-
};
|
|
46
|
-
var createRedirectTo = (request, redirectTo, trustedProxyHeaders) => {
|
|
47
|
-
try {
|
|
48
|
-
const headers = request.headers;
|
|
49
|
-
const origin = headers.get("Origin");
|
|
50
|
-
const referer = headers.get("Referer");
|
|
51
|
-
let hostedURL = getOriginURL(request, trustedProxyHeaders);
|
|
52
|
-
if (redirectTo) {
|
|
53
|
-
if (redirectTo.startsWith("/")) {
|
|
54
|
-
return sanitizeURL(redirectTo);
|
|
55
|
-
}
|
|
56
|
-
const redirectToURL = new URL(sanitizeURL(getNormalizedOriginPath(redirectTo)));
|
|
57
|
-
if (!isValidURL(redirectTo) || !equals(redirectToURL.origin, hostedURL.origin)) {
|
|
58
|
-
throw new AuthSecurityError(
|
|
59
|
-
"POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED",
|
|
60
|
-
"The redirectTo parameter does not match the hosted origin."
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
return sanitizeURL(redirectToURL.pathname);
|
|
64
|
-
}
|
|
65
|
-
if (referer) {
|
|
66
|
-
const refererURL = new URL(sanitizeURL(referer));
|
|
67
|
-
if (!isValidURL(referer) || !equals(refererURL.origin, hostedURL.origin)) {
|
|
68
|
-
throw new AuthSecurityError(
|
|
69
|
-
"POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED",
|
|
70
|
-
"The referer of the request does not match the hosted origin."
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
return sanitizeURL(refererURL.pathname);
|
|
74
|
-
}
|
|
75
|
-
if (origin) {
|
|
76
|
-
const originURL = new URL(sanitizeURL(getNormalizedOriginPath(origin)));
|
|
77
|
-
if (!isValidURL(origin) || !equals(originURL.origin, hostedURL.origin)) {
|
|
78
|
-
throw new AuthSecurityError("POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED", "Invalid origin (potential CSRF).");
|
|
79
|
-
}
|
|
80
|
-
return sanitizeURL(originURL.pathname);
|
|
81
|
-
}
|
|
82
|
-
return "/";
|
|
83
|
-
} catch (error) {
|
|
84
|
-
if (isAuthSecurityError(error)) {
|
|
85
|
-
throw error;
|
|
86
|
-
}
|
|
87
|
-
throw new AuthSecurityError("POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED", "Invalid origin (potential CSRF).");
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
export {
|
|
92
|
-
createAuthorizationURL,
|
|
93
|
-
getOriginURL,
|
|
94
|
-
createRedirectURI,
|
|
95
|
-
createRedirectTo
|
|
96
|
-
};
|