gpt4 book ai didi

android - 为什么 Firebase 数据库安全规则不适用于经过身份验证的 REST API?

转载 作者:行者123 更新时间:2023-11-29 19:03:43 25 4
gpt4 key购买 nike

我正在使用 Firebase 数据库并设置了一个测试安全规则

".write":false

读取始终为真。

现在,当我在 Android 应用程序中使用客户端 SDK 编写任何内容时,如预期的那样,写入在数据库中的任何地方都被拒绝。

但是,当我使用经过身份验证的 REST API 补丁请求在任何地方写入任何内容时,它总是成功。

token 生成如下:

       //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 上提到:

The auth request parameter allows access to data protected by Firebase Realtime Database Rules, and is supported by all request types. The argument can either be our Firebase app secret or an authentication token, which we'll cover in the user authorization section.

我看到您提到您正在使用经过身份验证的 REST API,所以我假设您确实设置了 auth 参数。这意味着您是对的:安全规则不适用于经过身份验证的 REST API。

关于android - 为什么 Firebase 数据库安全规则不适用于经过身份验证的 REST API?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47963788/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com