title: Invalid redirect_uri in request Discord Oauth2
body: <p>I looked at other problems like mine, for example <a href="https://stackoverflow.com/questions/66926061/discord-oauth2-token-method-return-invalids-redirect-uri">this one</a> or <a href="https://stackoverflow.com/questions/60093082/issue-with-discord-oauth2-redirect-uri-component">this one</a>. But the problems are because the URIs used aren't in the Redirect URIs in Discord OAuth2 config, and I checked them several times.</p>
  <p>I have the following code:</p>
  <pre class="lang-js prettyprint-override"><code>import querySring from 'query-string'
  
  // I'm using React Router for this
  const code = searchParams.get('code')
  
  if (!code) return
  
  const data = {
        'client_id': 'my client id',
        'client_secret': 'my client secret',
        'grant_type': 'authorization_code',
        'code': code,
        'redirect_uri': querySring.stringifyUrl({ url: 'http://localhost:3000/login/callback' }),
  }
  
  const strData = querySring.stringify(data)   
  
  const headers = {
        'Content-Type': 'application/x-www-form-urlencoded'
  }
  
  fetch('https://discord.com/api/oauth2/token', {
        method: 'POST',
        headers,
        body: strData,
  })
    .then(res =&gt; res.json())
    .then(console.log)
  </code></pre>
  <p>And I get the following error:</p>
  <pre class="lang-js prettyprint-override"><code>error: &quot;invalid_request&quot;,
  error_description: &quot;Invalid \&quot;redirect_uri\&quot; in request.&quot;
  </code></pre>
  <p>Of course, I made sure of having this redirect uri in the Discord Developer Portal:
  <a href="https://i.stack.imgur.com/5migL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5migL.png" alt="Redirect urls config" /></a></p>
  <p>I also tried using:</p>
  <pre class="lang-js prettyprint-override"><code>const data = {
      // ...
      'redirect_uri': 'http://localhost:3000/login/callback'
  }
  </code></pre>
  <p>But nothing, I can't find what is wrong.</p>