title: Google authentication with nodejs
body: <p>I'm trying to reach Google authentication API with my node.js server but I just can't find how. Basically, I want the user to arrive on my login page, click on the authentication button, then the server redirects him to the Google API, the user allows my app to access his data and then the Google API redirects the user to my site with the authorization token.</p>
  <p>I've set up the url required by oauth2 and it seems to work (if I paste it in my web browser, it redirects me on google authorization page). I saw <a href="https://stackoverflow.com/questions/6234380/nodejs-redirect-url">this post</a> which seemed to answer my question but I don't how to handle the express code part.</p>
  <p>Here is the code I'm using :</p>
  <pre><code>https.get(options, function(res) {
      var retrieved_data = '';
      res.on('data', function(data) { retrieved_data += data; });
      res.on('end', function() { 
          // FIXME
          client_response.writeHead(302, {&quot;Content-Type&quot; : &quot;text/plain&quot;, &quot;Location&quot; : res.headers.location});
          client_response.end(retrieved_data);    
      });
  });
  </code></pre>
  <p>But this method returns an error on my client page (raised by the error field of my ajax request). If I change the HTTP code to 200 without the &quot;Location&quot; information, it displays on the client a &quot;Moved Temporarily&quot; page with a button which redirects me to Google API authorization page.</p>
  <p>Any suggestion ?</p>