Commit 6667b003 by zCaesar

delete chk role file

parent 539268ab
var jwt = require('jsonwebtoken')
var config = require('config')
var getExp = require('./utils/getDates').getExp
module.exports.checkRealDB = checkRealDB
module.exports.getRole = getRole
module.exports.signRole = signRole
function checkRealDB(token) {
const verifyOptions = {
algorithms: ['ES256']
};
try {
return jwt.verify(token, config.get('pubca'), verifyOptions)
}
catch(e) {
return false
}
}
function getRole(token) {
var secret = 'nexpie'
try {
return jwt.verify(token, secret)
}
catch(e) {
return false
}
}
function signRole(req, res) {
var secret = 'nexpie'
if (req.body.scope && req.body.exp) {
const signOptions = {
expiresIn: getExp(req.body.exp)
}
var payload = req.body
delete payload['exp']
res.send(jwt.sign(payload, secret, signOptions))
}
else {
res.send('role not complete')
}
}
\ No newline at end of file
...@@ -15,7 +15,6 @@ var auth_on_subscribe = require('./auth_on_subscribe')({ debug: auth_on_subscrib ...@@ -15,7 +15,6 @@ var auth_on_subscribe = require('./auth_on_subscribe')({ debug: auth_on_subscrib
var on_publish = require('./on_publish')({ debug: on_publish_debug }); var on_publish = require('./on_publish')({ debug: on_publish_debug });
var on_deliver = require('./on_deliver')({ debug: on_deliver_debug }); var on_deliver = require('./on_deliver')({ debug: on_deliver_debug });
var on_unsubscribe = require('./on_unsubscribe')({ debug: on_unsubscribe_debug }); var on_unsubscribe = require('./on_unsubscribe')({ debug: on_unsubscribe_debug });
var signRole = require('./checkClientRole').signRole
const server = restify.createServer({ const server = restify.createServer({
name: 'authhook', name: 'authhook',
...@@ -45,7 +44,6 @@ server.post('/onsub', (req,res,next) => { ...@@ -45,7 +44,6 @@ server.post('/onsub', (req,res,next) => {
server.post('/onunsub', on_unsubscribe) server.post('/onunsub', on_unsubscribe)
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.listen(port, function () { server.listen(port, function () {
console.log('%s listening at %s', server.name, server.url); console.log('%s listening at %s', server.name, server.url);
......
module.exports.getExp = getExp
function getExp(expires) {
var exp
if (expires.endsWith('y')) {
exp = getYears(expires.split('y')[0])
}
else if (expires.endsWith('m')) {
exp = getMonths(expires.split('m')[0])
}
else if (expires.endsWith('d')) {
exp = expires.split('d')[0] + 'd'
}
else if (expires.endsWith('h')) {
exp = expires.split('h')[0] + 'h'
}
else if (expires.endsWith('mi')) {
exp = getMinutes(expires.split('mi')[0])
}
else if (expires.endsWith('s')) {
exp = getSeconds(expires.split('s')[0])
}
else exp = getYears(10)
return exp
}
function getMonths(d) {
return (d * 30) + 'd'
}
function getYears(m) {
return (m * 30 * 12) + 'd'
}
function getMinutes(mi) {
return (mi * 1000 * 60) + 'ms'
}
function getSeconds(ms) {
return (ms * 1000) + 'ms'
}
\ No newline at end of file
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