我是Express JS和Node JS的新手。在中间件中发布POST请求
我打算实现快速中间件auth服务器手动 我使用https://github.com/ranm8/requestify发出请求
const requestify = require('requestify');
app.use(function (req, res, next) {
var config = require('./config-' + process.env.REACT_APP_ENV)
var redirect = config.ADMIN_UI_URL
// Perform login to Auth-Server
if (req.originalUrl.startsWith('/?code')) {
let auth_code = req.query.code
let params = {
'grant_type': 'authorization_code',
'code': auth_code,
'client_id': config.OAUTH_CLIENT_ID,
'redirect_uri': redirect
}
requestify.post(config.OAUTH_ID_URL+'/oauth2/token', params).then(function(response) {
console.log(response.getBody()); // There is not data post to the Auth-Server
});
return res.redirect('http://google.com');
}
// Check Token
if (req.cookies._token === undefined) {
let url = config.OAUTH_ID_URL + '/oauth2/authorize?' + 'response_type=code' + '&' + 'client_id=' + config.OAUTH_CLIENT_ID + '&' + 'redirect_uri=' + redirect
return res.redirect(url)
}
next()
})
,我可以检查用户令牌和收到AUTH_CODE就好了。但我不能做一个POST请求,以验证用户
好像我错过了解的NodeJS,Epxress工作,或某种范围的这里
请申请一个令牌了登录用户的帮帮我!谢谢