我已经坚持了很长一段时间,我正在为 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"
)
但这会导致相同的响应。对于我可能做错的事情或其他方法的任何帮助将不胜感激!