尝试为 coinbase 设置分离的 oauth,令牌请求代码失败

Trying to set up decoupled oauth for coinbase, code for token request failing

我已经坚持了很长一段时间,我正在为 coinbase 做分离的 oauth2 并且一切正常,除了当我获得令牌交换代码时。我的一个 rails 控制器

中有以下代码行
@coinbase_user_token =   HTTParty.post("https://api.coinbase.com/oauth/token/",
        :headers => {"Accept" => "application/json"}, 
        :query => { 
            "grant_type" => "authorization_code",
            "code" => params["code"],
            "client_id" => ENV["COINBASE_KEY"],
            "client_secret" => ENV["COINBASE_SECRET"],
            "redirect_uri" => "http://fuf.me:3000/api/coinbase/token-callback"
        }
    )

每当我发送此消息时,我都会收到以下回复

"error"=>"invalid_grant",
"error_description"=>"The provided authorization grant is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client."}

我还尝试更改请求以模拟他们在其网站上的 curl 请求

        @coinbase_user_token = HTTParty.post("https://api.coinbase.com/oauth/token/",
        :headers => {"Accept" => "application/x-www-form-urlencoded"}, 
        :data => "grant_type=authorization_code&code=" + params["code"] + "&client_id=" + ENV["COINBASE_KEY"] + "&client_secret=" + ENV["COINBASE_SECRET"] + "&redirect_uri=http://fuf.me:3000/api/coinbase/token-callback" 
    )

但这会导致相同的响应。任何关于我可能做错的事情或其他方法的帮助将不胜感激!

这可能只需更改

即可解决
:query => {

:body => {

我不熟悉 HTTParty,但 similar answers 建议这会将参数放在 POST 正文中,而不是查询字符串中。

For Coinbase Wallet API endpoints, you can pass arguments in your requests, as params, form data or JSON with correct Content-Type header.

- (ref)