Я новичок в Express JS и Node JS.
Я намереваюсь внедрить Auth-Server в Express Middleware вручную, я использую 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 просто отлично. Но я не могу запросить токен из зарегистрированного пользователя, сделав почтовый запрос Auth-User
Кажется, я скучаю, понимаю, как работают NodeJS, Epxress, или какая-то область действия здесь
Пожалуйста, помогите мне! Спасибо
Мой плохой, я должен использовать пакет https://www.npmjs.com/package/request#forms
request.post({url:config.OAUTH_ID_URL+'/oauth2/token', form: bodyData},
function(err,httpResponse,body){
console.log(err);
console.log(body);
})
Он работает сейчас !!! Спасибо
Попробуйте проверить, какая ошибка вы получаете. добавить обработчик ошибок
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
}).error(function(error){
console.log(error) // see if anything is coming in error object
});