0

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?

Linda Lawton - DaImTo
118k40 gold badges228 silver badges511 bronze badges
asked Feb 19, 2019 at 2:38
3
  • 1
    have you tried the issue forum it seams to be a common issue on the library github.com/nodejs/node-gyp/issues/695 Commented Feb 19, 2019 at 7:16
  • setting this environment variable worked! NODE_TLS_REJECT_UNAUTHORIZED=0. Thanks DaImTo! Commented Feb 19, 2019 at 14:27
  • post the answer to your own question you may help someone in the future. Commented Feb 19, 2019 at 14:31

1 Answer 1

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

sɐunıɔןɐqɐp
3,59516 gold badges41 silver badges43 bronze badges
answered Aug 2, 2020 at 8:47
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.