以Firebase用户身份使用Node.js访问Firebase存储

时间:2018-08-07 10:35:02

标签: node.js firebase firebase-storage firebase-security-rules

我想验证Firebase Storage rules在自动Node.js测试中是否按预期工作。

Upload files to Firebase Storage using Node.js所示,一个人可以使用Firebase Admin API或服务帐户访问Firebase存储桶。

问题在于,使用Admin API或服务帐户会绕过存储规则。

由于Firebase Node.js API不包含firebase.storage函数,因此没有以给定的Firebase用户访问Firebase Storage的明显方法。

简而言之,一个人如何作为给定的Firebase用户/ uid从Node.js访问Firebase存储?

1 个答案:

答案 0 :(得分:4)

据我所知,目前尚无法完成您想要的工作。

其中有一个storage() service in the Firebase Admin SDK for Node.js ,但是正如您所发现的,它提供了对存储桶的完全管理访问权限。

Admin SDK for the Realtime Database can be initialized to access the database as a specific user时,此功能不适用于存储服务。

尽管您想做的事情听起来很合理,所以我建议您file a feature request。同时,我能想到的最好的方法是在浏览器中运行这些单元测试,以便可以使用常规的JavaScript客户端SDK进行身份验证。