目前,我正在使用Firebase Admin SDK连接NodeJS服务器端应用程序中的Firebase数据库.
但我找不到通过代理设置连接Firebase的选项,或者它可以检测我的系统HTTP_PROXY
环境变量.
当我运行节点脚本时node index.js
,得到一些这样的超时消息(我知道在我的工作网络中,我无法直接连接到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进程的主机上的日期和时间设置不正确,也会发生此错误.确保同步服务器时间.
完整的错误消息:
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.