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
3d0afcba
Commit
3d0afcba
authored
Sep 17, 2018
by
zCaesar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add role to flow
parent
d24dd439
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
106 additions
and
46 deletions
+106
-46
authhook/auth_on_publish.js
+49
-22
authhook/auth_on_subscribe.js
+49
-23
authhook/index.js
+4
-0
authhook/on_deliver.js
+3
-0
authhook/on_publish.js
+1
-1
No files found.
authhook/auth_on_publish.js
View file @
3d0afcba
...
@@ -26,32 +26,59 @@ module.exports = function (options = {}) {
...
@@ -26,32 +26,59 @@ module.exports = function (options = {}) {
var
cachekey
=
'pub:'
+
req
.
body
.
client_id
+
':'
+
req
.
body
.
username
+
':'
+
topic
;
var
cachekey
=
'pub:'
+
req
.
body
.
client_id
+
':'
+
req
.
body
.
username
+
':'
+
topic
;
var
authstatus
=
cache
.
get
(
cachekey
);
var
authstatus
=
cache
.
get
(
cachekey
);
// Set Response
console
.
log
(
req
.
body
)
var
getGroupID
=
require
(
'./utils/getGroupID'
).
getGroupID
getGroupID
(
req
.
body
.
username
,
req
.
body
.
client_id
,
(
_id
)
=>
{
// get groupID
// console.log(_id)
var
_ftopic
=
require
(
'./utils/getTopic'
).
getTopic
(
topic
,
_id
)
// get topic where concat with groupID
var
response
=
{
'result'
:
'ok'
,
'modifiers'
:
{
'topic'
:
_ftopic
,
'qos'
:
0
,
'retain'
:
false
}
}
console
.
log
(
response
)
if
(
typeof
(
authstatus
)
==
'undefined'
)
{
// checkRole
// cache missed
var
checkRealDB
=
require
(
'./checkClientRole'
).
checkRealDB
authCheck
(
req
.
body
.
client_id
,
req
.
body
.
username
,
topic
,
function
(
result
)
{
checkRealDB
(
req
.
body
.
username
,
(
err
,
decoded
)
=>
{
cache
.
set
(
cachekey
,
result
);
if
(
err
)
{
res
.
send
(
response
);
// Set Response
});
var
getGroupID
=
require
(
'./utils/getGroupID'
).
getGroupID
getGroupID
(
req
.
body
.
username
,
req
.
body
.
client_id
,
(
_id
)
=>
{
// get groupID
// console.log(_id)
var
_ftopic
=
require
(
'./utils/getTopic'
).
getTopic
(
topic
,
_id
)
// get topic where concat with groupID
var
response
=
{
'result'
:
'ok'
,
'modifiers'
:
{
'topic'
:
_ftopic
,
'qos'
:
0
,
'retain'
:
false
}
}
console
.
log
(
response
)
if
(
typeof
(
authstatus
)
==
'undefined'
)
{
// cache missed
authCheck
(
req
.
body
.
client_id
,
req
.
body
.
username
,
topic
,
function
(
result
)
{
cache
.
set
(
cachekey
,
result
);
res
.
send
(
response
);
});
}
else
{
res
.
send
(
response
);
}
next
();
})
}
}
else
{
else
{
res
.
send
(
response
);
console
.
log
(
decoded
)
if
(
decoded
.
role
===
'realtimedb'
)
{
var
response
=
{
'result'
:
'ok'
}
if
(
typeof
(
authstatus
)
==
'undefined'
)
{
// cache missed
authCheck
(
req
.
body
.
client_id
,
req
.
body
.
username
,
topic
,
function
(
result
)
{
cache
.
set
(
cachekey
,
result
);
res
.
send
(
response
);
});
}
else
{
res
.
send
(
response
);
}
next
();
}
}
}
next
();
})
})
}
}
else
{
else
{
...
...
authhook/auth_on_subscribe.js
View file @
3d0afcba
...
@@ -31,33 +31,59 @@ module.exports = function (options = {}) {
...
@@ -31,33 +31,59 @@ module.exports = function (options = {}) {
var
cachekey
=
'sub:'
+
req
.
body
.
client_id
+
':'
+
req
.
body
.
username
+
':'
+
topic
;
var
cachekey
=
'sub:'
+
req
.
body
.
client_id
+
':'
+
req
.
body
.
username
+
':'
+
topic
;
var
authstatus
=
cache
.
get
(
cachekey
);
var
authstatus
=
cache
.
get
(
cachekey
);
console
.
log
(
req
.
body
)
// checkRole
// checkRole
var
role
=
require
(
'./checkClientRole'
)
var
checkRealDB
=
require
(
'./checkClientRole'
).
checkRealDB
// Set Response
checkRealDB
(
req
.
body
.
username
,
(
err
,
decoded
)
=>
{
var
getGroupID
=
require
(
'./utils/getGroupID'
).
getGroupID
if
(
err
)
{
getGroupID
(
req
.
body
.
username
,
req
.
body
.
client_id
,
(
_id
)
=>
{
// get groupID
// Set Response
// console.log(_id)
var
getGroupID
=
require
(
'./utils/getGroupID'
).
getGroupID
var
_ftopic
=
require
(
'./utils/getTopic'
).
getTopic
(
topic
,
_id
)
// get topic where concat with groupID
getGroupID
(
req
.
body
.
username
,
req
.
body
.
client_id
,
(
_id
)
=>
{
// get groupID
var
_topic
=
[{
// setTopic for response
// console.log(_id)
'topic'
:
_ftopic
,
var
_ftopic
=
require
(
'./utils/getTopic'
).
getTopic
(
topic
,
_id
)
// get topic where concat with groupID
'qos'
:
0
var
_topic
=
[{
// setTopic for response
}]
'topic'
:
_ftopic
,
var
response
=
{
'qos'
:
0
'result'
:
'ok'
,
}]
'topics'
:
_topic
var
response
=
{
}
'result'
:
'ok'
,
'topics'
:
_topic
if
(
typeof
(
authstatus
)
==
'undefined'
)
{
}
// cache missed
console
.
log
(
response
)
authCheck
(
req
.
body
.
client_id
,
req
.
body
.
username
,
topic
,
function
(
result
)
{
cache
.
set
(
cachekey
,
result
);
if
(
typeof
(
authstatus
)
==
'undefined'
)
{
res
.
send
(
response
);
// cache missed
});
authCheck
(
req
.
body
.
client_id
,
req
.
body
.
username
,
topic
,
function
(
result
)
{
cache
.
set
(
cachekey
,
result
);
res
.
send
(
response
);
});
}
else
{
res
.
send
(
response
);
}
next
();
})
}
}
else
{
else
{
res
.
send
(
response
);
console
.
log
(
decoded
)
if
(
decoded
.
role
===
'realtimedb'
)
{
var
response
=
{
'result'
:
'ok'
}
if
(
typeof
(
authstatus
)
==
'undefined'
)
{
// cache missed
authCheck
(
req
.
body
.
client_id
,
req
.
body
.
username
,
topic
,
function
(
result
)
{
cache
.
set
(
cachekey
,
result
);
res
.
send
(
response
);
});
}
else
{
res
.
send
(
response
);
}
next
();
}
}
}
next
();
})
})
}
}
else
{
else
{
...
...
authhook/index.js
View file @
3d0afcba
...
@@ -35,6 +35,10 @@ server.get('/about', function (req, res, next) {
...
@@ -35,6 +35,10 @@ server.get('/about', function (req, res, next) {
server
.
post
(
'/authreg'
,
auth_on_register
);
server
.
post
(
'/authreg'
,
auth_on_register
);
server
.
post
(
'/authpub'
,
auth_on_publish
);
server
.
post
(
'/authpub'
,
auth_on_publish
);
server
.
post
(
'/authsub'
,
auth_on_subscribe
);
server
.
post
(
'/authsub'
,
auth_on_subscribe
);
server
.
post
(
'/onsub'
,
(
req
,
res
,
next
)
=>
{
console
.
log
(
req
.
body
)
res
.
send
(
''
)
})
server
.
post
(
'/ondeliver'
,
on_deliver
)
server
.
post
(
'/ondeliver'
,
on_deliver
)
server
.
post
(
'/onpub'
,
on_publish
)
server
.
post
(
'/onpub'
,
on_publish
)
server
.
post
(
'/signRole'
,
signRole
)
server
.
post
(
'/signRole'
,
signRole
)
...
...
authhook/on_deliver.js
View file @
3d0afcba
function
on_deliver
(
req
,
res
,
next
)
{
function
on_deliver
(
req
,
res
,
next
)
{
var
topics
=
beDesireTopic
(
req
.
body
.
topic
)
var
topics
=
beDesireTopic
(
req
.
body
.
topic
)
console
.
log
(
'----on_deliver-----'
)
console
.
log
(
req
.
body
)
console
.
log
(
topics
)
var
response
=
{
var
response
=
{
'result'
:
'ok'
,
'result'
:
'ok'
,
'modifiers'
:
{
'modifiers'
:
{
...
...
authhook/on_publish.js
View file @
3d0afcba
...
@@ -14,7 +14,7 @@ module.exports = function(options={}) {
...
@@ -14,7 +14,7 @@ module.exports = function(options={}) {
console
.
log
(
'on_publish-------------'
);
console
.
log
(
'on_publish-------------'
);
console
.
log
(
req
.
body
);
console
.
log
(
req
.
body
);
}
}
console
.
log
(
req
.
body
)
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
;
...
...
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