Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

connot find client.user #49

Open
expandboard opened this issue Sep 29, 2017 · 0 comments
Open

connot find client.user #49

expandboard opened this issue Sep 29, 2017 · 0 comments

Comments

@expandboard
Copy link

expandboard commented Sep 29, 2017

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);
	});	
   
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant