moscajs / aedes

Barebone MQTT broker that can run on any stream server, the node way
MIT License
1.79k stars 231 forks source link

authorizeSubscribe, cannot restrict client from subscribing #48

Closed rahulbhanushali closed 8 years ago

rahulbhanushali commented 8 years ago

I am trying to restrict subscriptions to specific topics on aedes using the authorizeSubscribe method.

I tried the example code shown in the documentation, however was not able to restrict users from subscribing.

Can you please help me in implementing this?

mcollina commented 8 years ago

You should probably attach an example here. Il giorno lun 9 mag 2016 alle 18:12 Rahul Bhanushali < notifications@github.com> ha scritto:

I am trying to restrict subscriptions to specific topics on aedes using the authorizeSubscribe method.

I tried the example code shown in the documentation, however was not able to restrict users from subscribing.

Can you please help me in implementing this?

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/mcollina/aedes/issues/48

rahulbhanushali commented 8 years ago

I tried multiple variations as demonstrated in readme file.

I tried this code snippet but was still able to receive messages when someone published message to the topic 'bbb'

instance.authorizeSubscribe = function (client, sub, done) {
    if (sub.topic === 'bbb') {
        // overwrites subscription
        sub.qos = sub.qos + 128
      }

  callback(null, sub)
}

The following code snippet causes the client to reconnect again and again

instance.authorizeSubscribe = function (client, sub, done) {
    if (sub.topic === 'aaaa') {
        return cb(new Error('wrong topic'))
    }
}

None of the above methods seem to work.

mcollina commented 8 years ago

The latter is expected, as the subscription is causing an error.

There previous example is wrong (even in the README), you need to set sub to false to negate.

rahulbhanushali commented 8 years ago

Setting sub to null works, thanks :)