POSTMAN:无法完成OAuth2.0登录。

问题描述 投票:0回答:1

我想请求一个令牌,以便我可以让我的邮递员登录到我的Gmail账户,然后我可以调用谷歌云API。

我尝试着输入我的Gmail邮箱地址和密码,如图所示

Postman Request Token

最终的目标是得到这样的API

https://monitoring.googleapis.com/v1/projects/firetestjimis/dashboards

我可以通过登录我的Gmail帐户从gcloud("gcloud auth应用程序默认登录"),然后打印令牌与gcloud auth应用程序默认打印访问令牌,复制打印的令牌,并将其粘贴在访问令牌(邮递员)。嗯,它的工作原理,但它是一种强制我启动gcloud,并已安装。我敢肯定,我可以达到同样的想法,通过签署相同的用户,我在gcloud签署。我只是不知道如何做到这一点与邮递员。所有我读过的最后几个小时驱动我的图像,我粘贴在上面,但它是故障与错误的这个问题。

如果它是相关的,这里是gcloud控制台,在那里我得到的令牌。

C:\Program Files (x86)\Google\Cloud SDK>gcloud auth application-default print-access-token
C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\bin\..\lib\third_party\google\auth\_default.py:69: UserWarning: Your application has authenticated using end user credentials from Google Cloud SDK. We recommend that most server applications use service accounts instead. If your application continues to use end user credentials from Cloud SDK, you might receive a "quota exceeded" or "API not enabled" error. For more information about service accounts, see https://cloud.google.com/docs/authentication/
  warnings.warn(_CLOUD_SDK_CREDENTIALS_WARNING)
ya29.a0Ae4lvC3-3WxUmx... removed token ... hs251yTql3eEE

C:\Program Files (x86)\Google\Cloud SDK>

*** 在第一次发布后编辑了一下。

其他暂定的是导致

Erro 400: invalid_request
Invalid parameter value for redirect_uri: Missing scheme: /

当我尝试

Postman

我复制的客户ID

https://console.developers.google.com/apis/credentials

***根据Madhead的建议进行了编辑。

我仔细地按照所有建议的步骤进行了操作,确实我可以通过点击获取新的访问令牌,直接从Postman获得一个Google令牌。然而,它得到的是

{
  "error": {
    "code": 403,
    "message": "Request had insufficient authentication scopes.",
    "status": "PERMISSION_DENIED"
  }
}

对于这两个来自Postman的暂定稿(粘贴的卷曲脚本,因为它比Postman的印刷屏更容易从其他人那里进行评估

curl --location --request GET 'https://monitoring.googleapis.com/v1/projects/firetestjimis/dashboards' --header 'Authorization: Bearer ya29. *** token *** kO3Fg'

curl --location --request POST 'https://firestore.googleapis.com/v1/projects/firetestjimis/databases/(default)/documents:runQuery' --header 'Authorization: Bearer ya29. *** token *** kO3Fg' --header 'Content-Type: application/json' --data-raw '{
"structuredQuery": {
    "where" : {
        "fieldFilter" : { 
        "field": {"fieldPath": "id"}, 
        "op":"EQUAL", 
        "value": {"stringValue": "1"}
        }
    },
    "from": [{"collectionId": "transfer"}]
    }
}'

这里是在以下地方创建的OAuth客户端ID 全权证书屏幕

{"web":{"client_id":"7953 *** 5k6e9ivtdg.apps.googleusercontent.com","project_id":"firetestjimis","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://oauth2.googleapis.com/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"IJGCe *** Du6bU","redirect_uris":["https://oauth.pstmn.io/v1/callback"]}}

下传到

Google Cloud Plataform Credentials

而这里是 OAuth consent screen

*** 经编辑

Add Scorpe screen

scope invalid

*** 经编辑

trying add https://monitoring.googleapis.com/ as scope

  • 编辑

Nothing returned from Cloud Monitoring API

***在成功添加两个范围后编辑。

它说:"由于您添加了一个敏感范围,您的同意屏幕需要谷歌验证后才能发布"

waiting for Google aproval

当我点击 "提交验证 "时,我看到它抱怨应用程序的主页和应用程序的隐私链接。

complaining about two urls

google-cloud-platform google-api postman gcloud google-oauth2
1个回答
5
投票

其实可以使用Postman来访问OAuth 2.0安全的谷歌API。

首先,你需要在你的Google Cloud Console项目中创建一个OAuth客户端。它应该是一个 "Web应用程序 "客户端,重定向URI应该是 https://oauth.pstmn.io/v1/callback:

Create OAuth client ID

记下客户ID和客户秘密。

Client ID & Client Secret

现在,去找邮差。创建新的请求。在 "授权 "选项卡上,选择OAuth 2.0,然后点击 "获取新的访问令牌"。

New request

填写表格

  • 回调URL。https://oauth.pstmn.io/v1/callback (会自动设置) Authorize using browser).
  • 使用浏览器授权:真
  • Auth URL。https://accounts.google.com/o/oauth2/auth
  • 访问令牌URL。https://accounts.google.com/o/oauth2/token
  • 客户端ID。${您的客户ID}
  • 客户秘密:${你的线索秘密}。
  • 范围:${你的作用域},如 https://www.googleapis.com/auth/gmail.readonly 用于Gmail的只读访问。确保在你的项目中允许使用相应的作用域和API(例如在consent scree配置页面)。

New access tokenConsent screen & ScopesMonitoring scopes

点击 "Request Token"。浏览器将打开Google的OAuth同意页面,点击 "请求令牌"。pstmn.io 应用。如有必要,请登录并授予访问权限。在程序结束时,将打开一个弹出式窗口(请确保它没有被浏览器阻止),将您重定向到Postman应用程序。

去使用你的令牌吧!

Token usage


3
投票

使用此方法无法实现登录谷歌账户的目标。客户端ID和客户秘密不是你的用户名和密码。它们是你的认证客户端的凭证。

如果你想使用Google用户凭证,你将需要实现一个支持的Google OAuth流。有几种方法,但都涉及到网络浏览器来处理用户名和密码的输入。

为了生成OAuth令牌(AccessIdentityRefresh),你还需要指定访问范围。这可能需要对你的应用程序进行安全审计。因此,我建议你使用Google支持的库,除非你想了解OAuth Flows的实现细节。

作为终端用户进行认证

© www.soinside.com 2019 - 2024. All rights reserved.