Spotify白名单URI仍会返回{“error”:“invalid_grant”,“error_description”:“无效的重定向URI”}

时间:2018-05-05 16:03:49

标签: javascript express spotify

我知道已经有类似的问题,但所有的答案大多是“哦,我忘了把斜线放在最后”但这绝对让我发疯。我试图从Spotify API获取访问令牌,但我一直收到无效的重定向uri错误。

这是我的api电话

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);
        }
    });

这些是我列入白名单的URI:

http://localhost:3000/LoginRedirect

http://localhost:3000/Test

http://localhost:3000/Home

我在白名单中添加了这么多组合,最后用斜杠,http:// s删除了搜索通配符,但我无法摆脱这个错误...感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

重构后我自己遇到了同样的问题,并且自己发疯了。发布请求中的redirect_uri必须与客户端第一个redirect_uri相同。来自Spotify docs

  

必需的。   此参数仅用于验证(没有实际的重定向)。此参数的值必须与请求授权码时提供的redirect_uri值完全匹配。

相关问题