Skip to content
This repository has been archived by the owner on Feb 11, 2020. It is now read-only.

username in authorizepublish #781

Open
timoschuetz opened this issue Jan 23, 2019 · 1 comment
Open

username in authorizepublish #781

timoschuetz opened this issue Jan 23, 2019 · 1 comment

Comments

@timoschuetz
Copy link

timoschuetz commented Jan 23, 2019

Hello,

I'm currently working on a application with authorization and I want only one user to be allowed to publish on his channel, like it is given in the example:https://github.com/mcollina/mosca/wiki/Authentication-&-Authorization
The problem is in the client object there is no user value, object.

var authorizePublish = function(client, topic, payload, callback) {
console.log(client.user);
if(topic.split('/')[0] == '$SYS'){callback(null, true)}else{
if(topic.split('/')[1] == 'device'){
if(topic.split('/')[2] == client.user){ //that the part that is not working
callback(null, true);
}
callback(null, false);
}else{callback(null, false)}
}
}

Here is the Client

var mqtt = require('mqtt');

var options = {
port: 1883,
clientId: 'mqttjs_1337',
username: '123',
password: '1234'
};

var client = mqtt.connect('mqtt://localhost', options);

var json = {
'temperature': '42'
}

client.on('connect', function () {
client.publish('/device/123', JSON.stringify(json));
setTimeout(function() {
process.exit();
}, 3000);
})

client.on('message', function (topic, message) {
// message is Buffer
console.log(message.toString())
client.end()
})

How can I access the username in the authorizepublish?

@danclive
Copy link

l already create pull requests #775, but there has been no merge.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants