Frage

Using Nodejs and Mikeal's Request to make this call. Doing everything the docs are saying to do here including the grant_type=authorization_code but I still keep getting the same error. See screenshot for the exact variables and methods I'm passing.

Screenshot of error

Here's what the path looks like with grant_type explicitly set first

/o/oauth2/token?grant_type=authorization_code&code=4%2F42sz3xxq4wGF9k9joYxRVop9mHi6.UpFaIUqZ_UQaaDn_6y0ZQNh869DgiwI&client_id=199079322117.apps.googleusercontent.com&client_secret=...&redirect_uri=...
War es hilfreich?

Lösung

Turns out sending the redirect uri in the initial oauth request is needed for it to have something to match against when exchanging the tokens.

Posted my answer here explaining how I ended having to build my own oauth user flow with a popup (instead of redirecting the user in the main app) Node Google OAuth2 redirect_uri_mismatch

Andere Tipps

Yeah I know its a very old question but I faced the same problem today.
and resolved the  issue as follow. 
if you use form option it will automatically set content type
appticationx-ww-orm-urtencoded



  var request = require('request');
  request.post('https://accounts.google.com/o/oauth2/token',
      {
          form: {
              code: authorization code, // which you get from google 
              client_secret: 'client secret',// its your app secret
              client_id: 'client id', //app client id
              grant_type: 'authorization_code',
              redirect_uri: 'https://developers.google.com/oauthplayground' //this should match the redirect uri which you give while creating the client id
          }
     },function(err,res,body){
         console.log(body);
         if(err) console.log(err);
         //console.log(res);
     });
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top