@aura-stack/auth 0.4.0-rc.5 → 0.5.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 +8 -3
- package/dist/@types/router.d.cjs +0 -17
- package/dist/@types/router.d.d.ts +7 -2
- package/dist/@types/router.d.js +0 -1
- package/dist/actions/callback/access-token.cjs +130 -71
- package/dist/actions/callback/access-token.d.ts +9 -4
- package/dist/actions/callback/access-token.js +3 -4
- package/dist/actions/callback/callback.cjs +428 -152
- package/dist/actions/callback/callback.d.ts +11 -3
- package/dist/actions/callback/callback.js +12 -10
- package/dist/actions/callback/userinfo.cjs +159 -65
- package/dist/actions/callback/userinfo.d.ts +8 -3
- package/dist/actions/callback/userinfo.js +7 -6
- package/dist/actions/csrfToken/csrfToken.cjs +70 -19
- package/dist/actions/csrfToken/csrfToken.js +8 -7
- package/dist/actions/index.cjs +780 -348
- package/dist/actions/index.d.ts +6 -2
- package/dist/actions/index.js +23 -18
- package/dist/actions/session/session.cjs +107 -26
- package/dist/actions/session/session.js +7 -5
- package/dist/actions/signIn/authorization-url.cjs +288 -0
- package/dist/actions/signIn/authorization-url.d.ts +31 -0
- package/dist/actions/signIn/authorization-url.js +16 -0
- package/dist/actions/signIn/authorization.cjs +209 -211
- package/dist/actions/signIn/authorization.d.ts +32 -21
- package/dist/actions/signIn/authorization.js +12 -9
- package/dist/actions/signIn/signIn.cjs +470 -235
- package/dist/actions/signIn/signIn.d.ts +12 -3
- package/dist/actions/signIn/signIn.js +11 -8
- package/dist/actions/signOut/signOut.cjs +376 -228
- package/dist/actions/signOut/signOut.d.ts +1 -1
- package/dist/actions/signOut/signOut.js +10 -9
- package/dist/api/createApi.cjs +750 -0
- package/dist/api/createApi.d.ts +12 -0
- package/dist/api/createApi.js +19 -0
- package/dist/api/getSession.cjs +141 -0
- package/dist/api/getSession.d.ts +16 -0
- package/dist/api/getSession.js +10 -0
- package/dist/api/signIn.cjs +549 -0
- package/dist/api/signIn.d.ts +26 -0
- package/dist/api/signIn.js +15 -0
- package/dist/api/signOut.cjs +279 -0
- package/dist/api/signOut.d.ts +16 -0
- package/dist/api/signOut.js +13 -0
- package/dist/assert.cjs +150 -5
- package/dist/assert.d.ts +26 -3
- package/dist/assert.js +17 -3
- package/dist/{chunk-YRCB5FLE.js → chunk-2A5B7GWR.js} +52 -6
- package/dist/chunk-2GQLSIJ2.js +40 -0
- package/dist/chunk-2IR674WX.js +44 -0
- package/dist/chunk-3J5TUH2I.js +50 -0
- package/dist/chunk-4RWSYUKX.js +98 -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-7BE46WWS.js +88 -0
- package/dist/chunk-7YYXFKLR.js +35 -0
- package/dist/chunk-C3A37LQC.js +33 -0
- package/dist/chunk-CITNGXDA.js +31 -0
- package/dist/chunk-CWX724AG.js +78 -0
- package/dist/chunk-D2CSIUKP.js +74 -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-HT4YLL7N.js → chunk-FPCVZUVG.js} +10 -8
- package/dist/chunk-FW4W3REU.js +25 -0
- package/dist/chunk-GNNBM2WJ.js +83 -0
- package/dist/chunk-IPKO6UQN.js +25 -0
- package/dist/chunk-JOCGX3RP.js +59 -0
- package/dist/chunk-KBXWTD6E.js +94 -0
- package/dist/chunk-KMMAZFSJ.js +25 -0
- package/dist/chunk-LATR3NIV.js +117 -0
- package/dist/chunk-LAYPUDQF.js +39 -0
- package/dist/chunk-LDU7A2JE.js +25 -0
- package/dist/chunk-LX3TJ2TJ.js +294 -0
- package/dist/chunk-NHZBQNRR.js +143 -0
- package/dist/chunk-OVHNRULD.js +33 -0
- package/dist/chunk-PDP3PHB3.js +127 -0
- package/dist/chunk-PHYNROD4.js +47 -0
- package/dist/chunk-QQEKY4XP.js +29 -0
- package/dist/chunk-U4RK4LKJ.js +348 -0
- package/dist/{chunk-RRLIF4PQ.js → chunk-U5663F2U.js} +16 -1
- package/dist/chunk-UN7X6SU5.js +53 -0
- package/dist/chunk-UZQJJD6A.js +100 -0
- package/dist/chunk-V6LLEAR4.js +80 -0
- package/dist/chunk-WHNDRO3N.js +50 -0
- package/dist/{chunk-W6LG7BFW.js → chunk-XY5R3EHH.js} +30 -23
- package/dist/client/client.cjs +135 -0
- package/dist/client/client.d.ts +85 -0
- package/dist/client/client.js +9 -0
- package/dist/client/index.cjs +135 -0
- package/dist/client/index.d.ts +14 -0
- package/dist/client/index.js +10 -0
- package/dist/context.cjs +1237 -0
- package/dist/context.d.ts +16 -0
- package/dist/context.js +28 -0
- package/dist/cookie.cjs +57 -22
- package/dist/cookie.d.ts +11 -6
- package/dist/cookie.js +3 -2
- package/dist/createAuth.cjs +2320 -0
- package/dist/createAuth.d.ts +12 -0
- package/dist/createAuth.js +48 -0
- package/dist/env.cjs +78 -0
- package/dist/env.d.ts +10 -0
- package/dist/env.js +12 -0
- package/dist/errors.cjs +17 -0
- package/dist/errors.d.ts +15 -4
- package/dist/errors.js +5 -1
- package/dist/headers.cjs +28 -2
- package/dist/headers.d.ts +25 -1
- package/dist/headers.js +9 -3
- package/dist/index-_aXtxb_s.d.ts +1377 -0
- package/dist/index.cjs +1843 -610
- package/dist/index.d.ts +11 -92
- package/dist/index.js +53 -85
- package/dist/jose.cjs +113 -38
- package/dist/jose.d.ts +12 -23
- package/dist/jose.js +17 -7
- package/dist/logger.cjs +424 -0
- package/dist/logger.d.ts +12 -0
- package/dist/logger.js +17 -0
- package/dist/oauth/atlassian.cjs +57 -0
- package/dist/oauth/atlassian.d.ts +12 -0
- package/dist/oauth/atlassian.js +6 -0
- package/dist/oauth/bitbucket.cjs +19 -15
- package/dist/oauth/bitbucket.d.ts +7 -2
- package/dist/oauth/bitbucket.js +1 -1
- package/dist/oauth/discord.cjs +27 -24
- package/dist/oauth/discord.d.ts +7 -2
- package/dist/oauth/discord.js +1 -1
- package/dist/oauth/dropbox.cjs +53 -0
- package/dist/oauth/dropbox.d.ts +12 -0
- package/dist/oauth/dropbox.js +6 -0
- package/dist/oauth/figma.cjs +19 -16
- package/dist/oauth/figma.d.ts +7 -2
- package/dist/oauth/figma.js +1 -1
- package/dist/oauth/github.cjs +19 -8
- package/dist/oauth/github.d.ts +7 -2
- package/dist/oauth/github.js +1 -1
- package/dist/oauth/gitlab.cjs +19 -16
- package/dist/oauth/gitlab.d.ts +7 -2
- package/dist/oauth/gitlab.js +1 -1
- package/dist/oauth/index.cjs +529 -239
- package/dist/oauth/index.d.ts +7 -2
- package/dist/oauth/index.js +39 -22
- package/dist/oauth/mailchimp.cjs +19 -16
- package/dist/oauth/mailchimp.d.ts +7 -2
- package/dist/oauth/mailchimp.js +1 -1
- package/dist/oauth/notion.cjs +131 -0
- package/dist/oauth/notion.d.ts +12 -0
- package/dist/oauth/notion.js +9 -0
- package/dist/oauth/pinterest.cjs +19 -16
- package/dist/oauth/pinterest.d.ts +7 -2
- package/dist/oauth/pinterest.js +1 -1
- package/dist/oauth/spotify.cjs +19 -16
- package/dist/oauth/spotify.d.ts +7 -2
- package/dist/oauth/spotify.js +1 -1
- package/dist/oauth/strava.cjs +19 -16
- package/dist/oauth/strava.d.ts +7 -2
- package/dist/oauth/strava.js +1 -1
- package/dist/oauth/twitch.cjs +95 -0
- package/dist/oauth/twitch.d.ts +12 -0
- package/dist/oauth/twitch.js +7 -0
- package/dist/oauth/x.cjs +19 -16
- package/dist/oauth/x.d.ts +7 -2
- package/dist/oauth/x.js +1 -1
- package/dist/schemas.cjs +89 -42
- package/dist/schemas.d.ts +114 -18
- package/dist/schemas.js +5 -3
- package/dist/secure.cjs +73 -31
- package/dist/secure.d.ts +11 -11
- package/dist/secure.js +7 -6
- package/dist/utils.cjs +203 -90
- package/dist/utils.d.ts +21 -40
- package/dist/utils.js +21 -12
- package/package.json +9 -6
- package/dist/chunk-3EUWD5BB.js +0 -63
- 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-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-GA2SMTJO.js +0 -58
- package/dist/chunk-HP34YGGJ.js +0 -22
- package/dist/chunk-IKHPGFCW.js +0 -14
- package/dist/chunk-IUYZQTJV.js +0 -30
- package/dist/chunk-IVET23KF.js +0 -58
- package/dist/chunk-JVFTCTTE.js +0 -33
- package/dist/chunk-KRNOMBXQ.js +0 -22
- package/dist/chunk-KSWLO5ZU.js +0 -102
- package/dist/chunk-N2APGLXA.js +0 -71
- package/dist/chunk-N4SX7TZT.js +0 -96
- package/dist/chunk-STHEPPUZ.js +0 -11
- package/dist/chunk-TLE4PXY3.js +0 -39
- package/dist/index-B8jeIElf.d.ts +0 -679
- /package/dist/{chunk-DIVDFNAP.js → chunk-5X7JZMEF.js} +0 -0
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-N2APGLXA.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
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
|
-
};
|
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
|
-
};
|
package/dist/chunk-STHEPPUZ.js
DELETED
package/dist/chunk-TLE4PXY3.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createDerivedSalt
|
|
3
|
-
} from "./chunk-N2APGLXA.js";
|
|
4
|
-
import {
|
|
5
|
-
AuthInternalError
|
|
6
|
-
} from "./chunk-RRLIF4PQ.js";
|
|
7
|
-
|
|
8
|
-
// src/jose.ts
|
|
9
|
-
import "dotenv/config";
|
|
10
|
-
import { createJWT, createJWS, createJWE, createDeriveKey } from "@aura-stack/jose";
|
|
11
|
-
var createJoseInstance = (secret) => {
|
|
12
|
-
const env = process.env;
|
|
13
|
-
secret ??= env.AURA_AUTH_SECRET ?? env.AUTH_SECRET;
|
|
14
|
-
if (!secret) {
|
|
15
|
-
throw new AuthInternalError(
|
|
16
|
-
"JOSE_INITIALIZATION_FAILED",
|
|
17
|
-
"AURA_AUTH_SECRET environment variable is not set and no secret was provided."
|
|
18
|
-
);
|
|
19
|
-
}
|
|
20
|
-
const salt = env.AURA_AUTH_SALT ?? env.AUTH_SALT ?? createDerivedSalt(secret);
|
|
21
|
-
const { derivedKey: derivedSigningKey } = createDeriveKey(secret, salt, "signing");
|
|
22
|
-
const { derivedKey: derivedEncryptionKey } = createDeriveKey(secret, salt, "encryption");
|
|
23
|
-
const { derivedKey: derivedCsrfTokenKey } = createDeriveKey(secret, salt, "csrfToken");
|
|
24
|
-
const { decodeJWT, encodeJWT } = createJWT({ jws: derivedSigningKey, jwe: derivedEncryptionKey });
|
|
25
|
-
const { signJWS, verifyJWS } = createJWS(derivedCsrfTokenKey);
|
|
26
|
-
const { encryptJWE, decryptJWE } = createJWE(derivedEncryptionKey);
|
|
27
|
-
return {
|
|
28
|
-
decodeJWT,
|
|
29
|
-
encodeJWT,
|
|
30
|
-
signJWS,
|
|
31
|
-
verifyJWS,
|
|
32
|
-
encryptJWE,
|
|
33
|
-
decryptJWE
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export {
|
|
38
|
-
createJoseInstance
|
|
39
|
-
};
|