title: Microsoft Live authorization GET request returns Net::HTTPBadRequest 400
body: <p>I am following <a href="https://msdn.microsoft.com/en-us/library/office/dn631818.aspx#authcodegrant" rel="nofollow">Microsoft live connect API documentation</a> to authorize my user to access onedrive. I am trying to stablish code flow authentication. I got the <code>AUTHORIZATION_CODE</code> as described. Now, I am trying to get the <code>ACCESS_TOKEN</code> with the help of that:</p>
  
  <p>In <a href="https://msdn.microsoft.com/en-us/library/office/dn631818.aspx#authcodegrant" rel="nofollow">Microsoft live connect API documentation</a>, its said for getting <code>ACCESS_TOKEN</code> we need to provide a request such as,</p>
  
  <pre><code>POST https://login.live.com/oauth20_token.srf
  
  Content-type: application/x-www-form-urlencoded
  
  client_id=CLIENT_ID&amp;redirect_uri=REDIRECT_URI&amp;client_secret=CLIENT_SECRET&amp;
            code=AUTHORIZATION_CODE&amp;grant_type=authorization_code      
  </code></pre>
  
  <p>I provided the same request using ruby and got a error:</p>
  
  <pre><code>#&lt;Net::HTTPBadRequest 400 Bad Request readbody=true&gt;
  </code></pre>
  
  <p>Then I found in <a href="https://social.msdn.microsoft.com/Forums/onedrive/en-US/4f6aaeda-2bac-4d1c-8898-e99725526fdb/getting-status-code-400-bad-request-error-from-oauth20tokensrf-during-authorization-code-grant?forum=messengerconnect" rel="nofollow">microsoft forum</a>, that the request is GET not POST.
  so, I created a GET request in ruby as follow:</p>
  
  <pre><code>access_code =params["code"]
  uri = URI.parse("https://login.live.com/oauth20_token.srf")
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true if uri.scheme == 'https'
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE  
  http.read_timeout = 500
  req = Net::HTTP::Get.new("https://login.live.com/oauth20_token.srf", 
                           initheader = {'Content-Type' =&gt;'application/x-www-form-urlencoded'})        
  data = URI.encode_www_form({'client_id'=&gt; 'my_client_id' , 
                           'redirect_uri' =&gt;'my_redirect_url', 
                           'client_secret' =&gt;'my_client_secret', 
                           'code'=&gt;access_code, 'grant_type' =&gt;'authorization_code'})
  req.body = data
  res = http.start { |http| http.request(req) }
  </code></pre>
  
  <p>When I run this I am getting the same HTTPBadRequest 400 error.</p>
  
  <p>Note: I have checked the values of <code>CLIENT_ID,REDIRECT_URI,CLIENT_SECRET,AUTHORIZATION_CODE</code> it's all perfect.</p>