0

我已经坚持了很长一段时间,我正在为 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" 
    )

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

4

1 回答 1

1

这可能只需通过更改即可解决

:query => {

:body => {

我不熟悉 HTTParty,但类似的答案表明这会将参数放在 POST 正文中,而不是查询字符串中。

对于 Coinbase 钱包 API 端点,您可以在请求中传递参数,作为参数、表单数据或带有正确 Content-Type 标头的 JSON。

-(参考

于 2015-12-24T00:56:12.400 回答