title: Spotify Web API Bad Request Error "invalid_client" when refreshing token
body: <p>I'm building an app in Rails using the Spotify web API. I built a method to refresh a user's token, but am receiving a 400 error. According the the Spotify Web API docs, the header of my request needs to be in the following format:</p>
  
  <pre><code>Authorization: Basic &lt;base64 encoded client_id:client_secret&gt;
  </code></pre>
  
  <p>Using Httparty gem, here's the POST method to refresh the access token:</p>
  
  <pre><code>def refresh_token
  client_id = "foo"
  client_secret = "bar"
  client_id_and_secret = Base64.encode64("#{client_id}:#{client_secret}")
  result = HTTParty.post(
      "https://accounts.spotify.com/api/token",
      :body =&gt; {:grant_type =&gt; "refresh_token",
                :refresh_token =&gt; "#{self.oauth_refresh_token}"},
      :headers =&gt; {"Authorization" =&gt; "Basic #{client_id_and_secret}"}
      )
  end
  </code></pre>
  
  <p>Here's what "result" ends up being:</p>
  
  <pre><code>=&gt; #&lt;HTTParty::Response:0x7f92190b2978 parsed_response={"error"=&gt;"invalid_client", "error_description"=&gt;"Invalid client secret"}, @response=#&lt;Net::HTTPBadRequest 400 Bad Request readbody=true&gt;, @headers={"server"=&gt;["nginx"], "date"=&gt;["Sun, 31 Aug 2014 22:28:38 GMT"], "content-type"=&gt;["application/json"], "content-length"=&gt;["70"], "connection"=&gt;["close"]}&gt;
  </code></pre>
  
  <p>I can decode client_id_and_secret and it returns "foo:bar", so I'm at a loss as to why I'm receiving a 400 error. Any insight is much appreciated. </p>