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('')
.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
http://localhost:3000/Test
http://localhost:3000/Home
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.
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
http://localhost:3000/Test
http://localhost:3000/Home
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.
Share Improve this question edited May 5, 2018 at 16:23 let_the_coding_begin asked May 5, 2018 at 16:03 let_the_coding_beginlet_the_coding_begin 4085 silver badges15 bronze badges1 Answer
Reset to default 18Ran 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.