我正在使用Firebase数据库,并设置了一个安全规则进行测试
".write":false
读总是对的。
现在,当我使用android应用程序中的客户端SDK编写任何内容时,该写入将按预期在数据库中的所有位置被拒绝。
但是,当我使用经过身份验证的REST API修补程序请求在任何地方写入任何内容时,它总是成功。
令牌生成如下:
//googleCredAhmedabad and scopedAhmedabad are GoogleCredential objects
InputStream is = getServletContext().getResourceAsStream("/WEB-INF/firebaseauth/myserviceaccountfile.json");
googleCredAhmedabad = GoogleCredential.fromStream(is);
scopedAhmedabad = googleCredAhmedabad.createScoped(
Arrays.asList(
"https://www.googleapis.com/auth/firebase.database",
"https://www.googleapis.com/auth/userinfo.email"
)
);
scopedAhmedabad.refreshToken();
String myToken = scopedAhmedabad.getAccessToken();
(使用服务帐户在足够范围内生成凭据)经过身份验证的REST API调用王牌安全规则吗?
最佳答案
在Firebase Documentation上提到过:
auth request参数允许访问受Firebase保护的数据
实时数据库规则,并且受所有请求类型的支持。的
参数可以是我们的Firebase应用程序密码或身份验证
令牌,我们将在用户授权部分中介绍。
而且我看到您提到您正在使用经过身份验证的REST API,所以我假设您确实设置了auth参数。这表示您是对的:安全规则不适用于经过身份验证的REST API。