Authorization code flow: get access token error invalid client_id
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page