如何通过Firebase Admin与代理连接到Firebase?

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

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

当我通过node index.js运行节点脚本,并得到一些像这样的超时消息(我知道在我的工作networking中,我无法直接连接到Firebase)。

 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) 

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

但是如何在NodeJS服务器端脚本中解决这个问题呢?

如果运行NodeJS进程的主机上的date和时间设置不正确,也会发生此错误。 确保保持服务器时间同步。

完整的错误消息: 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. 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.