ruby - 使用 Spotify 客户端 ID 和 secret 返回无效客户端的 Curl 发布请求

标签 ruby authentication curl encoding base64

我正在关注 Spotify 的 client credentials authorization flow ,但我所有的curl请求都返回{"error":"invalid_client"}每一次。以下是 Spotify 的说明:

The request will include parameters in the request body:

  • grant_type - Set to “client_credentials”.

The header of this POST request must contain the following parameter:

  • Authorization - A Base 64 encoded string that contains the client ID and client secret key. The field must have the format: Authorization: Basic <base64 encoded client_id:client_secret>

它们还包括一个curl请求的示例:

$ curl -H "Authorization: Basic ZjM4ZjAw...WY0MzE=" -d grant_type=client_credentials https://accounts.spotify.com/api/token

按照他们的示例,到目前为止,我已经尝试过使用以下命令进行 curl 请求:

  • client_id 和 client_secret 纯文本
  • 两者都是单独编码的
  • 仅使用其中之一进行编码
  • 两者都编码为带冒号的一个字符串
  • 两者都编码为一个字符串,不带冒号
  • 上述每一项都带有重新生成的客户端 key

我正在使用 Ruby 的 Base64#encode64方法进行编码。还是没有运气。有什么有用的提示吗?

最佳答案

好的,我开始工作了 - 将我的 client_id 和 client_secret(用冒号分隔)传递给 Base64.strict_encode64 (不是 Base64.encode64),然后将其传递给上面的curl请求得到带有访问 token 的200响应。显然 encode64 还不够。

关于ruby - 使用 Spotify 客户端 ID 和 secret 返回无效客户端的 Curl 发布请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39423464/

相关文章:

ruby-on-rails - 有没有办法通过数组将多个参数输入到方法中

ruby - 在(最新版本的)Ruby 中递增整数(使用 +=)线程安全吗?

authentication - Yesod 脚手架站点 browserId TlsException

php - 重新加载后页面变成空白

ios - 如何使用浏览器重定向创建 Facebook 风格的应用内身份验证?

php - 使用 PHP 进行安全的 SSL/HTTPS API 调用

php - PHP 的 RVM 等价物?

hadoop - 将 --negotiate 与 curl 一起使用时,是否需要 key 表文件?

json - 无法在 json --data 中使用变量

javascript - AJAX + Rails 的最新技术是什么?