2017-08-07 22 views
1

私はExpress JSとNode JSを初めて使用しています。ミドルウェア中に投稿リクエストを作成する

私は私が要求

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() 
}) 

を作るためにhttps://github.com/ranm8/requestifyを使用してい 手動エクスプレスミドルウェアで認証サーバーを実装する予定私はトークンをユーザーに確認し、うまくauth_codeを受け取ることができます。しかし、私はここにどのようにNodeJS、Epxress仕事、または範囲のいくつかの種類を理解

逃すように思え

認証ユーザにポストの要求を行うことにより、ログインしているユーザーのうち、トークンをしてください要求することはできません私を助けて!ありがとうございます

答えて

0

あなたが得ているエラーは何ですか?私の悪いこの

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 
}); 
0

のようなエラーハンドラを追加し、私はそれが動作するようになりまし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); 
    }) 

を使用する必要があります! ありがとうございました

関連する問題