Homeland Ruby China API V3 获取 token 失败

hanji · 2015年06月04日 · 最后由 hanji 回复于 2015年11月23日 · 4071 次阅读

Ruby China API V3 获取 token 一直失败,HTTP 请求响应码 401,Body 如下,请问该如何解决,谢谢!

{
    "error": "invalid_client",
    "error_description": "由于未知、不支持或没有客户端,认证失败"
}

你怎么请求的

@hanji

使用 curl 获取: curl -X POST -d "grant_type=password" -d "username=[name]" -d "password=[pass]" 'https://ruby-china.org/oauth/token'

* Adding handle: conn: 0x7fd1b280aa00
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x7fd1b280aa00) send_pipe: 1, recv_pipe: 0
* About to connect() to ruby-china.org port 443 (#0)
*   Trying 61.174.15.167...
* Connected to ruby-china.org (61.174.15.167) port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384
* Server certificate: www.ruby-china.org
* Server certificate: StartCom Class 1 Primary Intermediate Server CA
* Server certificate: StartCom Certification Authority
> POST /oauth/token HTTP/1.1
> User-Agent: curl/7.30.0
> Host: ruby-china.org
> Accept: */*
> Content-Length: 70
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 70 out of 70 bytes
< HTTP/1.1 200 OK
* Server nginx/1.8.0 is not blacklisted
< Server: nginx/1.8.0
< Date: Thu, 04 Jun 2015 05:13:35 GMT
< Content-Type: application/json; charset=utf-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< Strict-Transport-Security: max-age=31536000
< X-Frame-Options: SAMEORIGIN
< X-XSS-Protection: 1; mode=block
< X-Content-Type-Options: nosniff
< Cache-Control: no-store
< Pragma: no-cache
< ETag: W/"5275890161f17844e4dffefe6e643344"
< X-Request-Id: 9d8e536c-3fb6-456e-a3b1-8f88a9799a77
< X-Runtime: 0.296195
<
* Connection #0 to host ruby-china.org left intact
{"access_token":"xxxxxxxx","token_type":"bearer","expires_in":86400,"refresh_token":"xxxxxxxxxx","created_at":1433394815}

需要 client id

#2 楼 @wppurking 为什么我尝试请求,结果如下,能麻烦再测试一下吗?谢谢!

{"error":"invalid_grant","error_description":"登录回调地址无效、过期或者已经被撤销了"}

#3 楼 @huacnlee

  1. https://ruby-china.org/oauth/authorize 获得授权码
  2. https://ruby-china.org/oauth/token POST 请求 token,结果如下。

麻烦查看一下问题在哪里,谢谢了!

#6 楼 @wppurking 有注册的,如 5L 的 client_id 就是注册应用后得到的。想问你 2L 的方式还能提交成功吗?

好像是要注意跳转地址

#8 楼 @huacnlee 5L 图中的跳转地址就是网站提示的本地测试用地址。根据错误类型,像是应用注册后没有得到审核授权,不知道找谁解决啊,感觉好无力。

#9 楼 @hanji 就是不要用那个,Doorkeeper 在这里好像是有点问题,我在开发的时候也是这样的问题

@hanji @huacnlee 貌似我现在也不行了... 返回 是使用 "urn:ietf:wg:oauth:2.0:oob" 注册的登陆回掉地址。

{"error":"invalid_grant","error_description":"登录回调地址无效、过期或者已经被撤销了"}

#10 楼 @huacnlee #11 楼 @wppurking 谢谢!参考 https://ruby-china.org/topics/14656 ,问题解决了,在发送获取 token 的 POST 请求时,需要加入 HTTP Basic Authentication Header。

设置一个不同的 redirect_uri 呢 这个 oauth:2.0:oob 是用来测试用的,没法用于生产环境

#12 楼 @hanji 具体是加的什么内容?

#14 楼 @huacnlee Authorization Basic base64(client_id:private_key)

@hanji 有相同的问题,总是提示非法客户端,我已经注册了啊,怎么解决的呢

#16 楼 @winter 请查看跟帖。如 15 楼所述,注意添加 Authorization HTTP Header。

需要 登录 后方可回复, 如果你还没有账号请 注册新账号