android - Firebase 删除的用户能够更改数据。如何在不修改应用程序代码的情况下解决此问题?

标签 android firebase firebase-security firebase-realtime-database firebase-authentication

我正在制作一个带有 Firebase Auth 的应用程序,但是当我删除或禁用帐户时,我需要手动制作一个 signOut()(我通过用户重新加载来控制它),如果我不这样做,用户可以继续上传数据。如果没有应用代码,我该如何解决这个问题?

Firebase 规则

{
  "rules": {
    "users": {
      "$uid": {
        ".read": "auth != null && auth.uid == $uid",
        ".write": "auth != null && auth.uid == $uid"
      }
    }
  }
}

应用代码 - 我如何检测它

if(user != null) user.reload().addOnCompleteListener(this, new OnCompleteListener<Void>() {
            @Override
            public void onComplete(@NonNull Task<Void> task) {
                if(!task.isSuccessful()) {
                    String exc = task.getException().getMessage();
                    Log.e("FireBaseUser", exc);
                    auth.signOut();
                }
            }
});

最佳答案

类型转换 token 时,它会获得一个过期时间戳。这实质上是说:“此 token 中的信息在……之前有效”。删除用户不会使任何现有 token 失效。

请记住,由于最新的 Firebase Authentication SDKs , token 仅在一小时内有效。因此,最多一个小时后, token 将过期,删除的用户将无法刷新它。

如果这对您的应用程序来说还不够,您可以在应用程序中添加逻辑来标记数据库中已删除的用户(在只有管理员可以访问的部分):

/deletedUsers
  209103: true
  37370493: true

然后您可以在您的 security rules验证只有未删除的用户才能访问数据:

".read": "!root.child('deletedUsers').child(auth.uid).exists()"

关于android - Firebase 删除的用户能够更改数据。如何在不修改应用程序代码的情况下解决此问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37370493/

相关文章:

android - 为什么 Google Play 商店说我的 Android 应用与我自己的设备不兼容?

android - 找不到包名称 'demo.abc.com.deals.debug' 的匹配客户端

java - Libgdx firebase robovm 绑定(bind)

ios - 在 UITableView 中显示 Firebase 数据

firebase - Firebase 数据库规则中允许写入和允许创建更新之间的区别

java - 游戏过程中退出时导致强制关闭

java - 将参数传递给 doGet() servlet

android - 使用 AccessToken 检索 Firebase 用户导致 Facebook 身份验证 : "Unsuccessful debug_token response from Facebook" Code 190 出现 Firebase 错误

security - 防止 "delete and update"一个 child 在火力基地

php - 如何配置 Firebase 安全规则以仅允许来自 CURL/PHP 源的写入?