googleapis / googleapis/google-api-nodejs-client

FetchError: Failed to retrieve verification certificates: request to https://www.googleapis.com/oauth2/v1/certs failed, reason: connect ETIMEDOUT

Open
#3,028 2 comments 15 reactions 0 assignees View on GitHub
priority: p3 type: question
Dominant language
TypeScript
Stars
12.2k
Forks
2k
Avg merge
1d 9h
Merged PRs (30d)
24

Description

Hi,

I have an issue, which reoccurs since a week or so in my node js backend.
Back then, when the issue occurred the first time, I created a SO question: [https://stackoverflow.com/questions/71460283/node-js-react-native-failed-to-retrieve-verification-certificates-google-auth-li](https://stackoverflow.com/questions/71460283/node-js-react-native-failed-to-retrieve-verification-certificates-google-auth-li)

The issue now is the same.

What you're trying to do:
I have a middleware where I am checking, if the user is allowed to use the backend routes.
In this middleware (code below) I am checking if the refresh token, stored in the front-end of my react native app in a secure storage. With the refresh token I am retrieving a new access token in order to retrieve the userId and if the user is verified. If so I call the next() method and the user is allowed to use the routes.

My code:

`
console.log('with refresh token a new access token is retrieved, in order to check if email_verified');

const OAuth2 = google.auth.OAuth2;

const oauth2Client = new OAuth2(
config.CLIENT_ID_GOOGLE, // ClientID
config.CLIENT_SECRET_GOOGLE, // Client Secret
"https://www.sagly.at" // Redirect URL
);

oauth2Client.setCredentials({
refresh_token: token,
});

const res = new Promise((resolve, reject) => {
oauth2Client.getAccessToken((err, token, res) => {
if (err) {
} else {
resolve(res);
}
});
});

const idToken = await res;

const client = new OAuth2Client(config.CLIENT_ID_GOOGLE);
result = await client.verifyIdToken({
idToken: idToken.data.id_token,
audience: config.CLIENT_ID_GOOGLE,
});

payload = result.getPayload();
req.userId = payload['sub'];

if (payload && payload.email_verified) {
console.log('next called');
return 'next';
}`

> Error message I am receiving: FetchError: Failed to retrieve verification certificates: request to https://www.googleapis.com/oauth2/v1/certs failed, reason: connect ETIMEDOUT

So I am just wondering what I am doing wrong here. Any help is appreciated.

Best,
Anton

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.