0% found this document useful (0 votes)
5 views4 pages

Node PDF

The document discusses a user's issue connecting to Firebase via a proxy using the Firebase Admin SDK in a NodeJS application. It highlights potential causes for connection errors, such as proxy settings and server time synchronization, and provides a solution involving the use of the 'https-proxy-agent' package to configure the proxy in the Firebase initialization code. The user is advised to avoid committing proxy configurations to their repository due to regional restrictions on Google services.

Uploaded by

Dra Matic
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

Node PDF

The document discusses a user's issue connecting to Firebase via a proxy using the Firebase Admin SDK in a NodeJS application. It highlights potential causes for connection errors, such as proxy settings and server time synchronization, and provides a solution involving the use of the 'https-proxy-agent' package to configure the proxy in the Firebase initialization code. The user is advised to avoid committing proxy configurations to their repository due to regional restrictions on Google services.

Uploaded by

Dra Matic
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Stack Overflow's 2025 Annual Developer Survey is still open — take the Survey before it closes

How to connect to Firebase by Firebase Admin against


a proxy?
Asked 8 years, 5 months ago Modified 3 years, 2 months ago Viewed 6k times

Part of Google Cloud Collective

Currently, I am using Firebase Admin SDK to connect a Firebase database in a NodeJS


server side application.

4
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 [Link] , 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 [Link]:443".
at ....erver\node_modules\firebase-adm
in\lib\[Link]: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?

[Link] firebase proxy firebase-realtime-database firebase-admin

Share Improve this question edited Jan 18, 2017 at 7:30 asked Jan 18, 2017 at 6:44

Follow AL. Hantsy


37.8k 10 147 287 9,516 11 72 139

It looks like the Admin [Link] SDK is not being properly initialized. Can you share your
initialization code ( [Link]() )? 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
[Link] port 443. I'd check to make sure your
proxy settings aren't blocking those requests. – jwngr Jan 25, 2017 at 19:27

I have tried my codes in different environments, it works if the network can connect to
Firebase/Google. – Hantsy Jan 27, 2017 at 13:02

I am behind a proxy and unable to initialize the firebase, any help? – Madeyedexter Feb 24, 2017 at
16:49

Report this ad

2 Answers Sorted by: Highest score (default)

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.

11
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
[Link] If not,
generatea new key file at
[Link]

Share Improve this answer Follow answered Jan 30, 2017 at 15:16
ElectroBuddha
658 10 21
For me, it actually says: "To solve (1), re-sync the time on your server." – Domi Aug 10, 2017 at
14:06

@electrobuddha My error is very different from Electrobuddha, obviously there is a timeout in my


error, because we can not connect to any google service in China, we have to use a Proxy to
resolve this. Electrobuddha's answer is highly voted, but it is really not related to my question,
please remove it . – Hantsy Jan 26, 2018 at 6:35

@Garbit Read carefully about my question and my comment, this answer is not related to my
question. – Hantsy Jan 26, 2018 at 6:41

Faced with the exact same problem yesterday, got it solved.

Let's get it straight, you are getting this error because Google services are banned in your
1
region, therefore you should access firebase through a proxy. Here's a blog explaining
how it is done.

For this specific case, you should

1. Prepare a proxy server that allows you to access Google services, then

2. Install the https-proxy-agent package through npm or yarn, then

3. Include the proxy in your firebase app initilization code like this

import HttpsProxyAgent from 'https-proxy-agent';


import * as admin from 'firebase-admin';
...
const agent = new HttpsProxyAgent('url to your proxy server');
[Link]({
credential: [Link](agent),
// Or any function you would like to use to provide your application's
credentials
// But remember to include the proxy agent in the parameter
httpAgent: agent
});

But remember not to commit this change into your repo, since this problem appears
specifically in regions without access to Google services.

Share Improve this answer edited Mar 28, 2022 at 16:11 answered Mar 5, 2022 at 7:25

Follow PotatoPie
11 2

Start asking to get answers


Find the answer to your question by asking.

Ask question

Explore related questions

[Link] firebase proxy firebase-realtime-database firebase-admin

See similar questions with these tags.

You might also like