0
votes

I used spotify token api method with authorization code to get a token and refresh token with permissions of my user. (authorization flow)

Here is the request i made with my nodejs app (console log) :

    Request {
2017-05-18T23:16:45.861879+00:00 app[web.1]:   host: 'accounts.spotify.com',
2017-05-18T23:16:45.861879+00:00 app[web.1]:   port: 443,
2017-05-18T23:16:45.861879+00:00 app[web.1]:   scheme: 'https',
2017-05-18T23:16:45.861880+00:00 app[web.1]:   queryParameters: undefined,
2017-05-18T23:16:45.861880+00:00 app[web.1]:   bodyParameters: 
2017-05-18T23:16:45.861881+00:00 app[web.1]:    { grant_type: 'authorization_code',
2017-05-18T23:16:45.861881+00:00 app[web.1]:      redirect_uri: 'https://octave-spotify.herokuapp.com/callback',
2017-05-18T23:16:45.861884+00:00 app[web.1]:      code: 'AQASbjsig7owAPhq_ICQSAv1d6iOb0NdB1dqI0M8EQPyjNyv3Dyq4wY8QndzD_Iyykzm9f4lO5xNklltmKBlnKFko3kYeuBm_w1EBlX9_tcMpK6Pg4g-mcAbTdHrArbYJfDCV5LFt-bI5JbPXbxAnfcaHSoto2lk2p6YdQC3EC5Y5FIFBXdCkE4WeZmsPWoDLhQxIMqb8FLrao4-spPq4esE-Btqg73adXyWqU3eO-7MF3291wExc0nFeVK_vefPfH4SbXvFyxmKoHKSOM5etChalj3WMsger9FA6TrPNt5CsAMHNiczW692mfquFapjh516tIgCHzgxPbocN_1xeg6dqvNvUtZ6jjoMW4TQ1j9gAf-B3LXLjCApgSSjqjj53RppFMbF6edv74Ds' },
2017-05-18T23:16:45.861885+00:00 app[web.1]:   headers: { Authorization: 'Basic MDE1N2MxYjkwNWU5NDk2YTgzZjViOTM2M2IxNzU5ZmI6ZmJkNGNmYWZlMzNjNDczNGFjMzRjNGYyNTQyMDI2NmI=' },
2017-05-18T23:16:45.861886+00:00 app[web.1]:   path: '/api/token' }
2017-05-18T23:16:45.934575+00:00 app[web.1]: Something went wrong authorizationCodeGrant! { [WebapiError: Bad Request] name: 'WebapiError', message: 'Bad Request', statusCode: 400 }

The return expected was a token and refresh token, but i get an api error 400 bad request. I checked my client_id, secret_id and redirect_uri, they seems all good.

Do you have any idea what is the problem ? Thank you for your help.

1

1 Answers

2
votes

Try moving your body parameters to query parameters:

The authorization process starts with your application sending a request to the Spotify Accounts service. (The reason your application sends this request can vary: it may be a step in the initialization of your application or in response to some user action, like a button click.) The request is sent to the /authorize endpoint of the Accounts service:

GET https://accounts.spotify.com/authorize The request will include parameters in the query string:

A typical request looks like this:

GET https://accounts.spotify.com/authorize/?client_id=5fe01282e44241328a84e7c5cc169165&response_type=code&redirect_uri=https%3A%2F%2Fexample.com%2Fcallback&scope=user-read-private%20user-read-email&state=34fFs29kd09