Merge pull request #230 from Hornwitser/auth-1.2.x

Add authentication to socket.io server
This commit is contained in:
Arvids Godjuks authored and GitHub committed 2019-09-11 15:19:18 +02:00
commit 97c7a69c7a
3 files changed
+25 -1

No files matched your search

+9
View File
@@ -0,0 +1,9 @@
Changelog
=========
Version 1.2.1
-------------
### Breaking Changes
- Added authentication to the socket.io server running on the master.
+4 -1
View File
@@ -570,7 +570,10 @@ async function instanceManagement(instanceconfig) {
console.log("Started instanceManagement();");
/* Open websocket connection to master */
var socket = ioClient("http://"+config.masterIP+":"+config.masterPort);
var socket = ioClient("http://"+config.masterIP+":"+config.masterPort+"?token="+config.masterAuthToken);
socket.on("error", err => {
console.log("SOCKET | Error: ", err);
});
socket.on("hello", data => {
console.log("SOCKET | registering slave!");
socket.emit("registerSlave", {
+12
View File
@@ -921,6 +921,18 @@ class wsSlave {
}
}
io.use((socket, next) => {
let token = socket.handshake.query.token;
authenticate.check(token).then((result) => {
if (result.ok) {
next();
} else {
console.error(`SOCKET | authentication failed for ${socket.handshake.address}`);
next(new Error(result.msg));
}
});
});
io.on('connection', function (socket) {
// cleanup dead sockets from disconnected people
let terminatedConnections = 0;