removed hasRole and hasAdminRole from passport_helpers
This commit is contained in:
parent
e1db98ec95
commit
3e3e7ccfe6
@ -6,7 +6,7 @@ module.exports.isAuthenticatedOrApiKey = function isAuthenticated(req, res, next
|
||||
if (req.isAuthenticated()) {
|
||||
return next();
|
||||
}
|
||||
|
||||
|
||||
// Try authenticate with API KEY
|
||||
if (req.headers.apikey || req.query.apikey || req.body.apikey) {
|
||||
passport.authenticate('localapikey', function (err, user, info) {
|
||||
@ -29,23 +29,3 @@ module.exports.isAuthenticatedOrApiKey = function isAuthenticated(req, res, next
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
module.exports.hasRole = function hasRole(roleRequired) {
|
||||
if (!roleRequired) {
|
||||
throw new Error('Required role needs to be set');
|
||||
}
|
||||
|
||||
return function(req, res, next) {
|
||||
return module.exports.isAuthenticated(req, res, function() {
|
||||
if (req.user && req.user.roles && req.user.roles.indexOf(roleRequired) !== -1){
|
||||
return next();
|
||||
}
|
||||
return res.sendStatus(403);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
module.exports.hasAdminRole = function hasAdminRole() {
|
||||
return module.exports.hasRole('admin');
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user