oauth-2.0 - Google API - 来自 Oauth2 的 token 请求返回 “invalid_request”

标签 oauth-2.0

我知道以前有人问过这个问题,但其他帖子中的建议没有帮助。
我成功收到了来自谷歌的授权 token ,但是当我尝试获取访问 token 时,我收到了一个 invalid_request。

我们在 PHP 中的第一次尝试导致了这种响应,当我通过我的 HTTP 客户端尝试它时,我得到了同样的结果。最后,我直接用 CURL 尝试,仍然得到相同的结果:

curl -v -k --header "Content-Type: application/x-www-form-urlencoded" \
-F 'code=4/U2su0fwiynq4v8J8xD56ohfF0fX6.EhP0brx3cosbuJJVnL49Cc8EFE7ncQI' \
-F 'client_id=012345678901-abcdefghijklmnopqrstuvwxyz012345.apps.googleusercontent.com' \
-F 'client_secret=ABC123ABC123ABC123ABC123' \
-F 'grant_type=authorization_code' \
-F 'redirect_uri=https://app.myserver.com/googleLogin.php' \
https://accounts.google.com/o/oauth2/token

我收到的回复是:
> https://accounts.google.com/o/oauth2/token
* About to connect() to accounts.google.com port 443 (#0)
*   Trying 173.194.77.84... connected
* Connected to accounts.google.com (173.194.77.84) port 443 (#0)
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Server finished (14):
* SSLv3, TLS handshake, Client key exchange (16):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSL connection using RC4-SHA
* Server certificate:
*      subject: C=US; ST=California; L=Mountain View; O=Google Inc; CN=accounts.google.com
*      start date: 2011-07-21 00:00:00 GMT
*      expire date: 2013-07-18 23:59:59 GMT
*      common name: accounts.google.com (matched)
*      issuer: C=ZA; O=Thawte Consulting (Pty) Ltd.; CN=Thawte SGC CA
*      SSL certificate verify ok.
> POST /o/oauth2/token HTTP/1.1
> User-Agent: curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 OpenSSL/0.9.8r zlib/1.2.5
> Host: accounts.google.com
> Accept: */*
> Content-Length: 771
> Expect: 100-continue
> Content-Type: application/x-www-form-urlencoded; boundary=----------------------------0d3dc3507a7f
> 
* Done waiting for 100-continue
< HTTP/1.1 400 Bad Request
< Cache-Control: no-cache, no-store, max-age=0, must-revalidate
< Pragma: no-cache
< Expires: Fri, 01 Jan 1990 00:00:00 GMT
< Date: Sat, 04 Aug 2012 22:07:07 GMT
< Content-Type: application/json
< X-Content-Type-Options: nosniff
< X-Frame-Options: SAMEORIGIN
< X-XSS-Protection: 1; mode=block
< Server: GSE
< Transfer-Encoding: chunked
< 
{
  "error" : "invalid_request"
* Connection #0 to host accounts.google.com left intact
* Closing connection #0
* SSLv3, TLS alert, Client hello (1):

我在发送之前没有对任何内容进行 url 编码,但是当我这样做时,我得到了相同的结果。

任何帮助是极大的赞赏!

最佳答案

尝试使用 OAuth 2.0 Playground 执行相同的请求并将它们与您的进行比较:

https://code.google.com/oauthplayground/

关于oauth-2.0 - Google API - 来自 Oauth2 的 token 请求返回 “invalid_request”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11812459/

相关文章:

java - App Engine 中的 UserService、OAuth 和 AJAX

java - Spring Security Java 配置

node.js - 谷歌 OAuth2 API 刷新 token

erlang - Erlang 的 OAuth2 库

java - 想让 oauth2 的 perl 代码在 Java 中工作 "curl -H ' 授权 : Bearer:<TOKEN> https://canvas. instruct.com/api/v1";

php - 我可以使用开发人员 key 在没有 Oauth 的情况下通过 Google Sheets API 写入 Google Sheet 吗?

authentication - 如何使用/验证 AspNet.Security.OpenIdConnect.Server (RC1) 颁发的 token ?

oauth - Outlook Office 365 : Refresh token failed to retrieve because "AADSTS70000" the provided value for the 'code' parameter is not valid

azure - 登录时没有收到 oid 响应?

Android OAuth 改造访问 token 请求