无法在POSTMan上获得Google oAuth 2令牌 [英] Could not obtain Google oAuth 2 token on POSTMan

查看:965
本文介绍了无法在POSTMan上获得Google oAuth 2令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,自其他问题(解决)仍然没有解决,我正在考虑使用POSTMan在客户端库的每个步骤上执行Trail和Error。



所以我阅读Google OAuth2的基本步骤再次创建了另一个OAuth 2 ID 开发人员控制台中的Api Manager>凭证和ID类型是Web应用程序,并将它们填充到POSTMan中:


  1. POSTMAN,然后单击授权标签。

  2. 选择类型为OAuth 2.0,然后选择为该URL添加令牌。

  3. 验证网址: https://accounts.google.com/o/oauth2/v2/auth

  4. 访问令牌网址: https://www.googleapis.com/oauth2/v4/token

  5. 客户端ID:[我刚刚收到的客户端ID]

  6. 客户秘密:[我刚收到的客户秘密]

  7. 范围:[空]
  8. 授予类型:授权码



  9. POSTMAN回复我说:可以不完整的OAuth2.0登录

我错过了什么?



(Google重定向URI可以在此处找到)



(API范围可以在此处找到) p>

解决方案

您只有在Google用户通过Google登录页面登录时才能获取访问令牌。



第1步:
Redirec t
https://accounts.google.com/o/oauth2/auth ?client_id = + GoogleClientID +& redirect_uri =+ Url.Encode(GoogleRedirectURL)+& response_type = code& scope = email

第2步:
现在你在谷歌登录页面,你会输入你的谷歌凭据。


第3步:
Google会将您重定向回您在Google Developer Console中配置的redirect_uri,您可以从QueryString中获取代码


第4步:
现在您将表单发布到 https://www.googleapis.com/oauth2/v4/token
with client_id,client_secret,redirect_uri,代码(您在步骤3中获得)以及grant_type = authorization_code



结果:您现在应该收到来自Google的access_token


Well, since the Other problem(solved) remain unsolved, I was thinking to use POSTMan to do Trail 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)

解决方案

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

这篇关于无法在POSTMan上获得Google oAuth 2令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆