@krak-stack/auth 0.1.66 → 0.1.67
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/server/index.d.ts +1 -0
- package/dist/server/proxy.d.ts +4 -1
- package/dist/server/proxy.js +22 -4
- package/package.json +1 -1
package/dist/server/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export type { AuthSession, AuthSessionWithOrganization, AuthSessionWithUser, Aut
|
|
|
3
3
|
export { AuthClientConfig } from "../config";
|
|
4
4
|
export { ServerDomainsApiGroup, ServerOrganizationsApiGroup, ServerUsersApiGroup, } from "./api.group";
|
|
5
5
|
export { proxyAuthRequest } from "./proxy";
|
|
6
|
+
export type { ProxyAuthRequestOptions } from "./proxy";
|
|
6
7
|
export { ActorRequired } from "./actor";
|
|
7
8
|
export type { ActorConstraint } from "./actor";
|
|
8
9
|
export { ApiKeySecurity, AuthMiddleware, makeAuthenticationLive, } from "./middleware";
|
package/dist/server/proxy.d.ts
CHANGED
|
@@ -1 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export interface ProxyAuthRequestOptions {
|
|
2
|
+
cookieDomain?: string;
|
|
3
|
+
}
|
|
4
|
+
export declare const proxyAuthRequest: (request: Request, baseUrl: string | URL, options?: ProxyAuthRequestOptions) => Promise<Response>;
|
package/dist/server/proxy.js
CHANGED
|
@@ -14,13 +14,31 @@ const blockedRequestHeaders = [
|
|
|
14
14
|
"cdn-loop",
|
|
15
15
|
];
|
|
16
16
|
const hostOnlyCookie = (cookie) => cookie.replace(/;\s*domain=[^;]*/gi, "");
|
|
17
|
-
const
|
|
17
|
+
const normalizedCookieDomain = (domain) => domain.trim().toLowerCase().replace(/^\.+|\.+$/g, "");
|
|
18
|
+
const sharedCookieDomain = (request, options) => {
|
|
19
|
+
if (!options?.cookieDomain)
|
|
20
|
+
return null;
|
|
21
|
+
const domain = normalizedCookieDomain(options.cookieDomain);
|
|
22
|
+
const hostname = new URL(request.url).hostname.toLowerCase();
|
|
23
|
+
if (!domain || (hostname !== domain && !hostname.endsWith(`.${domain}`))) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
return domain;
|
|
27
|
+
};
|
|
28
|
+
const cookieForDomain = (cookie, domain) => {
|
|
29
|
+
const hostOnly = hostOnlyCookie(cookie);
|
|
30
|
+
if (!domain || hostOnly.startsWith("__Host-"))
|
|
31
|
+
return hostOnly;
|
|
32
|
+
return `${hostOnly}; Domain=${domain}`;
|
|
33
|
+
};
|
|
34
|
+
const proxyResponse = async (request, response, options) => {
|
|
18
35
|
const headers = new Headers(response.headers);
|
|
19
36
|
const cookies = response.headers.getSetCookie();
|
|
37
|
+
const cookieDomain = sharedCookieDomain(request, options);
|
|
20
38
|
if (cookies.length > 0) {
|
|
21
39
|
headers.delete("set-cookie");
|
|
22
40
|
for (const cookie of cookies) {
|
|
23
|
-
headers.append("set-cookie",
|
|
41
|
+
headers.append("set-cookie", cookieForDomain(cookie, cookieDomain));
|
|
24
42
|
}
|
|
25
43
|
}
|
|
26
44
|
return new Response(response.body, {
|
|
@@ -46,7 +64,7 @@ const proxyHeaders = (request) => {
|
|
|
46
64
|
headers.set("x-forwarded-proto", url.protocol.replace(":", ""));
|
|
47
65
|
return headers;
|
|
48
66
|
};
|
|
49
|
-
export const proxyAuthRequest = async (request, baseUrl) => {
|
|
67
|
+
export const proxyAuthRequest = async (request, baseUrl, options) => {
|
|
50
68
|
const target = new URL(request.url);
|
|
51
69
|
const authUrl = new URL(baseUrl);
|
|
52
70
|
const init = {
|
|
@@ -63,5 +81,5 @@ export const proxyAuthRequest = async (request, baseUrl) => {
|
|
|
63
81
|
const response = await fetch(new Request(target, init), {
|
|
64
82
|
redirect: "manual",
|
|
65
83
|
});
|
|
66
|
-
return proxyResponse(response);
|
|
84
|
+
return proxyResponse(request, response, options);
|
|
67
85
|
};
|