Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
vernemq
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
stack
vernemq
Commits
f04b3be6
Commit
f04b3be6
authored
Oct 29, 2018
by
zCaesar
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'alpha-v2' into 'master'
Edit Register See merge request
!4
parents
4e9efab1
e0d42e97
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
65 additions
and
62 deletions
+65
-62
authhook/auth_on_register.js
+61
-57
authhook/auth_on_subscribe.js
+0
-1
authhook/config/local-dev.json
+2
-2
authhook/package-lock.json
+2
-2
No files found.
authhook/auth_on_register.js
View file @
f04b3be6
...
...
@@ -2,7 +2,7 @@ var validator = require('./validator');
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
(
'token_registry_port'
),
host
:
config
.
get
(
'token_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
var
LRU
=
require
(
"lru-cache"
),
...
...
@@ -17,67 +17,71 @@ var debug = false;
function
authCheck
(
client_id
,
token
,
password
,
callback
)
{
const
util
=
require
(
'util'
)
// console.log(util.inspect(myObject, false, null, true));
if
(
require
(
'jwt-verify'
).
verify
(
token
))
{
// auth realtimedb by token
// console.log('jwt-result:' + util.inspect(require('jwt-verify').verify(token), false, null, true))
if
(
require
(
'jwt-verify'
).
verify
(
token
).
res
)
{
// auth realtimedb by token
callback
(
true
);
}
else
{
if
(
require
(
'jwt-verify'
).
verify
(
token
))
callback
(
true
)
// auth client device by token
else
{
seneca
.
act
(
'ms:tokenregistry, cmd:getAttributes, type:device, 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
);
}
});
// 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
// if (debug) {
// console.log("res ------>\n");
// console.log(res);
// }
// if (res && res.data) {
// try {
// var jdata = JSON.parse(res.data);
// if (jdata && jdata.code == 200) {
// callback(true);
// }
// else callback(false);
// } catch (e) {
// callback(false);
// }
// callback(true);
// }
// else {
// callback(false);
// }
// });
}
// console.log('token :' + token)
seneca
.
act
(
'ms:tokenregistry, cmd:getAttributes, type:device, tokencode:'
+
token
,
function
(
err
,
res
)
{
// console.log('result : ' + util.inspect(res.result, false, null, true))
if
(
res
.
result
)
{
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
);
}
});
// 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
// if (debug) {
// console.log("res ------>\n");
// console.log(res);
// }
// if (res && res.data) {
// try {
// var jdata = JSON.parse(res.data);
// if (jdata && jdata.code == 200) {
// callback(true);
// }
// else callback(false);
// } catch (e) {
// callback(false);
// }
// callback(true);
// }
// else {
// callback(false);
// }
// });
}
}
...
...
authhook/auth_on_subscribe.js
View file @
f04b3be6
...
...
@@ -37,7 +37,6 @@ module.exports = function (options = {}) {
var
GGID
=
require
(
'./utils/getGroupID'
);
GGID
.
getGroupID
(
req
.
body
.
username
,
req
.
body
.
client_id
,
function
(
group
)
{
console
.
log
(
group
);
var
_ftopic
=
require
(
'./utils/router'
).
rewriteTopic
(
topic
,
'sub'
,
group
,
req
.
body
.
client_id
)
// get topic where concat with groupID
var
_topic
=
[{
// setTopic for response
'topic'
:
_ftopic
,
...
...
authhook/config/local-dev.json
View file @
f04b3be6
{
"device_registry_host"
:
"
alpha.nexpie.io
"
,
"device_registry_host"
:
"
localhost
"
,
"device_registry_port"
:
8990
,
"token_registry_host"
:
"
alpha.nexpie.io
"
,
"token_registry_host"
:
"
localhost
"
,
"token_registry_port"
:
8790
,
"auth_on_register_debug"
:
true
,
...
...
authhook/package-lock.json
View file @
f04b3be6
...
...
@@ -438,8 +438,8 @@
}
},
"jwt-verify"
:
{
"version"
:
"git+https://nexpienpm:CCqLQjg4ytvzN7QbssUV@dev.nexpie.com/npm/jwt-verify.git#
2652fe32eb15f1e1f05bc31aa98f5a7c10d049e3
"
,
"from"
:
"git+https://nexpienpm:CCqLQjg4ytvzN7QbssUV@dev.nexpie.com/npm/jwt-verify.git
#issuer
"
,
"version"
:
"git+https://nexpienpm:CCqLQjg4ytvzN7QbssUV@dev.nexpie.com/npm/jwt-verify.git#
c9692da3fd11464e9270acd0c47f289648119ec9
"
,
"from"
:
"git+https://nexpienpm:CCqLQjg4ytvzN7QbssUV@dev.nexpie.com/npm/jwt-verify.git"
,
"requires"
:
{
"config"
:
"^2.0.1"
,
"jsonwebtoken"
:
"^8.3.0"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment