This repository was archived by the owner on Feb 6, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 59
This repository was archived by the owner on Feb 6, 2025. It is now read-only.
connot find client.user #49
Copy link
Copy link
Open
Description
when use Ponte as embedded in nodejs code and i want to authorize for publishing, client.user is not found in client object while publish payload in MQTT.
var authorizePublish = function(client, topic, payload, callback) {
callback(null, client.user == topic.split('/')[1]);
} client.id is Ok but about client.user it is not included and it's undefined.
you can find whole code below;
const debug = require('debug')('iok-express:ponte');
const ponte = require('ponte');
var config = require('../config/ponte.js');
var mongoose = require('mongoose');
var Thing = require("../models/thing");
// Accepts the connection if the username and password are valid
var authenticate = function (client, username, password, callback) {
Thing.findOne({clientid: client.id}, function(err, things) {
if (err) {
console.log('Quering thing failed.');
console.log(err);
callback(null, false);
return;
}
if (!things) {
console.log("ClientID Not found, Client ID:" + client.id);
callback(null, false);
return;
}
if (username == things.config.username && password == things.config.password) {
console.log('Successful MQTT credintial. Client ID:' + client.id);
callback(null, true);
return;
}
else {
console.log('Unsuccessful MQTT credintial. Client ID:' + client.id + ' ,Username:' + username + ' ,Password:' + password);
callback(null, false);
}
});
}
var authorizePublish = function(client, topic, payload, callback) {
callback(null, client.id == topic.split('/')[1]);
}
var authorizeSubscribe = function(client, topic, callback) {
callback(null, client.id == topic.split('/')[1]);
}
config.mqtt.authenticate = authenticate;
config.mqtt.authorizePublish = authorizePublish;
config.mqtt.authorizeSubscribe = authorizeSubscribe;
var server = ponte(config);
server.on("updated", function(resource, buffer) {
console.log("Resource Updated", resource, buffer);
});
Metadata
Metadata
Assignees
Labels
No labels