mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-15 23:24:52 +09:00
Add authentication to socket.io server
Authenticate connections made to the socket.io server via a token query parameter that's validated in a similar manner to the x-access-token for HTTP requests.
This commit is contained in:
1 parent
88eff17dfd
commit
0c45e57732
3 files changed
+25
-1
No files matched your search
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user