最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Spotify Whitelisted URI still returns { "error": "invalid_grant", "err

programmeradmin1浏览0评论

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 badges
Add a comment  | 

1 Answer 1

Reset to default 18

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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论