Google OAuth 2: response_type error on token reque

2020-08-16 03:44发布

I am trying to return an OAuth 2 response code for an OAuth response token. However, my request returns the following error which has zero results in google. I tried changing response_type to "token" instead of "code" but that didn't work either.

OAuth 2 parameters can only have a single value: response_type

Request Details:

scope=https://www.googleapis.com/auth/userinfo.email
client_secret=_____
response_type=code
grant_type=authorization_code
redirect_uri=http://localhost/folder/
client_id=____.apps.googleusercontent.com
code=_____

I'm sending this second-step payload to POST https://accounts.google.com/o/oauth2/auth

What is wrong with my request?

Edit

I just realized that there is the https://accounts.google.com/o/oauth2/token URL that should be used for this request. However, changing to that URL now gives:

HTTP/1.0 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: Fri, 27 Jul 2012 22:44:35 GMT
Content-Type: application/json
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Server: GSE

{
  "error" : "invalid_request"
}

Edit 2

Removing the response_type and changing the URL like above solved this.

2条回答
别忘想泡老子
2楼-- · 2020-08-16 03:57

After receiving the authorization code you have to ask '/o/oauth2/token' for the access token. This request takes no 'scope' and no 'response_type' parameters. See the Google documentation for more details.

查看更多
smile是对你的礼貌
3楼-- · 2020-08-16 03:58

After trying out a couple of methods, the required parameters to make the OAUTH2 call are redirect_uri, response_type, scope, client_id. I kept on debugging the oauth call based on the error report I received.

查看更多
登录 后发表回答