无法在 POSTMan 上获取 Google oAuth 2 令牌

Could not obtain Google oAuth 2 token on POSTMan

嗯,由于 (已解决) 仍未解决,我正在考虑使用 POSTMan 对客户端库将执行的每个步骤进行试错。

所以我再次阅读了 Google OAuth2 的 Basic steps,在 Api Manager > Credentials 在 Dev Console 中创建了另一个 OAuth 2 ID ID类型为Web Application,在POSTMan中填写:

  1. 在 POSTMan 中新建选项卡,然后单击授权标签。
  2. 选择类型为 OAuth 2.0 和 select "Add token to the url"
  3. 授权 URL: https://accounts.google.com/o/oauth2/v2/auth
  4. 访问令牌URL:https://www.googleapis.com/oauth2/v4/token
  5. 客户 ID:[我刚收到的客户 ID]
  6. 客户端密码:[我刚刚收到的客户端密码]
  7. 范围:[空]
  8. 授权类型:授权码
  9. 在本地请求访问令牌:已选择
  10. 点击"Request Token"
  11. POSTMan 回复我:"Could not complete OAuth2.0 login"

我是不是漏掉了什么?

(Google 可以找到重定向 URI here)

(API 可以找到范围 here)

只有当 Google 用户通过 google 登录页面登录时,您才能获得访问令牌。

第一步: 重定向 https://accounts.google.com/o/oauth2/auth?client_id=" + GoogleClientID + "&redirect_uri=" + Url.Encode(GoogleRedirectURL) + "&response_type=code&scope=email"

第 2 步: 现在您在 google 登录页面,您将输入 google 凭据。

第 3 步: Google 会将您重定向回您在 Google 开发人员控制台中配置的 redirect_uri,您可以从 QueryString

中获取 "code"

第 4 步: 现在你 post 一个表单到 https://www.googleapis.com/oauth2/v4/token 使用 client_id、client_secret、redirect_uri、代码(您在步骤 3 中获得)和 grant_type=authorization_code

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

的 access_token

我遵循了 Rajat 的指示,它们起作用了,但后来我再次尝试了 OP 所做的,但这次将范围设置为 'email' 而不是留空,我得到了输入我的 gmail 凭据的提示,并且能够获得访问令牌。

BigHomie 关于 'email' 范围的建议对我也有用。 但是我使用了与 BigHomie 不同的 Auth URL 和 Access Token URL,因为我认为它已经更新了。

授权URL: https://accounts.google.com/o/oauth2/auth

访问令牌URL: https://accounts.google.com/o/oauth2/token