Windshaft-cartodb/lib/api/middlewares/authorize.js

22 lines
557 B
JavaScript
Raw Normal View History

'use strict';
2018-04-10 00:08:56 +08:00
module.exports = function authorize (authBackend) {
2018-03-01 02:21:44 +08:00
return function authorizeMiddleware (req, res, next) {
2018-04-10 00:08:56 +08:00
authBackend.authorize(req, res, (err, authorized) => {
req.profiler.done('authorize');
if (err) {
return next(err);
}
if(!authorized) {
err = new Error("Sorry, you are unauthorized (permission denied)");
err.http_status = 403;
return next(err);
}
return next();
});
};
};