<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Authorization code flow: get access token error invalid client_id in Spotify for Developers</title>
    <link>https://community.spotify.com/t5/Spotify-for-Developers/Authorization-code-flow-get-access-token-error-invalid-client-id/m-p/5027638#M1051</link>
    <description>&lt;P data-unlink="true"&gt;Hey guys !&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I'm building a webapp based on Spotify API using RoR. To get the access token, I use the Autorization Code Flow process.&lt;/P&gt;&lt;P data-unlink="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;P data-unlink="true"&gt;At step 2, I when make the [POST] to&amp;nbsp;&lt;A href="https://accounts.spotify.com/api/token," target="_blank"&gt;https://accounts.spotify.com/api/token,&lt;/A&gt;&amp;nbsp;sending my client_id and client_secret base64 encoded, I have a 400 "Invalid client_id".&lt;BR /&gt;Then I tried to sending it in the headers and this time I have a 400 "Invalid authorization_code".&lt;/P&gt;&lt;P data-unlink="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;P data-unlink="true"&gt;I'm a bit lost right now, your help is greatly appreciated &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P data-unlink="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="ruby"&gt;  def get_token
    api_endpoint = 'https://accounts.spotify.com/api/token'
    encoded_auth = Base64.encode64(ENV['SPOTIFY_CLIENT'] + ENV['SPOTIFY_SECRET']).delete("\n")

    body = {
      grant_type: 'authorization_code',
      code: params['code'],
      redirect_uri: "http://localhost:3000/auth/spotify/callback",
      client_id: ENV['SPOTIFY_CLIENT'],
      client_secret: ENV['SPOTIFY_SECRET']
    }
    headers = { Authorization: "Authorization: Basic #{encoded_auth}" }

    resp = HTTParty.post(
      api_endpoint,
      headers: headers,
      body: body
    )
  end&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 01 Sep 2020 10:19:58 GMT</pubDate>
    <dc:creator>pablior</dc:creator>
    <dc:date>2020-09-01T10:19:58Z</dc:date>
    <item>
      <title>Authorization code flow: get access token error invalid client_id</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/Authorization-code-flow-get-access-token-error-invalid-client-id/m-p/5027638#M1051</link>
      <description>&lt;P data-unlink="true"&gt;Hey guys !&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I'm building a webapp based on Spotify API using RoR. To get the access token, I use the Autorization Code Flow process.&lt;/P&gt;&lt;P data-unlink="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;P data-unlink="true"&gt;At step 2, I when make the [POST] to&amp;nbsp;&lt;A href="https://accounts.spotify.com/api/token," target="_blank"&gt;https://accounts.spotify.com/api/token,&lt;/A&gt;&amp;nbsp;sending my client_id and client_secret base64 encoded, I have a 400 "Invalid client_id".&lt;BR /&gt;Then I tried to sending it in the headers and this time I have a 400 "Invalid authorization_code".&lt;/P&gt;&lt;P data-unlink="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;P data-unlink="true"&gt;I'm a bit lost right now, your help is greatly appreciated &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P data-unlink="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="ruby"&gt;  def get_token
    api_endpoint = 'https://accounts.spotify.com/api/token'
    encoded_auth = Base64.encode64(ENV['SPOTIFY_CLIENT'] + ENV['SPOTIFY_SECRET']).delete("\n")

    body = {
      grant_type: 'authorization_code',
      code: params['code'],
      redirect_uri: "http://localhost:3000/auth/spotify/callback",
      client_id: ENV['SPOTIFY_CLIENT'],
      client_secret: ENV['SPOTIFY_SECRET']
    }
    headers = { Authorization: "Authorization: Basic #{encoded_auth}" }

    resp = HTTParty.post(
      api_endpoint,
      headers: headers,
      body: body
    )
  end&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Sep 2020 10:19:58 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/Authorization-code-flow-get-access-token-error-invalid-client-id/m-p/5027638#M1051</guid>
      <dc:creator>pablior</dc:creator>
      <dc:date>2020-09-01T10:19:58Z</dc:date>
    </item>
    <item>
      <title>Re: Authorization code flow: get access token error invalid client_id</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/Authorization-code-flow-get-access-token-error-invalid-client-id/m-p/5028768#M1061</link>
      <description>&lt;P&gt;Shouldn't you have separated the client ID and client secret with a colon character? And why is it prefixed with a hash character?&lt;/P&gt;</description>
      <pubDate>Wed, 02 Sep 2020 15:37:08 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/Authorization-code-flow-get-access-token-error-invalid-client-id/m-p/5028768#M1061</guid>
      <dc:creator>kingosticks4</dc:creator>
      <dc:date>2020-09-02T15:37:08Z</dc:date>
    </item>
  </channel>
</rss>

