Trying to get User data from Google Directory User API using Node.js. Have set up service account and downloaded the key json file and proper permissions have been granted for the service account. 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
I tried :
- npm config set strict-ssl false
- and also tried to download a ca-cert and 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. This makes TLS, and HTTPS by extension, insecure. The use of this environment variable is strongly discouraged.
https://nodejs.org/api/cli.html#cli_node_tls_reject_unauthorized_value