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?
-
1have you tried the issue forum it seams to be a common issue on the library github.com/nodejs/node-gyp/issues/695Linda Lawton - DaImTo– Linda Lawton - DaImTo2019年02月19日 07:16:34 +00:00Commented Feb 19, 2019 at 7:16
-
setting this environment variable worked! NODE_TLS_REJECT_UNAUTHORIZED=0. Thanks DaImTo!sameer_v– sameer_v2019年02月19日 14:27:21 +00:00Commented Feb 19, 2019 at 14:27
-
post the answer to your own question you may help someone in the future.Linda Lawton - DaImTo– Linda Lawton - DaImTo2019年02月19日 14:31:41 +00:00Commented Feb 19, 2019 at 14:31
1 Answer 1
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
Comments
Explore related questions
See similar questions with these tags.