如何通过Firebase Admin与代理连接到Firebase? [英] How to connect to Firebase by Firebase Admin against a proxy?

查看:1636
本文介绍了如何通过Firebase Admin与代理连接到Firebase?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我正在使用Firebase Admin SDK在NodeJS服务器端应用程序中连接Firebase数据库。



但我没有找到通过代理连接Firebase的选项设置,或者它可以检测到我的系统 HTTP_PROXY 环境变量



当我运行 node index.js ,并得到了一些这样的超时消息(我知道在我的工作网络中,我无法直接连接到Firebase)。

 错误:通过凭证
属性向initializeApp()提供的凭证实现无法获取有效的Google OAuth2访问令牌,其中包含以下
错误: 连接ETIMEDOUT 216.58.200.237:443。
at .... erver\\\
ode_modules\firebase-adm
in\lib\firebase-app.js:74:23
at process._tickCallback(internal / process / next_tick.js:103:7)

我也使用浏览器通过代理访问Firebase控制台,作品。

但是如何在NodeJS服务器端脚本中解决这个问题?这个错误也会发生,如果您的主机上运行NodeJS进程的日期和时间不正确。请确保保持服务器时间同步。

完整的错误消息:
错误:凭证执行提供给initializeApp() 凭证属性无法获取有效的Google OAuth2访问令牌,并出现以下错误:获取访问令牌时出错:invalid_grant(无效的JWT:令牌必须是短期令牌,并且在合理的时间范围内)。导致此错误的最可能原因是使用已被吊销的证书密钥文件。确保您的密钥文件的密钥ID仍然存在于https://console.firebase.google.com/iam-admin/serviceaccounts/project中。如果没有,请在https://console.firebase.google.com/project/_/settings/serviceaccounts/adminsdk中生成一个新的密钥文件。


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?

解决方案

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.

这篇关于如何通过Firebase Admin与代理连接到Firebase?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆