0

Google oauth api を使用して自分の Web サイトにログインしようとしています。HTTP リクエストを使用していますが、302 http コード (リダイレクト/一時的に移動) を受け取り、何をどのように行うべきかわかりません。新しい場所で別の http リクエストを作成する必要があると思いますが、それを取得する方法がわかりません。

ここに私が使用しているコアがあります:

var redirectUri = encodeURIComponent("http://localhost:3000/user/login/oauth2"); 
var clientId = "322263763991.apps.googleusercontent.com";
var clientSecret = "********************";

var dataPath    = "/o/oauth2/token"
                            + "?code="                  + cod 
                            + "&client_id="         + clientId 
                            + "&client_secret=" + clientSecret 
                            + "&redirect_uri="  + redirectUri 
                            + "&grant_type=authorization_code";

var options = {
      host: 'accounts.google.com',
      path: dataPath,
      method: 'POST'
    };

    var req = http.request(options, function(res) {

      console.log('STATUS: ' + res.statusCode);
      console.log('HEADERS: ' + JSON.stringify(res.headers));
      res.setEncoding('utf8');
      res.on('data', function (chunk) {
        console.log('X_BODY: ' + chunk);
      });
    });

    req.on('error', function(e) {
      console.log('problem with request: ' + e.message);
    });

    req.write('data\n');
    req.write('data\n');
    req.end();
4

0 に答える 0