已删除的用户有权访问 Firebase Firestore
Deleted user has access to Firebase Firestore
我的应用程序是公司内部软件。我想让所有经过身份验证的用户都可以访问 Firestore 中的所有文档以进行测试。
我 运行 在执行此操作时犯了一个错误。
- 用户登录 iOS 应用程序并有权访问文档。
- 我从 Firebase Auth 中删除用户(通过 Firebase 控制台)
只要用户打开应用程序,他就会收到更新并可以读写。
规则代码如下:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read : if request.auth != null
allow write: if request.auth != null
}
}
}
如何防止已删除的用户继续访问?
- The user logs in to the iOS app and has access to the documents.
这是预期的行为。
- I delete the user from Firebase Auth (via the console) As long as the user has the app open, he receives updates and can read and write.
当用户使用 Firebase 登录时,他会收到一个令牌,有效期约为一个小时。不幸的是,由于每次调用的检查成本很高,因此无法撤销此类令牌。
如果您直接从 Firebase 控制台删除用户帐户,该用户仍然可以访问长达一个小时。在那段时间之后,需要刷新令牌。但此操作将失败,因为该帐户已不存在。这样访问将在一个小时内自动被禁用。
但是,如果您想在令牌过期之前删除该访问权限,那么您应该考虑保留一个额外的禁止 UID 列表并随着时间的推移对其进行维护。例如,您可以将 bannedUID 的全局 list/array 保存到文档中,然后将 UID 添加到其中。最后,在您的安全规则中,您可以检查该特定 UID 是否未被禁止。如果该 UID 存在于该列表中,则 Firebase 服务器将拒绝该操作。
编辑:
另一个选项可能是禁用用户帐户。这与上面的实现相同,并且用户在当前令牌过期后将无法获得新令牌。它还可以防止用户使用相同的凭据再次注册。
我的应用程序是公司内部软件。我想让所有经过身份验证的用户都可以访问 Firestore 中的所有文档以进行测试。 我 运行 在执行此操作时犯了一个错误。
- 用户登录 iOS 应用程序并有权访问文档。
- 我从 Firebase Auth 中删除用户(通过 Firebase 控制台) 只要用户打开应用程序,他就会收到更新并可以读写。
规则代码如下:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read : if request.auth != null
allow write: if request.auth != null
}
}
}
如何防止已删除的用户继续访问?
- The user logs in to the iOS app and has access to the documents.
这是预期的行为。
- I delete the user from Firebase Auth (via the console) As long as the user has the app open, he receives updates and can read and write.
当用户使用 Firebase 登录时,他会收到一个令牌,有效期约为一个小时。不幸的是,由于每次调用的检查成本很高,因此无法撤销此类令牌。
如果您直接从 Firebase 控制台删除用户帐户,该用户仍然可以访问长达一个小时。在那段时间之后,需要刷新令牌。但此操作将失败,因为该帐户已不存在。这样访问将在一个小时内自动被禁用。
但是,如果您想在令牌过期之前删除该访问权限,那么您应该考虑保留一个额外的禁止 UID 列表并随着时间的推移对其进行维护。例如,您可以将 bannedUID 的全局 list/array 保存到文档中,然后将 UID 添加到其中。最后,在您的安全规则中,您可以检查该特定 UID 是否未被禁止。如果该 UID 存在于该列表中,则 Firebase 服务器将拒绝该操作。
编辑:
另一个选项可能是禁用用户帐户。这与上面的实现相同,并且用户在当前令牌过期后将无法获得新令牌。它还可以防止用户使用相同的凭据再次注册。