Commit 4982f211 by Chavee Issariyapat

update authhook

parent ce0624cf
...@@ -14,14 +14,12 @@ function authCheck(client_id, username, topic, callback) { ...@@ -14,14 +14,12 @@ function authCheck(client_id, username, topic, callback) {
module.exports = function(options={}) { module.exports = function(options={}) {
return function(req, res, next) { 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) { if (options.debug) {
console.log(req.body); console.log(req.body);
} }
var out, authstatus; var authstatus;
var cachekey = req.body.client_id +':'+ req.body.username +':'+ req.body.password;
var topic = req.body.topic; var topic = req.body.topic;
var cachekey = 'pub:'+req.body.client_id +':'+ req.body.username+':'+topic; var cachekey = 'pub:'+req.body.client_id +':'+ req.body.username+':'+topic;
...@@ -47,6 +45,7 @@ module.exports = function(options={}) { ...@@ -47,6 +45,7 @@ module.exports = function(options={}) {
res.send({ res.send({
"result": "no" "result": "no"
}); });
next();
} }
} }
} }
...@@ -11,8 +11,8 @@ var authclient = require('seneca')({log: 'silent'}) ...@@ -11,8 +11,8 @@ var authclient = require('seneca')({log: 'silent'})
// for testing // for testing
function authCheck(client_id, token, password, callback) { function authCheck(client_id, token, password, callback) {
authclient.act({role:'auth',cmd:'token',action:'info',token: token}, function(err, res) { authclient.act({role:'auth',cmd:'token',action:'info',token: token}, function(err, res) {
console.log(res);
if (res && res.data) { if (res && res.data) {
callback(true); callback(true);
} }
...@@ -48,6 +48,7 @@ module.exports = function(options={}) { ...@@ -48,6 +48,7 @@ module.exports = function(options={}) {
res.send({ res.send({
"result": "no" "result": "no"
}); });
next();
} }
} }
} }
...@@ -7,21 +7,19 @@ var LRU = require("lru-cache") , ...@@ -7,21 +7,19 @@ var LRU = require("lru-cache") ,
}); });
// for testing // for testing
function authCheck(client_id, username, topic, callback) { function authCheck(client_id, token, topic, callback) {
callback(true); callback(true);
} }
module.exports = function(options={}) { module.exports = function(options={}) {
return function(req, res, next) { 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) { if (options.debug) {
console.log(req.body); console.log(req.body);
} }
var out, authstatus; var authstatus;
var cachekey = req.body.client_id +':'+ req.body.username +':'+ req.body.password;
var topic = req.body.topic; var topic = req.body.topic;
var cachekey = 'sub:'+req.body.client_id +':'+ req.body.username+':'+topic; var cachekey = 'sub:'+req.body.client_id +':'+ req.body.username+':'+topic;
...@@ -47,6 +45,7 @@ module.exports = function(options={}) { ...@@ -47,6 +45,7 @@ module.exports = function(options={}) {
res.send({ res.send({
"result": "no" "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