【问题标题】:Firebase Admin failed to fetch a valid Google OAuth2 access token - unable to verify certificateFirebase 管理员未能获取有效的 Google OAuth2 访问令牌 - 无法验证证书
【发布时间】:2018-08-07 03:29:33
【问题描述】:

任何帮助表示赞赏。

目前在 localhost 上开发。
日期和时间同步。
安装了最新的 firebase-admin。

这一天工作得非常好,但第二天就不行了。 (没有变化)。

终端输出:
@firebase/database: FIREBASE WARNING: {"code":"app/invalid-credential","message":"Credential implementation provided to initializeApp() via the \"credential\" property failed to fetch a valid Google OAuth2 access token with the following error: \"unable to verify the first certificate\"."}

这是app.js的开头:

//requires
var radius = require("radius");
var dgram = require("dgram");
var admin = require("firebase-admin");    

//for CHAP hashing
var crypto = require("crypto");

//Load additional radius dictionaries
radius.add_dictionary('./radius_dictionaries');

//init firebase
var serviceAccount = require("./serviceKey.json");
admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  databaseURL: "https://<database>.firebaseio.com/"
});
//init db object
var db = admin.database();

此应用不提供 HTTPS 网页或 http 请求的 HTTPS 端点。只需连接到 Firebase 数据库并读取数据。

【问题讨论】:

    标签: node.js firebase firebase-realtime-database google-oauth firebase-admin


    【解决方案1】:

    启动了一个干净的应用程序,但遇到了一个问题,我什至无法安装 firebase-admin

    经过一番挖掘,我注意到node-pre-gyp 在尝试构建时抛出了很多堆栈错误,并且节点找不到我的本地 python 安装(尽管已安装)。

    gyp ERR! build error
    gyp ERR! stack Error: `C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe` failed with 
    exit code: 1
    gyp ERR! stack     at ChildProcess.onExit 
    (C:\Users\Jonth\AppData\Roaming\npm\node_modules\npm\node_modules\node- 
    gyp\lib\build.js:262:23)
    

    又是证书错误

    node-pre-gyp WARN Hit error unable to verify the first certificate
    

    所以我解决这个问题的方法是:

    运行

    npm install --global --production windows-build-tools
    

    并运行

    这才是真正解决问题的方法

    set NODE_TLS_REJECT_UNAUTHORIZED=0
    

    我现在可以运行我的应用程序并继续开发。
    为什么我需要这样做,我真的不知道。
    如果有人能启发我,我会全神贯注。
    我可以只希望在我的应用部署到 Google 云时这不会影响它。

    仅供参考,开发 PC 是 Windows 10 Pro

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-15
    • 2019-11-19
    • 2018-09-07
    • 2016-08-21
    • 1970-01-01
    • 2019-11-26
    • 2020-05-09
    相关资源
    最近更新 更多