[英]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 chain对https://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.