Commit 49e56b22 by zCaesar

chg pth to tokenregistry

parent 6667b003
...@@ -27,14 +27,7 @@ module.exports = function (options = {}) { ...@@ -27,14 +27,7 @@ module.exports = function (options = {}) {
var response var response
var decoded = require('jwt-verify').verify(req.body.username).res var decoded = require('jwt-verify').verify(req.body.username).res
// var decoded = require('./checkClientRole').checkRealDB(req.body.username)
// const util = require('util')
// console.log('-----------decode----------')
// console.log(util.inspect(decoded, false, null, true));
// console.log('-----------decode----------')
// console.log('-----------decodes----------')
// console.log(util.inspect(decodeds, false, null, true));
// console.log('-----------decodes----------')
if (decoded) { if (decoded) {
if (decoded.role === 'realtimedb') response = { 'result': 'ok' } if (decoded.role === 'realtimedb') response = { 'result': 'ok' }
else response = { 'result': 'no' } else response = { 'result': 'no' }
......
var validator = require('./validator'); var validator = require('./validator');
var config = require('config'); var config = require('config');
var seneca = require('seneca')({log: 'silent'}).client({ port: config.get('device_registry_port'), host: config.get('device_registry_host') }); // var seneca = require('seneca')({log: 'silent'}).client({ port: config.get('device_registry_port'), host: config.get('device_registry_host') });
var seneca = require('seneca')({log: 'silent'}).client({ port: config.get('token_registry_port'), host: config.get('token_registry_host') });
// https://github.com/isaacs/node-lru-cache // https://github.com/isaacs/node-lru-cache
var LRU = require("lru-cache"), var LRU = require("lru-cache"),
...@@ -20,13 +21,11 @@ function authCheck(client_id, token, password, callback) { ...@@ -20,13 +21,11 @@ function authCheck(client_id, token, password, callback) {
if (require('jwt-verify').verify(token)) { // auth realtimedb by token if (require('jwt-verify').verify(token)) { // auth realtimedb by token
callback(true); callback(true);
} }
// if (require('./checkClientRole').checkRealDB(token)) { // auth realtimedb by token
// callback(true);
// }
else { else {
if (require('jwt-verify').verify(token)) callback(true) // auth client device by token if (require('jwt-verify').verify(token)) callback(true) // auth client device by token
else { else {
seneca.act('cmd:getAccessTokenInfo, tokencode:'+token, function(err,res) { seneca.act('ms:tokenregistry, cmd:getAttributes, type:device, tokencode:'+token, function(err,res) {
if (!err && res) { if (!err && res) {
var token_profile = (res&&res.result&&res.result[0])?res.result[0]:{}; var token_profile = (res&&res.result&&res.result[0])?res.result[0]:{};
var mqttauth = { var mqttauth = {
...@@ -40,6 +39,20 @@ function authCheck(client_id, token, password, callback) { ...@@ -40,6 +39,20 @@ function authCheck(client_id, token, password, callback) {
callback(false); callback(false);
} }
}); });
// seneca.act('cmd:getAccessTokenInfo, tokencode:'+token, function(err,res) {
// if (!err && res) {
// var token_profile = (res&&res.result&&res.result[0])?res.result[0]:{};
// var mqttauth = {
// clientid : client_id,
// token : token,
// password : password
// };
// callback( validator.auth_connect(mqttauth, token_profile) );
// }
// else {
// callback(false);
// }
// });
// authclient.act({ role: 'auth', cmd: 'token', action: 'info', token: token }, function (err, res) { // auth client device by query from db // authclient.act({ role: 'auth', cmd: 'token', action: 'info', token: token }, function (err, res) { // auth client device by query from db
......
...@@ -26,11 +26,7 @@ module.exports = function (options = {}) { ...@@ -26,11 +26,7 @@ module.exports = function (options = {}) {
} }
var response var response
var decoded = require('jwt-verify').verify(req.body.username).res var decoded = require('jwt-verify').verify(req.body.username).res
// var decoded = require('./checkClientRole').checkRealDB(req.body.username)
const util = require('util')
console.log('-----------decode----------')
console.log(util.inspect(decoded, false, null, true));
console.log('-----------decode----------')
if (decoded) { if (decoded) {
if (decoded.role === 'realtimedb') response = { 'result': 'ok' } if (decoded.role === 'realtimedb') response = { 'result': 'ok' }
else response = { 'result': 'no' } else response = { 'result': 'no' }
......
...@@ -8,7 +8,7 @@ module.exports = function(options = {}) { ...@@ -8,7 +8,7 @@ module.exports = function(options = {}) {
var response var response
var decoded = require('jwt-verify').verify(token).res var decoded = require('jwt-verify').verify(token).res
// var decoded = require('./checkClientRole').checkRealDB(token)
if (decoded) { if (decoded) {
if (decoded.role === 'realtimedb') { if (decoded.role === 'realtimedb') {
response = { 'result': 'ok' } response = { 'result': 'ok' }
......
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