Announcements

Help Wizard

Step 1

NEXT STEP

FAQs

Please see below the most popular frequently asked questions.

Loading article...

Loading faqs...

VIEW ALL

Ongoing Issues

Please see below the current ongoing issues which are under investigation.

Loading issue...

Loading ongoing issues...

VIEW ALL

Authorization code flow: get access token error invalid client_id

Authorization code flow: get access token error invalid client_id

Hey guys ! 

I'm building a webapp based on Spotify API using RoR. To get the access token, I use the Autorization Code Flow process.

 

At step 2, I when make the [POST] to https://accounts.spotify.com/api/token, sending my client_id and client_secret base64 encoded, I have a 400 "Invalid client_id".
Then I tried to sending it in the headers and this time I have a 400 "Invalid authorization_code".

 

I'm a bit lost right now, your help is greatly appreciated ๐Ÿ™‚

 

 

  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

 

 

Reply
1 Reply

Shouldn't you have separated the client ID and client secret with a colon character? And why is it prefixed with a hash character?

Suggested posts

Type a product name