Open hoerlanton opened 2 years ago
We see this happening a lot on our services as well. There is a fairly big percentage of requests failing because of that.
Failed to retrieve verification certificates: request to https://www.googleapis.com/oauth2/v1/certs failed, reason: socket hang up
I am seeing a similar issue as of recently: FetchError: Failed to retrieve verification certificates: request to https://www.googleapis.com/oauth2/v1/certs failed, reason: unable to get local issuer certificate
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
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'; }`
So I am just wondering what I am doing wrong here. Any help is appreciated.
Best, Anton