我正在将 coinbase 集成到 iOS 应用程序中,并使用 Oauth2 进行身份验证。经过通常的工作流程后,我能够获得访问令牌。每当任何请求遇到 401(过期时)时,我都会通过调用以下命令来尝试刷新我的访问令牌:
POST https://coinbase.com/oauth/token https://coinbase.com/oauth/token
Data:
grant_type=refresh_token&refresh_token=abcd1234&client_id=theclientid&client_secret=somesecretid
它可以工作一段时间,但有时会因请求响应而失败:
NSHTTPURLResponse: 0x15eb2730
{ URL: https://coinbase.com/oauth/token } { status code: 401, headers {
"CF-RAY" = "f67d477aae4052e-YYZ";
"Cache-Control" = "no-store";
Connection = "keep-alive";
"Content-Type" = "application/json; charset=utf-8";
Date = "Sun, 02 Feb 2014 15:14:14 GMT";
Pragma = "no-cache";
Server = "cloudflare-nginx";
"Set-Cookie" = "__cfduid=<some long alpha-numeric string>; expires=Mon, 23-Dec-2019 23:50:00 GMT; path=/; domain=.coinbase.com; HttpOnly";
Status = "401 Unauthorized";
"Strict-Transport-Security" = "max-age=31536000";
"Transfer-Encoding" = Identity;
Vary = "Accept-Encoding";
"Www-Authenticate" = "Bearer realm=\"Doorkeeper\", error=\"invalid_request\", error_description=\"The request is missing a required parameter, includes an unsupported parameter value, or is otherwise malformed.\"";
"X-Content-Type-Options" = nosniff;
"X-Frame-Options" = SAMEORIGIN;
"X-Rack-Cache" = "invalidate, pass";
"X-Request-Id" = "<some long alpha-numeric string>";
"X-Runtime" = "0.012066";
"X-Ua-Compatible" = "IE=Edge,chrome=1";
} }
以前有人遇到过这个错误吗?我假设请求 URL 始终是正确的。我不知道为什么它会抱怨“缺少必需的参数”或“不支持的参数”。我还没有找出失败的模式。希望那里的人以前可能见过这个。
我无法直接找到有关refresh_token请求的任何文档,但我认为您还应该在refresh_token请求中包含redirect_uri(基于此:https://coinbase.com/docs/api/authentication#collapse2 https://coinbase.com/docs/api/authentication#collapse2).
另外,我注意到我的官方 coinbase 应用程序几天前需要重新授权,但当我登录我的 coinbase 帐户时,它说该应用程序已在 25 天前获得授权。那么,也许 request_tokens 也有超时?您的 request_token 请求是否因一段时间未使用该应用而失败?
或者,Coinbase 可能会重置某些内容并使所有 access_token 和 refresh_token 无效,因为我的应用程序(之前在刷新令牌方面工作正常)现在在刷新令牌请求上失败。
因此,我建议您的应用程序在发生这种情况时重新授权,并获取新的access_token和refresh_token,因为我认为这就是官方coinbase应用程序所做的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)