Sheets Quickstart Error - self signed certificate in certificate chain
Expected Behavior
I should be able to run the Sheets API Node.js quickstart and authorize my google account to access the API https://developers.google.com/sheets/api/quickstart/nodejs
Actual Behavior
I am unable to authorize my account due to a self signed certificate found in my certificate chain.
Steps to Reproduce the Problem
- Complete steps 1 and 2 of the quickstart guide.
- Copy and run the provided script in the quickstart guide.
- Follow the generated link to login to my google account.
- Copy the authorization code and paste it into the terminal.
- The following error is displayed in the terminal:
Error while trying to retrieve access token { FetchError: request to https://oauth2.googleapis.com/token failed, reason: self signed certificate in certificate chain
at ClientRequest.
Specifications
- Node version (
node -v): v11.9.0 - OS (Mac/Linux/Windows): Windows 10
Are you on a network behind a firewall/proxy? Have you tried running the same code on a different/open network?
Yes, I am behind a corporate firewall, but I've run the same code on a different machine on the same network and it works fine. It clearly has something to do with my local machine settings rather than the code hosted here. The weird part is that I don't see any self-signed certificates on my machine.
The self-signed cert is likely coming in the response from the proxy/firewall. Maybe a different policy for that machine or you're not authenticated on the network in the same way?
You can also test with a simpler script that just uses built-in node functions.
const https = require('https');
let options = {
hostname: 'oauth2.googleapis.com',
port: 443,
path: '/token',
method: 'POST'
};
let req = https.request(options, (resp) => {
resp.on('data', (chunk) => console.log(chunk.toString()));
resp.on('end', () => console.log('End'));
resp.on('error', (err) => console.log(err));
});
req.end();