Reputation: 408
I know there are already questions similar to this but all of the answers are mostly "Oh I forgot to put the slash at the end" But this is absolutely driving me crazy. Im trying to get an access token from Spotify API but i keep getting the invalid redirect uri error.
Here is my api call
const request = require('superagent');
const data = {
grant_type: 'authorization_code',
code: code,
// redirect_uri: encodeURIComponent('http://localhost:3000/Test')
redirect_uri: 'http://localhost:3000/Test'
};
request.post('https://accounts.spotify.com/api/token')
.set({
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Basic ' + base64.encode(configs.client_id + ':' + configs.client_secret)
})
.send(data)
.end((err, tokenRes) => {
if (tokenRes) {
res.send({token: tokenRes})
} else {
res.error(err);
}
});
and these are the URIs I have whitelisted:
http://localhost:3000/LoginRedirect
I added so many combinations to the whitelist with slashes at the end, http:// s removed searched for wildcards but i cant get rid of this error... Any help is appreciated.
Upvotes: 10
Views: 6331
Reputation: 318
Ran into the same problem myself after some refactoring, and was going insane myself. The redirect_uri
in the post request has to be the same as the first redirect_uri
from the client side. From the Spotify docs:
Required. This parameter is used for validation only (there is no actual redirection). The value of this parameter must exactly match the value of redirect_uri supplied when requesting the authorization code.
Upvotes: 18