title: Retrieve authorization code from Redirect URL
body: <p>I am trying to use the Destiny 2 API and retrieve information that is sent from their API and being new to OAuth2 retrieving the authorization code is where I have hit a wall.</p>
  <p>I have this code:</p>
  <pre><code>async function get(url, callback) {
  
      var clientID = process.env.BUNGIE_CLIENTID;
      var authorizationCode = 'CODE_GOES_HERE';
  
      var xhr = new XMLHttpRequest();
  
      xhr.open(&quot;POST&quot;, &quot;https://www.bungie.net/Platform/App/OAuth/Token/&quot;, true);
      xhr.setRequestHeader(&quot;X-API-Key&quot;, process.env.BUNGIE_API);
      xhr.setRequestHeader(&quot;Content-Type&quot;, &quot;application/x-www-form-urlencoded&quot;);
      xhr.send(&quot;client_id=&quot;+ clientID + &quot;&amp;grant_type=authorization_code&amp;code=&quot; + authorizationCode);
  
      xhr.onreadystatechange = function () {
         callback.apply(xhr);
      }
  };
  </code></pre>
  <p>which will send me the access token required to access certain information in the Destiny API. However, with this code I will have to manually retrieve the authorization code from a redirect URL when a user approves my application, which will not cut it. The destiny API documentation if vague, like many other sources on OAuth2, stating &quot;get the authorization code&quot;.</p>
  <p>From what I have learnt the user will approve the application and then be redirected to a redirect URL with</p>
  <p>&quot;?code={authorization code}&quot;</p>
  <p>appended onto the end of the URL. I do not know where to start on getting this code from the URL. I believe a server will be need, which can be set up, but other than that I don’t know where to start.</p>