moscajs / mosca

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

MQTT over WS doesn't call auth callbacks #504

Closed muka closed 8 years ago

muka commented 8 years ago

Hi, I have an embed mosca instance attached with attachHttpServer to the main http server.

I noticed that when client connect from plain mqtt the are checked via authenticate and authorizeSubscribe while instead over WS I do not see any check on connection and publish/subscribe seems to be not working (but I see subscription in mosca logs).

Is it supposed to work like this or is it a bug?

UPDATE: Seems attach server must be called after overriding auth-related callbacks, but setting it after ready cause connection drops with

Connection closed before receiving a handshake response

  var server = new mosca.Server(cfg);
  // server.attachHttpServer(httpserver);
  server.on('ready', function () {

    server.authenticate = authenticate;
    server.authorizePublish = authorizePublish;
    server.authorizeSubscribe = authorizeSubscribe;

    server.attachHttpServer(httpserver);
  });

Thank you Luca

muka commented 8 years ago

Sorry, self closing as it is not a bug.

The final code which works is

var server = new mosca.Server(cfg);
server.authenticate = authenticate;
server.authorizePublish = authorizePublish;
server.authorizeSubscribe = authorizeSubscribe;
server.attachHttpServer(httpserver);