Merge branch 'separate-routers' into improve-folder-structure

This commit is contained in:
Daniel García Aubert
2018-04-10 16:15:49 +02:00
16 changed files with 1110 additions and 54 deletions
@@ -79,7 +79,7 @@ function authorizedByAPIKey ({ authBackend, action, label }) {
return function authorizedByAPIKeyMiddleware (req, res, next) {
const { user } = res.locals;
authBackend.authorizedByAPIKey(user, res, (err, authenticated) => {
authBackend.authorizedByAPIKey(user, res, (err, authenticated, apikey) => {
if (err) {
return next(err);
}
@@ -91,6 +91,15 @@ function authorizedByAPIKey ({ authBackend, action, label }) {
return next(error);
}
if (apikey.type !== 'master') {
const error = new Error('Forbidden');
error.type = 'auth';
error.subtype = 'api-key-does-not-grant-access';
error.http_status = 403;
return next(error);
}
next();
});
};