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

20 lines
513 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) => {
if (err) {
return next(err);
}
2019-10-22 01:07:24 +08:00
if (!authorized) {
err = new Error('Sorry, you are unauthorized (permission denied)');
err.http_status = 403;
return next(err);
}
return next();
});
};
};