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
8fbdb9dc
Commit
8fbdb9dc
authored
Aug 23, 2018
by
Chavee Issariyapat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update authhook
parent
b8c89812
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
12 deletions
+40
-12
authhook/auth_on_register.js
+21
-2
authhook/auth_on_subscribe.js
+9
-5
authhook/index.js
+10
-5
No files found.
authhook/auth_on_register.js
View file @
8fbdb9dc
...
...
@@ -3,8 +3,9 @@ var config = require('config');
var
LRU
=
require
(
"lru-cache"
)
,
cache
=
LRU
({
max
:
500
,
maxAge
:
1000
*
60
*
5
maxAge
:
1000
*
60
*
5
});
var
debug
=
false
;
var
authclient
=
require
(
'seneca'
)({
log
:
'silent'
})
.
client
({
port
:
config
.
get
(
'authserv_port'
),
host
:
config
.
get
(
'authserv_host'
)});
...
...
@@ -13,7 +14,22 @@ var authclient = require('seneca')({log: 'silent'})
function
authCheck
(
client_id
,
token
,
password
,
callback
)
{
authclient
.
act
({
role
:
'auth'
,
cmd
:
'token'
,
action
:
'info'
,
token
:
token
},
function
(
err
,
res
)
{
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
{
...
...
@@ -23,11 +39,14 @@ function authCheck(client_id, token, password, callback) {
}
module
.
exports
=
function
(
options
=
{})
{
debug
=
options
.
debug
||
false
;
return
function
(
req
,
res
,
next
)
{
if
(
req
.
header
(
'vernemq-hook'
)
==
'auth_on_register'
&&
req
&&
req
.
body
)
{
if
(
options
.
debug
)
{
if
(
debug
)
{
console
.
log
(
'auth_on_register-------------'
);
console
.
log
(
req
.
body
);
}
...
...
authhook/auth_on_subscribe.js
View file @
8fbdb9dc
...
...
@@ -5,6 +5,7 @@ var LRU = require("lru-cache") ,
max
:
500
,
maxAge
:
1000
*
60
*
5
});
var
debug
=
false
;
// for testing
function
authCheck
(
client_id
,
token
,
topic
,
callback
)
{
...
...
@@ -12,14 +13,17 @@ function authCheck(client_id, token, topic, callback) {
}
module
.
exports
=
function
(
options
=
{})
{
debug
=
options
.
debug
||
false
;
return
function
(
req
,
res
,
next
)
{
if
(
req
.
header
(
'vernemq-hook'
)
==
'auth_on_subscribe'
&&
req
&&
req
.
body
)
{
if
(
options
.
debug
)
{
console
.
log
(
'auth_on_subscribe-------------'
);
console
.
log
(
req
.
body
);
}
if
(
debug
)
{
console
.
log
(
'auth_on_subscribe-------------'
);
console
.
log
(
req
.
body
);
}
if
(
req
.
header
(
'vernemq-hook'
)
==
'auth_on_subscribe'
&&
req
&&
req
.
body
)
{
var
authstatus
;
var
topic
=
req
.
body
.
topics
[
0
].
topic
;
...
...
authhook/index.js
View file @
8fbdb9dc
process
.
env
[
"NODE_ENV"
]
=
"development"
;
process
.
env
[
"NODE_CONFIG_DIR"
]
=
__dirname
+
"/config/"
;
var
auth_on_register_debug
=
process
.
env
[
"AUTH_ON_REGISTER_DEBUG"
]
||
false
;
var
auth_on_publish_debug
=
process
.
env
[
"AUTH_ON_PUBLISH_DEBUG"
]
||
false
;
var
auth_on_subscribe_debug
=
process
.
env
[
"AUTH_ON_SUBSCRIBE_DEBUG"
]
||
false
;
var
on_publish_debug
=
process
.
env
[
"ON_PUBLISH_DEBUG"
]
||
false
;
var
restify
=
require
(
'restify'
);
var
auth_on_register
=
require
(
'./auth_on_register'
)({
debug
:
true
});
var
auth_on_publish
=
require
(
'./auth_on_publish'
)({
debug
:
true
});
var
auth_on_subscribe
=
require
(
'./auth_on_subscribe'
)({
debug
:
true
});
var
on_publish
=
require
(
'./on_publish'
)({
debug
:
true
});
var
auth_on_register
=
require
(
'./auth_on_register'
)({
debug
:
auth_on_register_debug
});
var
auth_on_publish
=
require
(
'./auth_on_publish'
)({
debug
:
auth_on_publish_debug
});
var
auth_on_subscribe
=
require
(
'./auth_on_subscribe'
)({
debug
:
auth_on_subscribe_debug
});
var
on_publish
=
require
(
'./on_publish'
)({
debug
:
on_publish_debug
});
const
server
=
restify
.
createServer
({
name
:
'authhook'
,
version
:
'1.0.
0
'
,
version
:
'1.0.
1
'
,
});
const
port
=
40000
;
...
...
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