mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 09:47:08 +00:00
Only send websocket notifications to authenticated users
This commit is contained in:
@@ -28,6 +28,10 @@ function start (server, pingInterval=30000) {
|
|||||||
jwt.checkValidCredentials({jwt: token}).then( decoded => {
|
jwt.checkValidCredentials({jwt: token}).then( decoded => {
|
||||||
console.log("refreshJwt decoded JWT = ", decoded);
|
console.log("refreshJwt decoded JWT = ", decoded);
|
||||||
if (decoded) {
|
if (decoded) {
|
||||||
|
// The connection is now authenticated.
|
||||||
|
// Let us remember this user's details
|
||||||
|
socket._jwt = decoded;
|
||||||
|
|
||||||
console.log("Renewing JWT via websocket");
|
console.log("Renewing JWT via websocket");
|
||||||
delete decoded.exp;
|
delete decoded.exp;
|
||||||
const token = jwt.issue(decoded);
|
const token = jwt.issue(decoded);
|
||||||
@@ -41,11 +45,13 @@ function start (server, pingInterval=30000) {
|
|||||||
scheduleJwtRefresh(token);
|
scheduleJwtRefresh(token);
|
||||||
} else {
|
} else {
|
||||||
console.warn("FAILED to decode JWT");
|
console.warn("FAILED to decode JWT");
|
||||||
|
delete socket._jwt;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch( err => {
|
.catch( err => {
|
||||||
console.log("refreshJwt: Invalid credentials found");
|
console.log("refreshJwt: Invalid credentials found");
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
delete socket._jwt;
|
||||||
socket.close();
|
socket.close();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -84,7 +90,11 @@ function start (server, pingInterval=30000) {
|
|||||||
|
|
||||||
listen(channels, (data) => {
|
listen(channels, (data) => {
|
||||||
wsServer.clients.forEach( (socket) => {
|
wsServer.clients.forEach( (socket) => {
|
||||||
socket.send(JSON.stringify(data));
|
if (socket._jwt) {
|
||||||
|
// Only send notifications to authenticated users
|
||||||
|
// FIXME should implement authorisation control as in the API
|
||||||
|
socket.send(JSON.stringify(data));
|
||||||
|
}
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user