简体   繁体   English

使用服务帐户的 Google 目录 API - 错误自签名证书

[英]Google directory API using Service account - error self signed cert

Trying to get User data from Google Directory User API using Node.js.尝试使用 Node.js 从 Google Directory User API 获取用户数据。 Have set up service account and downloaded the key json file and proper permissions have been granted for the service account.已设置服务帐户并下载密钥 json 文件,并已为服务帐户授予适当的权限。 Below is the code.下面是代码。

'use strict';

const {google} = require('googleapis');
const path = require('path');

async function runSample() {
  // acquire an authentication client using a service account
  const auth = await google.auth.getClient({
    keyFile: ('./auth.json'),
    scopes: [
      'https://www.googleapis.com/auth/admin.directory.user.readonly',
    ],
  });

  // obtain the admin client
  const admin = google.admin({
    version: 'directory_v1',
    auth,
  });

  // Insert member in Google group
  const res = await admin.users.get({
    userKey: '{email}'
  });

  console.log(res.data);
}
runSample().catch(console.error);

Getting this error:收到此错误:

request to https://www.googleapis.com/oauth2/v4/token failed, reason: self signed certificate in certificate chainhttps://www.googleapis.com/oauth2/v4/token 的请求失败,原因:证书链中的自签名证书

I tried :我试过 :
- npm config set strict-ssl false - npm config set strict-ssl false
- and also tried to download a ca-cert and npm config set cafile "path/file.pem" - 并尝试下载 ca-cert 和 npm config set cafile "path/file.pem"

neither helped.都没有帮助。 Can anyone please help with this?任何人都可以帮忙吗?

Set this environment variable:设置这个环境变量:

NODE_TLS_REJECT_UNAUTHORIZED=0

Documentation:文档:

If value equals '0', certificate validation is disabled for TLS connections.如果值等于“0”,则对 TLS 连接禁用证书验证。 This makes TLS, and HTTPS by extension, insecure.这使得 TLS 和 HTTPS 不安全。 The use of this environment variable is strongly discouraged.强烈建议不要使用此环境变量。

https://nodejs.org/api/cli.html#cli_node_tls_reject_unauthorized_value https://nodejs.org/api/cli.html#cli_node_tls_reject_unauthorized_value

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:使用localhost的SELF_SIGNED_CERT_IN_CHAIN - ERROR: SELF_SIGNED_CERT_IN_CHAIN using localhost 使用npm安装时出现SELF_SIGNED_CERT_IN_CHAIN错误 - SELF_SIGNED_CERT_IN_CHAIN error while using npm install 错误:SELF_SIGNED_CERT_IN_CHAIN错误 - Error: SELF_SIGNED_CERT_IN_CHAIN error 使用自签名证书向我的服务器调用 API 时证书被撤销 - Cert Revoked when calling API to my server with self signed cert 在 nodejs 中使用 Google API 服务帐户生成签名的 JSON Web 令牌 - Generates a signed JSON Web Token using a Google API Service Account in nodejs 接收错误:使用 npm 时出现“错误:SSL 错误:SELF_SIGNED_CERT_IN_CHAIN” - receiving error: 'Error: SSL Error: SELF_SIGNED_CERT_IN_CHAIN' while using npm Google-api-nodejs-client:使用服务帐户调用目录 api 返回无效输入 - Google-api-nodejs-client: Using service account to call directory api returns invalid inputs MySQL xdevapi 节点错误:SELF_SIGNED_CERT_IN_CHAIN - MySQL xdevapi Node Error: SELF_SIGNED_CERT_IN_CHAIN 节点 TLS 套接字:DEPTH_ZERO_SELF_SIGNED_CERT 错误 - Node TLS socket : DEPTH_ZERO_SELF_SIGNED_CERT error Google Calendar API 和服务帐户权限错误 - Google Calendar API and Service Account permission error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM