title: Not able to redirect to client side with token from server(express) side route
body: <p>I am using 'googleapis' npm package to do token based google authentication.
  I am redirected to '/api/auth/success/google' route inside express after google provided authentication and redirects us to the uri stated in google app credentials.</p>
  
  <p>The problem I am facing is that ,I have retrieved the tokens on server side,but I am unable to send those tokens to client side for them to be saved in cookies.</p>
  
  <p>The problem I am facing is because,'/api/auth/success/google' is redirected from google side and not an ajax call from client side.So if I send the tokens back in res,where will it redirect.Also please suggest a way to redirect from server side to client side,along with access_token.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>server side code.
  
  //Route reached after google successful login/authentication
  
  app.get('/api/auth/success/google',function(req,res){
    console.log("inside redirect");
    var code = req.query.code;
    oauth2Client.getToken(code, function(err, tokens) {
      // Now tokens contains an access_token and an optional refresh_token. Save them.
      if(!err) {
        oauth2Client.setCredentials(tokens);
      }
      res.sendFile('./index.html');
    });
  })
  
  
  Client side call
  
  //Google login requested from this function
  
  googleLogin(){
      event.preventDefault();
      $.ajax({
        type : 'POST',
        url : baseURL + 'api/authenticate/google',
        success: (function(data) {
          if (data.redirect) {
              document.location.href = data.redirect;
          }
  
        }).bind(this)
      });
    } 
  
  //Route handling request of google access
  
  app.post('/api/authenticate/google',function(req,res){
  
    // generate a url that asks permissions for Google+ and Google Calendar scopes
    var scopes = [
      googlecredentials.SCOPE[0],
      googlecredentials.SCOPE[1]
    ];
  
    var url = oauth2Client.generateAuthUrl({
      access_type: 'offline', // 'online' (default) or 'offline' (gets refresh_token)
      scope: scopes // If you only need one scope you can pass it as string
    });
    res.send({ redirect: url });
  })
  
  //Google App Credentials
  
  var OAuth2 = google.auth.OAuth2;
  var oauth2Client = new OAuth2(googlecredentials.CLIENT_ID, googlecredentials.CLIENT_SECRET, googlecredentials.REDIRECT_URL);
  
  
  googlecredentials.CLIENT_ID - 858093863410-j9ma1i7lgapupip1ckegc61plrlledtq.apps.googleusercontent.com
  
  REDIRECT_URL - http://localhost:3000/api/auth/success/google  where localhost:3000 runs server side </code></pre>
  </div>
  </div>
  </p>