@voltagent/server-core 1.0.28 → 1.0.30
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/index.d.mts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +32 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +32 -15
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1900,6 +1900,11 @@ interface JWTAuthOptions {
|
|
|
1900
1900
|
audience?: string;
|
|
1901
1901
|
issuer?: string;
|
|
1902
1902
|
};
|
|
1903
|
+
/**
|
|
1904
|
+
* When true, all routes require authentication by default (opt-out model)
|
|
1905
|
+
* @default false
|
|
1906
|
+
*/
|
|
1907
|
+
defaultPrivate?: boolean;
|
|
1903
1908
|
}
|
|
1904
1909
|
/**
|
|
1905
1910
|
* Create a JWT authentication provider
|
package/dist/index.d.ts
CHANGED
|
@@ -1900,6 +1900,11 @@ interface JWTAuthOptions {
|
|
|
1900
1900
|
audience?: string;
|
|
1901
1901
|
issuer?: string;
|
|
1902
1902
|
};
|
|
1903
|
+
/**
|
|
1904
|
+
* When true, all routes require authentication by default (opt-out model)
|
|
1905
|
+
* @default false
|
|
1906
|
+
*/
|
|
1907
|
+
defaultPrivate?: boolean;
|
|
1903
1908
|
}
|
|
1904
1909
|
/**
|
|
1905
1910
|
* Create a JWT authentication provider
|
package/dist/index.js
CHANGED
|
@@ -3963,7 +3963,8 @@ function jwtAuth(options) {
|
|
|
3963
3963
|
}
|
|
3964
3964
|
return void 0;
|
|
3965
3965
|
},
|
|
3966
|
-
publicRoutes
|
|
3966
|
+
publicRoutes,
|
|
3967
|
+
defaultPrivate: options.defaultPrivate
|
|
3967
3968
|
};
|
|
3968
3969
|
}
|
|
3969
3970
|
__name(jwtAuth, "jwtAuth");
|
|
@@ -4884,21 +4885,37 @@ function setupWebSocketUpgrade(server, wss, pathPrefix = "/ws", auth, logger) {
|
|
|
4884
4885
|
}
|
|
4885
4886
|
user = { id: "console", type: "console-access" };
|
|
4886
4887
|
} else {
|
|
4887
|
-
const
|
|
4888
|
-
if (
|
|
4889
|
-
|
|
4890
|
-
|
|
4891
|
-
|
|
4892
|
-
|
|
4893
|
-
|
|
4894
|
-
|
|
4895
|
-
|
|
4888
|
+
const hasConsoleAccess2 = hasWebSocketConsoleAccess(req);
|
|
4889
|
+
if (hasConsoleAccess2) {
|
|
4890
|
+
user = { id: "console", type: "console-access" };
|
|
4891
|
+
} else {
|
|
4892
|
+
const needsAuth = requiresAuth("WS", path2, auth.publicRoutes, auth.defaultPrivate);
|
|
4893
|
+
if (needsAuth) {
|
|
4894
|
+
const token = url.searchParams.get("token");
|
|
4895
|
+
if (token) {
|
|
4896
|
+
try {
|
|
4897
|
+
user = await auth.verifyToken(token);
|
|
4898
|
+
} catch (error) {
|
|
4899
|
+
logger?.debug("[WebSocket] Token verification failed:", { error });
|
|
4900
|
+
socket.write("HTTP/1.1 401 Unauthorized\r\n\r\n");
|
|
4901
|
+
socket.destroy();
|
|
4902
|
+
return;
|
|
4903
|
+
}
|
|
4904
|
+
} else {
|
|
4905
|
+
logger?.debug("[WebSocket] No token provided for protected WebSocket");
|
|
4906
|
+
socket.write("HTTP/1.1 401 Unauthorized\r\n\r\n");
|
|
4907
|
+
socket.destroy();
|
|
4908
|
+
return;
|
|
4909
|
+
}
|
|
4910
|
+
} else {
|
|
4911
|
+
const token = url.searchParams.get("token");
|
|
4912
|
+
if (token) {
|
|
4913
|
+
try {
|
|
4914
|
+
user = await auth.verifyToken(token);
|
|
4915
|
+
} catch {
|
|
4916
|
+
}
|
|
4917
|
+
}
|
|
4896
4918
|
}
|
|
4897
|
-
} else if (auth.defaultPrivate) {
|
|
4898
|
-
logger?.debug("[WebSocket] No token provided for protected WebSocket");
|
|
4899
|
-
socket.write("HTTP/1.1 401 Unauthorized\r\n\r\n");
|
|
4900
|
-
socket.destroy();
|
|
4901
|
-
return;
|
|
4902
4919
|
}
|
|
4903
4920
|
}
|
|
4904
4921
|
} catch (error) {
|