You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Feb 11, 2020. It is now read-only.
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)}
}
}
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?
The text was updated successfully, but these errors were encountered: