Token based authentication

This commit is contained in:
Shivering Ocelot committed 2025-05-28 01:15:46 -05:00
1 parent 9a8e68f021
commit 5bbdfe8747
7 files changed
+121 -77

No files matched your search

+26 -5
View File
@@ -2,7 +2,8 @@ const WebSocket = require('ws');
const USE_LLM = false;
const ws = new WebSocket('ws://localhost:5000/ws');
const hostname = 'localhost:5000';
const ws = new WebSocket(`ws://${hostname}/ws`);
var nonceCounter = 1;
var nonceCallbacks = {};
var messageQueue = [];
@@ -10,8 +11,27 @@ var messageResolverQueue = [];
// Setup
ws.on('open', function open() {
const packet = JSON.stringify({ username: "test-user", password: "123456" });
const credentials = { username: "test-user", password: "123456" };
const tokenPromise = new Promise(async resolve => {
try {
const response = await fetch(`http://${hostname}/user/login`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(credentials),
});
const data = await response.json();
resolve(data.token);
} catch (error) {
console.error("Login Failed", error);
process.exit(1);
}
});
ws.on('open', async function open() {
const token = await tokenPromise;
console.log("Token:", token);
const packet = JSON.stringify({token});
ws.send(packet);
runTest();
@@ -125,8 +145,9 @@ async function runTest() {
await testChats();
// Should be enabled with USE_LLM
await testGral(mainAgentId);
if (USE_LLM) {
await testGral(mainAgentId);
}
process.exit();
}