3
votes

Currently, I am using Firebase Admin SDK to connect a Firebase database in a NodeJS server side application.

But I do not find an option to connect Firebase via proxy settings, or it can detect my system HTTP_PROXY environment variable.

When I run the node script by node index.js, and got some timeout messages like this(I know in my work network, I can not connect to Firebase directly).

Error: Credential implementation provided to initializeApp() via the "credential
" property failed to fetch a valid Google OAuth2 access token with the following
 error: "connect ETIMEDOUT 216.58.200.237:443".                                 
    at ....erver\node_modules\firebase-adm
in\lib\firebase-app.js:74:23                                                    
    at process._tickCallback (internal/process/next_tick.js:103:7)                                                                                             

I also use browser to access the firebase console via proxy, it works.

But how to resolve this issue in NodeJS server side scripts?

1
It looks like the Admin Node.js SDK is not being properly initialized. Can you share your initialization code (admin.initializeApp())? It's possible your proxy settings are blocking the SDKs request to create a Google OAuth2 access token that is needed to communicate with Firebase services. That request goes to https://www.accounts.google.com/o/oauth2/token port 443. I'd check to make sure your proxy settings aren't blocking those requests.jwngr
I have tried my codes in different environments, it works if the network can connect to Firebase/Google.Hantsy
I am behind a proxy and unable to initialize the firebase, any help?Madeyedexter

1 Answers

11
votes

This error also happens if the date and time on your host machine where you run NodeJS process is not set right. Make sure to keep the server time synced.

The full error message: Error: Credential implementation provided to initializeApp() via the "credential" property failed to fetch a valid Google OAuth2 access token with the following error: "Error fetching access token: invalid_grant (Invalid JWT: Token must be a short-lived token and in a reasonable timeframe)". The most likely cause of this error is using a certificate key file which has been revoked. Make sure the key ID for your key file is still present at https://console.firebase.google.com/iam-admin/serviceaccounts/project. If not, generatea new key file at https://console.firebase.google.com/project/_/settings/serviceaccounts/adminsdk.