title: Trying to Authenticate with Google OAuth and get error "Required parameter is missing: grant_type"
body: <p>I am trying to create a Node.js authentication service to authenticate with the Google OAuth api.</p>
  
  <p>I have this code:</p>
  
  <pre><code>private exchangeTokens(code: string): Rx.Observable&lt;IAuthTokens&gt;{
  
      code = decodeURIComponent(code);
  
      console.log(`exchanging code for tokens: ${code}`);
  
      const redirectUri = "http://localhost:8080";
  
      let url = YouTubeAuthenticationServer.baseUrl + "token";
  
      var postData= "code=" + encodeURIComponent(code);
      postData += "&amp;redirect_uri=" + encodeURIComponent(redirectUri);
      postData += "&amp;client_id=" + encodeURIComponent(process.env.CLIENT_ID);
      postData += "&amp;client_secret=" + encodeURIComponent(process.env.CLIENT_SECRET);
      postData += "&amp;scope=";
      postData += "&amp;grant_type=authorization_code";
  
      return this.makePostRequest&lt;IAuthTokens&gt;(url,postData);
  }
  
  private makePostRequest&lt;T&gt;(targetUrl:string, data: string): Rx.Observable&lt;T&gt;{
  
      console.log(`getting targetUrl: ${targetUrl}`);
  
      var urlObject = url.parse(targetUrl);
  
      var options: http.RequestOptions = {
          hostname: urlObject.hostname,
          port: Number(urlObject.port),
          path: urlObject.path,
          protocol: "https:",
          method: "POST"
      };
  
      const request = https.request(options);
  
      const returnObservable = Rx.Observable.fromEvent(&lt;any&gt;request, "response")
          .take(1)
          .flatMap( response =&gt; RxNode.fromWritableStream(&lt;any&gt;response))
          .do( data =&gt; console.log(`data pumped: ${data}`) )
          .toArray()
          .map(function(allData){
              return JSON.parse(allData.join("")) as T;
          });
  
      console.log(`write data: ${data}`);
  
      request.write(data);
      request.end();
  
      return returnObservable;
  }
  </code></pre>
  
  <p>and from this I get the following logs:</p>
  
  <pre><code>exchanging code for tokens: 4/k6Pp7jCPDms2meo0qfINqs0c9FZSjJ7PvGp8mdnh3Y8#
  getting targetUrl: https://accounts.google.com/o/oauth2/token
  write data: code=4%2Fk6Pp7jCPDms2meo0qfINqs0c9FZSjJ7PvGp8mdnh3Y8%23&amp;redirect_uri=http%3A%2F%2Flocalhost%3A8080&amp;client_id=myCorrectId&amp;client_secret=myCorrectSecret&amp;scope=&amp;grant_type=authorization_code
  data pumped: {
    "error" : "invalid_request",
    "error_description" : "Required parameter is missing: grant_type"
  }
  </code></pre>
  
  <p>So I am sending the following:</p>
  
  <pre><code>code=4%2Fk6Pp7jCPDms2meo0qfINqs0c9FZSjJ7PvGp8mdnh3Y8%23
  redirect_uri=http%3A%2F%2Flocalhost%3A8080
  client_id=myCorrrectId
  client_secret=myCorrectSecret
  scope=
  grant_type=authorization_code
  </code></pre>
  
  <p>So I can't understand why it is saying that I am not sending grant_type</p>