Could not obtain Google oAuth 2 token on POSTMan

对着背影说爱祢 提交于 2019-11-29 19:17:47

问题


Well, since the Other problem(solved) remain unsolved, I was thinking to use POSTMan to do Trial and Error on each steps that the Client library will do.

So I read the Basic steps of Google OAuth2 again, created another OAuth 2 ID at Api Manager > Credentials in Dev Console and ID type is Web Application, and filled them into the POSTMan:

  1. New tab in POSTMan, then click the Authorization label.
  2. Choose type as OAuth 2.0 and select "Add token to the url"
  3. Auth URL: https://accounts.google.com/o/oauth2/v2/auth
  4. Access Token URL: https://www.googleapis.com/oauth2/v4/token
  5. Client ID: [the Client ID that I just received]
  6. Client Secret: [the Client secret that I just received]
  7. Scope: [empty]
  8. Grant Type: Authorization Code
  9. Request access token locally: Selected
  10. Click "Request Token"
  11. POSTMan replied me: "Could not complete OAuth2.0 login"

Do I missed something?

(Google redirect URI could be found here)

(API scope could be found here)


回答1:


You get access Token only when a Google User Logs in through the google signin page.

Step 1: Redirect https://accounts.google.com/o/oauth2/auth?client_id=" + GoogleClientID + "&redirect_uri=" + Url.Encode(GoogleRedirectURL) + "&response_type=code&scope=email"

Step 2: Now you are on google signin page and you would enter your google credentials.

Step 3 : Google will redirect you back to the redirect_uri that you have configured in the Google Developer Console and you can get the "code" from the QueryString

Step 4: Now you post a form to https://www.googleapis.com/oauth2/v4/token with client_id, client_secret, redirect_uri, code(you obtained in Step 3), and the grant_type=authorization_code

Result: You should now receive the access_token from Google




回答2:


I followed Rajat's instructions, and they worked but afterward I tried what the OP did again but this time setting the scope to 'email' instead of leaving it blank, I got a prompt to enter my gmail creds, and was able to get access token.




回答3:


BigHomie's suggestion of scope to 'email' worked for me as well. But I used a different Auth URL and Access Token URL than BigHomie, because I think it's been updated.

Auth URL: https://accounts.google.com/o/oauth2/auth

Access Token URL: https://accounts.google.com/o/oauth2/token



来源:https://stackoverflow.com/questions/36174558/could-not-obtain-google-oauth-2-token-on-postman

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!