无法使用firebase-admin获取有效的Google OAuth2访问令牌

问题描述:

我目前无法使用nodejs中的firebase-admin读取或写入数据。无法使用firebase-admin获取有效的Google OAuth2访问令牌

没有记录打开它只是永远挂起,永远不会返回一个错误,永远不会完成。

随着日志功能但是它提供了以下(继续重试上一个腐朽的时间表 - 但具有相同的结果):

p:0: Browser went online. 
0: set {"path":"/server/saving-data/fireblog/users","value":{"alanisawesome":{"date_of_birth":"June 23, 1912","full_name":"Alan Turing"},"gracehop":{"date_of_birth":"December 9, 1906","full_name":"Grace Hopper"}},"zg":null} 
p:0: Buffering put: /server/saving-data/fireblog/users 
p:0: Making a connection attempt 
p:0: Failed to get token: Error: 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". 
p:0: data client disconnected 
p:0: Trying to reconnect in 0ms 
0: onDisconnectEvents 

当我赶上(内部火力管理员)HTTPS请求我得到以下内容:

{ Error: unable to verify the first certificate 
    at TLSSocket.<anonymous> (_tls_wrap.js:1094:38) 
    at emitNone (events.js:86:13) 
    at TLSSocket.emit (events.js:188:7) 
    at TLSSocket._finishInit (_tls_wrap.js:616:8) 
    at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:446:38) code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE' } 

我试着从控制台生成一个新的私钥,但它继续返回相同的错误。我还添加了require('ssl-root-cas').input(),如其他地方所建议的,但它不会改变行为。同时将实际的json对象传递给admin.credential.cert函数不会改变行为。

我目前在节点v7.7.4上。

下面是代码我有产生错误:

const admin = require('firebase-admin'); 

admin.initializeApp({ 
    credential: admin.credential.cert('./serviceAccountKey.json'), 
    databaseURL: 'https://mtg-decks-bc92d.firebaseio.com' 
}); 

// turn on logging 
admin.database.enableLogging(true); 

const db = admin.database(); 
const ref = db.ref('server/saving-data/fireblog'); 

const usersRef = ref.child('users'); 
usersRef.set({ 
    alanisawesome: { 
    date_of_birth: 'June 23, 1912', 
    full_name: 'Alan Turing' 
    }, 
    gracehop: { 
    date_of_birth: 'December 9, 1906', 
    full_name: 'Grace Hopper' 
    } 
}).then(() => { 
    console.log('set complete'); 
}); 
+0

您是否能够弄清楚这一点?我的服务器在几天前运行良好,没有任何代码更新,现在我遇到了这个问题。 – arpwal

其他几个帖子建议通过调用require('ssl-root-cas').inject();添加根证书。你可以试试吗?

例如:Error: unable to verify the first certificate in nodejs

+0

不幸的是我已经尝试过。我开始相信这是因为我落后于本地代理(用于监控孩子的互联网使用情况) – RogerHamilton