我假设类似的旧问题HTTPS and Firebase authentication有一些更新。至少,弗兰克(Frank)的答案指向“旧”文档,例如https://www.firebase.com/docs/rest/api/#section-query-parameters 因此,我的问题是,假设我有Firebase应用程序的用户,我该如何仅通过用户名和密码通过通过Postman发送的http请求对他/她进行身份验证? 我是否需要诸如以下的帮助程序库:https://github.com/googlearchive/firebase-token-generator-node 但是已存档。 这是:https://firebase.google.com/docs/auth/admin/create-custom-tokens是文档中最相关的部分,在回答我的问题吗? 再次假设用户只知道用户名和密码,我应该输入令牌生成代码
var uid = "some-uid";
admin.auth().createCustomToken(uid)
.then(function(customToken) {
// Send token back to client
})
.catch(function(error) {
console.log("Error creating custom token:", error);
});
在我的HTTP触发器内部? 我想要实现的是仅使用Firebase Cloud Functions(HTTP触发器和数据库触发器)构建的一些REST API。我已经设置了数据库规则,所以我希望那些触发器遵守这些规则,而无需重复触发器内部的逻辑。
编辑:我知道使用“秘密”可以访问整个数据库,所以这对我来说不是一个选择,因为我要强制执行我编写的数据库规则。
编辑:我是否使用类似于
的代码admin.auth().getUserByEmail(email)
.then(function(userRecord) {
// See the UserRecord reference doc for the contents of userRecord.
console.log("Successfully fetched user data:", userRecord.toJSON());
})
.catch(function(error) {
console.log("Error fetching user data:", error);
});
登录用户后,一旦获得用户名(本例中为电子邮件地址),
在我的http触发器内?也就是说,我在请求参数中收到电子邮件地址,并在执行进一步的逻辑之前登录用户?这样,auth
变量将可用。我说的对吗?