【发布时间】:2017-06-18 18:21:07
【问题描述】:
我需要使用节点对 Firebase 用户进行身份验证,以便测试一些服务器端方法。对于每个受保护的请求,我使用以下方法验证 Firebase 令牌:
firebase.auth().verifyIdToken(firebaseAccessToken).then(function(decodedToken) {
// forward request
})
所以在我的测试中,我使用 Firebase 数据库中的 uid 创建了一个令牌
firebase.auth().createCustomToken(uid).then(function(token) {
//add to header for requests
})
后来我读到,自定义令牌没有通过 verifyIdToken 方法验证,只有客户端生成的。
我看过这个答案 - server side verification of tokens in firebase
所以我在初始化 json 中添加了 databaseAuthVariableOverride
firebase.initializeApp({
credential: firebase.credential.cert(serviceAccount),
databaseURL: [dbURL],
databaseAuthVariableOverride: {
uid: [uid]
}
});
在我的测试中仍然得到输出
Error: expected 200 "OK", got 401 "Unauthorized"
还有 firebase 错误 -
Error: Decoding Firebase ID token failed. Make sure you passed the entire string JWT which represents an ID token. See https://firebase.google.com/docs/auth/admin/verify-id-tokens for details on how to retrieve an ID token.
那么我如何使用我当前的设置来模拟用户呢?
【问题讨论】:
-
或许这篇文章对你有帮助:firebase.googleblog.com/2015/04/…
标签: node.js firebase mocha.js firebase-authentication chai