我知道已经有类似的问题,但所有答案大多是“哦,我忘了在末尾加上斜线”但这绝对让我发疯。我试图从 Spotify API 获取访问 token ,但我一直收到无效的重定向 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://删除了搜索通配符,但我无法摆脱这个错误...感谢任何帮助。
最佳答案
经过一些重构后,我自己也遇到了同样的问题,我自己都快疯了。 post 请求中的 redirect_uri
必须与来自客户端的第一个 redirect_uri
相同。来自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.
关于javascript - Spotify 白名单 URI 仍然返回 { "error": "invalid_grant", "error_description": "Invalid redirect URI"},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50191422/