邮递员:无法完成 OAuth2.0 登录
POSTMAN: Could not complete OAuth2.0 login
我想请求一个令牌,以便我可以让我的邮递员登录我的 Gmail 帐户,然后我可以调用 Google 云 API。
我正在尝试输入我的 Gmail 电子邮件地址及其密码,您可以从这张图片中看到
最终目标是获得这样的 API
https://monitoring.googleapis.com/v1/projects/firetestjimis/dashboards
我可以使用我的 Gmail 帐户从 gcloud ("gcloud auth application-default login") 登录,然后使用 gcloud auth application-default print-access-token 打印令牌,复制打印的令牌并粘贴在访问令牌(邮递员)中。很好,但它有点让我有义务启动 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: /
当我尝试时
我从
复制的客户端 ID
*** 根据 Madhead 的建议编辑
我仔细遵循了建议的所有步骤,实际上我可以通过单击“获取新访问令牌”直接从 Postman 获得 Google 令牌。尽管如此,它得到了
{
"error": {
"code": 403,
"message": "Request had insufficient authentication scopes.",
"status": "PERMISSION_DENIED"
}
}
对于 Postman 的这两个尝试(粘贴 curl 脚本,因为它比 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"]}}
下载自
这里是
*** 已编辑
*** 已编辑
- 已编辑
*** 在成功添加两个范围后编辑
它说 "Because you've added a sensitive scope, your consent screen requires verification by Google before it's published"
当我点击 "Submit for verification" 时,我看到它抱怨应用程序主页和应用程序隐私链接
您无法使用此方法登录 Google 个帐户。 Client ID 和 Client Secret 不是您的用户名和密码。它们是您的身份验证客户端的凭据。
如果您想使用 Google 用户凭据,则需要实施受支持的 Google OAuth 流程。有几种方法,但都涉及网络浏览器来处理用户名和密码输入。
为了生成 OAuth 令牌 (Access/Identity/Refresh),您还需要指定访问范围。这可能 involve/require 对您的应用程序进行安全审核。因此,我建议您使用 Google 支持的库,除非您想了解 OAuth 流程的实施细节。
实际上可以使用 Postman 访问安全的 OAuth 2.0 Google APIs.
首先,您需要在 Google Cloud Console 项目中创建一个 OAuth 客户端。它应该是一个 "Web application" 客户端,重定向 URI 应该是 https://oauth.pstmn.io/v1/callback
:
记下客户端 ID 和客户端密码:
现在,去找邮递员。创建新请求。在 "Authorization" 选项卡上,select OAuth 2.0,然后单击 "Get New Access Token":
填写表格。
- 回调URL:
https://oauth.pstmn.io/v1/callback
(将由Authorize using browser
自动设置)。
- 使用浏览器授权:true
- 授权 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(例如,在同意屏幕配置页面上)。
点击"Request Token"。浏览器将打开 pstmn.io
应用的 Google 的 OAuth 同意屏幕。如有必要,请登录并授予访问权限。在该过程结束时,将打开一个弹出窗口(确保它没有被您的浏览器阻止),将您重定向回 Postman 应用程序。
去使用你的令牌吧!
我遇到了同样的问题,并通过修复不正确的(可能是旧的)API URL 解决了这个问题。
确保您使用的是正确的授权端点 URL。为此,请下载 JSON 文件,其中包含授权您的应用程序所需的信息。您可以通过左侧菜单中的主页 > APIs & 服务 > 凭据然后 OAuth 2.0 客户端 ID 访问文件 link。
它将提供如下信息:
{
"web": {
"client_id": "xxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com",
"project_id": "xxxxxxxxxxxxxx",
"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": "xxxxxxxxxxxxxxxxxxxxxxx",
"redirect_uris": [
"https://oauth.pstmn.io/v1/browser-callback"
]
}
}
我想请求一个令牌,以便我可以让我的邮递员登录我的 Gmail 帐户,然后我可以调用 Google 云 API。
我正在尝试输入我的 Gmail 电子邮件地址及其密码,您可以从这张图片中看到
最终目标是获得这样的 API
https://monitoring.googleapis.com/v1/projects/firetestjimis/dashboards
我可以使用我的 Gmail 帐户从 gcloud ("gcloud auth application-default login") 登录,然后使用 gcloud auth application-default print-access-token 打印令牌,复制打印的令牌并粘贴在访问令牌(邮递员)中。很好,但它有点让我有义务启动 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: /
当我尝试时
我从
复制的客户端 ID*** 根据 Madhead 的建议编辑
我仔细遵循了建议的所有步骤,实际上我可以通过单击“获取新访问令牌”直接从 Postman 获得 Google 令牌。尽管如此,它得到了
{
"error": {
"code": 403,
"message": "Request had insufficient authentication scopes.",
"status": "PERMISSION_DENIED"
}
}
对于 Postman 的这两个尝试(粘贴 curl 脚本,因为它比 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"]}}
下载自
这里是
*** 已编辑
*** 已编辑
- 已编辑
*** 在成功添加两个范围后编辑
它说 "Because you've added a sensitive scope, your consent screen requires verification by Google before it's published"
当我点击 "Submit for verification" 时,我看到它抱怨应用程序主页和应用程序隐私链接
您无法使用此方法登录 Google 个帐户。 Client ID 和 Client Secret 不是您的用户名和密码。它们是您的身份验证客户端的凭据。
如果您想使用 Google 用户凭据,则需要实施受支持的 Google OAuth 流程。有几种方法,但都涉及网络浏览器来处理用户名和密码输入。
为了生成 OAuth 令牌 (Access/Identity/Refresh),您还需要指定访问范围。这可能 involve/require 对您的应用程序进行安全审核。因此,我建议您使用 Google 支持的库,除非您想了解 OAuth 流程的实施细节。
实际上可以使用 Postman 访问安全的 OAuth 2.0 Google APIs.
首先,您需要在 Google Cloud Console 项目中创建一个 OAuth 客户端。它应该是一个 "Web application" 客户端,重定向 URI 应该是 https://oauth.pstmn.io/v1/callback
:
记下客户端 ID 和客户端密码:
现在,去找邮递员。创建新请求。在 "Authorization" 选项卡上,select OAuth 2.0,然后单击 "Get New Access Token":
填写表格。
- 回调URL:
https://oauth.pstmn.io/v1/callback
(将由Authorize using browser
自动设置)。 - 使用浏览器授权:true
- 授权 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(例如,在同意屏幕配置页面上)。
点击"Request Token"。浏览器将打开 pstmn.io
应用的 Google 的 OAuth 同意屏幕。如有必要,请登录并授予访问权限。在该过程结束时,将打开一个弹出窗口(确保它没有被您的浏览器阻止),将您重定向回 Postman 应用程序。
去使用你的令牌吧!
我遇到了同样的问题,并通过修复不正确的(可能是旧的)API URL 解决了这个问题。
确保您使用的是正确的授权端点 URL。为此,请下载 JSON 文件,其中包含授权您的应用程序所需的信息。您可以通过左侧菜单中的主页 > APIs & 服务 > 凭据然后 OAuth 2.0 客户端 ID 访问文件 link。
它将提供如下信息:
{
"web": {
"client_id": "xxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com",
"project_id": "xxxxxxxxxxxxxx",
"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": "xxxxxxxxxxxxxxxxxxxxxxx",
"redirect_uris": [
"https://oauth.pstmn.io/v1/browser-callback"
]
}
}