使用范围内的应用程序默认凭据进行身份验证失败 GCP

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

目前,我在获取用于访问 Gmail 用户邮箱的访问令牌时正在努力解决此类问题。我正在尝试使用 Node.js 的 Google Auth Library 获取访问令牌。使用这种代码片段:

const {GoogleAuth} = require('google-auth-library');

async function main() {
  const auth = new GoogleAuth({
    scopes: 
     'https://mail.google.com/', 
  });
  const client = await auth.getClient();
  const token = await auth.getAccessToken();
  console.log(client);
  console.log(token)
}

main().catch(console.error);

问题是我获得了具有默认范围列表的访问令牌:

scope: 'https://www.googleapis.com/auth/cloud-platform openid https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/accounts.reauth'

当我尝试使用

gcloud auth application-default login --scopes='https://mail.google.com/'

登录 ADC 时

我被重定向到 google 身份验证页面,以选择提供 Google 身份验证库访问权限的帐户。一旦我选择帐户,就会出现屏幕,显示“应用程序已被阻止”

那么,伙计们,有没有办法向通过 ADC(应用程序默认凭据)验证的用户的 Gmail 邮箱授予对 Node.js Google Auth Library 客户端库的访问权限。

我了解模拟服务帐户方法和 OAuth2.0 身份验证,但是是否可以使用范围 ADC 获取访问令牌?以及如何使这些 ADC 自定义范围(https://mail.google.com)访问。

node.js authentication google-cloud-platform gmail credentials
1个回答
0
投票

我遇到了类似的问题,我认为我们都遇到了问题,那就是我们正在尝试访问敏感受限 API 范围。这些有一个验证过程,因此,如果您不是严格需要它们,最好避免它们。我猜您的顶级 Gmail 范围正在触发此操作。

参考:https://developers.google.com/identity/protocols/oauth2/product-readiness/sensitive-scope-verification

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