我正在研究express js,在传入的POST请求中,用户名和密码存在于请求的正文中,我想实现路由,以便可以将授权头添加到传入的req对象
我的路由如下:
router.route('/token')
.post(function(req,res,next){
if(req.body.client_id){
//set headers for authentication, e.g "Authorization":"Basic dskvnksnsnjsnvsnlvnsd"
next();
}
},authController.isClientAuthenticated,oauth2Controller.token);
您可以使用req.headers
属性添加标题:req.headers.authorization = 'Basic ...'
注意,有一个res.headersSent
属性,它可以用来确定是否已经发送到客户端,否则你会遇到一个错误。