Commit 4982f211 by Chavee Issariyapat

update authhook

parent ce0624cf
......@@ -14,14 +14,12 @@ function authCheck(client_id, username, topic, callback) {
module.exports = function(options={}) {
return function(req, res, next) {
if (req.header('vernemq-hook') == 'auth_on_publish') {
if (req.header('vernemq-hook') == 'auth_on_publish' && req && req.body) {
if (options.debug) {
console.log(req.body);
}
var out, authstatus;
var cachekey = req.body.client_id +':'+ req.body.username +':'+ req.body.password;
var authstatus;
var topic = req.body.topic;
var cachekey = 'pub:'+req.body.client_id +':'+ req.body.username+':'+topic;
......@@ -47,6 +45,7 @@ module.exports = function(options={}) {
res.send({
"result": "no"
});
next();
}
}
}
......@@ -11,8 +11,8 @@ var authclient = require('seneca')({log: 'silent'})
// for testing
function authCheck(client_id, token, password, callback) {
authclient.act({role:'auth',cmd:'token',action:'info',token: token}, function(err, res) {
console.log(res);
if (res && res.data) {
callback(true);
}
......@@ -48,6 +48,7 @@ module.exports = function(options={}) {
res.send({
"result": "no"
});
next();
}
}
}
......@@ -7,21 +7,19 @@ var LRU = require("lru-cache") ,
});
// for testing
function authCheck(client_id, username, topic, callback) {
function authCheck(client_id, token, topic, callback) {
callback(true);
}
module.exports = function(options={}) {
return function(req, res, next) {
if (req.header('vernemq-hook') == 'auth_on_publish') {
if (req.header('vernemq-hook') == 'auth_on_subscribe' && req && req.body) {
if (options.debug) {
console.log(req.body);
}
var out, authstatus;
var cachekey = req.body.client_id +':'+ req.body.username +':'+ req.body.password;
var authstatus;
var topic = req.body.topic;
var cachekey = 'sub:'+req.body.client_id +':'+ req.body.username+':'+topic;
......@@ -47,6 +45,7 @@ module.exports = function(options={}) {
res.send({
"result": "no"
});
next();
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment