2018-03-01 02:21:44 +08:00
|
|
|
module.exports = function authorize (authApi) {
|
|
|
|
return function authorizeMiddleware (req, res, next) {
|
2017-10-05 17:28:41 +08:00
|
|
|
authApi.authorize(req, res, (err, authorized) => {
|
2017-09-25 19:40:22 +08:00
|
|
|
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();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|