Skip to content

Instantly share code, notes, and snippets.

@andreareginato
Last active October 14, 2017 22:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreareginato/c8d934cc022e2be10373 to your computer and use it in GitHub Desktop.
Save andreareginato/c8d934cc022e2be10373 to your computer and use it in GitHub Desktop.
var mongoose = require('mongoose')
, debug = require('debug')('lelylan')
, Device = require('../app/models/devices/device');
module.exports.authenticate = function(client, username, password, callback) {
Device.findOne({ _id: username, secret: password }, function (err, doc) {
if (doc) client.device_id = doc.id
callback(null, doc);
});
}
module.exports.authorizePublish = function(client, topic, payload, callback) {
callback(null, client.device_id == topic.split('/')[1]);
}
module.exports.authorizeSubscribe = function(client, topic, callback) {
callback(null, client.device_id == topic.split('/')[1]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment