Node.js 错误:16未经身份验证:请求具有无效的身份验证凭据。预期的OAuth 2访问令牌、登录cookie或其他有效的身份验证凭据

Node.js 错误:16未经身份验证:请求具有无效的身份验证凭据。预期的OAuth 2访问令牌、登录cookie或其他有效的身份验证凭据,node.js,google-secret-manager,Node.js,Google Secret Manager,我的Node.js代码使用Google Secret Manager时停止工作(不久前工作正常)。我已将GOOGLE_应用程序_凭据env变量设置为有效路径和console.log(process.env.GOOGLE_应用程序_凭据);打印正确。 我甚至尝试重新生成新的.json文件,但仍然得到相同的错误。最初它没有keyFilename,但都给出了相同的结果,即错误。密钥在管理网站中启用。 我已尝试调用wait client.initialize()也是 有什么方法可以调试这个吗?最近从冬季

我的Node.js代码使用Google Secret Manager时停止工作(不久前工作正常)。我已将
GOOGLE_应用程序_凭据
env变量设置为有效路径和
console.log(process.env.GOOGLE_应用程序_凭据)
;打印正确。 我甚至尝试重新生成新的.json文件,但仍然得到相同的错误。最初它没有keyFilename,但都给出了相同的结果,即错误。密钥在管理网站中启用。 我已尝试调用
wait client.initialize()也是

有什么方法可以调试这个吗?最近从冬季到夏季的变化会产生影响吗?但是为什么重新生成的密钥不起作用呢

const { SecretManagerServiceClient } = require('@google-cloud/secret-manager');
const client = new SecretManagerServiceClient({
  keyFilename: 'path-to.json'
});

const projectId = 'project-number';
const parent = 'projects/' + projectId;

...
async function listSecrets() { // Calling this throws the error
  const [secrets] = await client.listSecrets({
    parent: parent
  });
完整错误堆栈:

[2021-04-12T09:14:56.366Z] (node:51988) UnhandledPromiseRejectionWarning: Error: 16 UNAUTHENTICATED: Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.
    at Object.callErrorFromStatus (<super-secret-path>\node_modules\@grpc\grpc-js\build\src\call.js:31:26)
    at Object.onReceiveStatus (<super-secret-path>\node_modules\@grpc\grpc-js\build\src\client.js:176:52)
    at Object.onReceiveStatus (<super-secret-path>\node_modules\@grpc\grpc-js\build\src\client-interceptors.js:336:141)
    at Object.onReceiveStatus (<super-secret-path>\node_modules\@grpc\grpc-js\build\src\client-interceptors.js:299:181)
    at <super-secret-path>\node_modules\@grpc\grpc-js\build\src\call-stream.js:130:78
    at processTicksAndRejections (internal/process/task_queues.js:75:11)
[2021-04-12T09:14:56.366Z](节点:51988)未经处理的Promisejection警告:错误:16未经身份验证:请求具有无效的身份验证凭据。预期的OAuth 2访问令牌、登录cookie或其他有效身份验证凭据。看见https://developers.google.com/identity/sign-in/web/devconsole-project.
在Object.callErrorFromStatus(\node\u modules\@grpc\grpc js\build\src\call.js:31:26)
在Object.onReceiveStatus(\node\u modules\@grpc\grpc js\build\src\client.js:176:52)
在Object.onReceiveStatus(\node\u modules\@grpc\grpc js\build\src\client interceptors.js:336:141)
在Object.onReceiveStatus(\node\u modules\@grpc\grpc js\build\src\client interceptors.js:299:181)
在\node\u modules\@grpc\grpc js\build\src\call stream.js:130:78
在处理和拒绝时(内部/process/task_queues.js:75:11)

我已经安装了谷歌云SDK,在我的服务器上运行了
gcloud auth activate服务帐户,它启动了

ERROR: (gcloud.auth.activate-service-account) There was a problem refreshing your current auth tokens: ('invalid_grant: Invalid JWT: Token must be a short-lived token (60 minutes) and in a reasonable timeframe. Check your iat and exp values in the JWT claim.', '{"error":"invalid_grant","error_description":"Invalid JWT: Token must be a short-lived token (60 minutes) and in a reasonable timeframe. Check your iat and exp values in the JWT claim."}')
在进一步的谷歌搜索之后,我检查了我的服务器的时间,现在已经落后2小时了,因为最近的变化是冬季->夏季,我想在晚了1小时之前仍然合适。 调整时间解决了问题。(有帮助)


有趣的是,我可以使用“人工”凭据登录。

这段代码在哪里运行?在Node.js服务器上我自己的服务器上,而不是在谷歌云上,如果这是问题的关键:-)你能分享完整的错误消息吗?我已经编辑了问题并添加了完整的消息:)