title: Google Drive OAuth 2.0 Invalid grant_type
body: <p>Following the example from <a href="https://developers.google.com/identity/protocols/OAuth2WebServer" rel="nofollow noreferrer">OAuth2WebServer</a> from google I'm trying to set up an authentication flow from an express app using the HTTP/REST method they have but with every request I am returned with an error</p>
  
  <p>I went through <a href="https://blog.timekit.io/google-oauth-invalid-grant-nightmare-and-how-to-fix-it-9f4efaf1da35" rel="nofollow noreferrer">Google OAuth “invalid_grant” nightmare — and how to fix it</a> but unfortunately it did not help.</p>
  
  <pre><code>{
    error: "unsupported_grant_type",
    error_description: "Invalid grant_type: "
  }
  </code></pre>
  
  <p>This is a shortened version of the error I am receiving. If you need to see more of the error let me know and I can post it.</p>
  
  <h2>Server</h2>
  
  <pre><code>const express = require('express');
  const axios = require('axios');
  
  const { web } = require('./src/client_id.json');
  
  const app = express();
  const { client_id, client_secret } = web;
  
  let count = 0;
  
  app.use(express.json());
  
  /*************************
  ** REDIRECT USER TO GOOGLE AUTH **
  *************************/
  app.get('/', (req, res) =&gt; {
    const redirect_uri = 'http://localhost:5000/auth';
    const scope = 'https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive.metadata.readonly';
    const access_type = 'offline';
  
    res.redirect(`https://accounts.google.com/o/oauth2/v2/auth?scope=${ scope }&amp;access_type=${ access_type }&amp;redirect_uri=${ redirect_uri }&amp;response_type=code&amp;client_id=${ client_id }`);
  });
  
  /*************************
  ** ON AUTH WE EXCHANGE ACCESS TOKEN FOR REFRESH TOKEN **
  *************************/
  app.get('/auth', (req, res) =&gt; {
    count++;
  
    if (count &gt;= 2) {
      return res.redirect('http://localhost:3000');
    }
  
    const { code } = req.query;
    const redirect_uri = 'http://localhost:5000/auth';
    const grant_type = 'authorization_code';
  
    axios.post('https://www.googleapis.com/oauth2/v4/token', {
      code,
      client_id,
      client_secret,
      redirect_uri,
      grant_type
    }, {
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
      }
    })
      .then(data =&gt; {
        console.log(data)
        res.redirect('http://localhost:3000');
      })
      // ALWAYS HITS THE CATCH "Invalid grant_type"
      .catch(err =&gt; {
        console.log(err);
        console.log('ERROR')
      });
  });
  
  app.listen(5000, console.log('Server listening on port 5000'));
  </code></pre>