moscajs / mosca

MQTT broker as a module
mosca.io
3.2k stars 509 forks source link

Are mosca can actively disconnect clients? #543

Closed renrenfree closed 7 years ago

renrenfree commented 7 years ago

Are mosca can actively disconnect clients

ameykshirsagar commented 7 years ago

Possible : Yes Solution: I think it is possible in first place by using the authorisation model wisely by using the authenticate method. So its like if the client connects and there is a DB store that stores the user's authorisation flags, which should be controlled by some other module and if the authorisation flags show non-allowance to connect for a particular user, then use the callback in following way

var authenticate = function(client, username, password, callback) {
  //value of authorized is decided by your custom authorization module
  if (authorized){
    //for allowing to connect
    callback(null, authorized);
  }else{
    //for disallowing to connect
    callback(false,null);
  }
}
server.on("ready",function(){
  server.authenticate = authenticate;
});

Reference : here

mcollina commented 7 years ago

You can call client.close once you get hold of a client instance. https://github.com/mcollina/mosca/blob/master/lib/client.js#L577