android - 如果用户在 FirebaseUI Auth 中退出或撤销提供者的访问权限,如何获知?
问题描述
我正在开发一个使用 Twitter 和电子邮件登录的 android 应用程序。我实现了 com.firebaseui:firebase-ui-auth:5.0.0。然后我正在检查用户是否已经登录,如果没有启动 FirebaseUI Auth 提供的登录活动:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
firebaseAuth = FirebaseAuth.getInstance();
List<AuthUI.IdpConfig> providers = Arrays.asList(
new AuthUI.IdpConfig.EmailBuilder().build(),
new AuthUI.IdpConfig.TwitterBuilder().build());
if (firebaseAuth.getCurrentUser() == null) {
startActivityForResult(
AuthUI.getInstance()
.createSignInIntentBuilder()
.setAvailableProviders(providers)
.setIsSmartLockEnabled(true)
.build(),
RC_SIGN_IN);
} else {
for (UserInfo profile : firebaseAuth.getCurrentUser().getProviderData()) {
if (profile.getProviderId().equals(TwitterAuthProvider.PROVIDER_ID)) {
// UID specific to the provider
String uid = profile.getUid();
String name = profile.getDisplayName();
String email = profile.getEmail();
Uri photoUrl = profile.getPhotoUrl();
}
}
startActivity(new Intent(this,MainActivity.class));
}
使用这种方法,我可以使用我的 Twitter 帐户登录并声明我的基本 Twitter 信息,例如姓名、电子邮件、照片 URL。但是,当我转到原始Twitter android 应用程序 > 设置 > 帐户 > 应用程序和会话并撤销对我的应用程序的访问权限,然后尝试再次打开我的应用程序时,我仍然可以索取我的 Twitter 信息。我想知道用户何时撤销对我的应用程序的访问权限,并且每当他们这样做时,我希望他们注销。我想知道如何克服这个问题,我也想知道这是否是这种情况的最佳做法。提前致谢。
解决方案
在 Firebase 身份验证期间,会生成一个令牌以确保安全。一旦将令牌提供给用户,它就会一直有效,直到过期。如果您撤销 Twitter 帐户的访问权限,这并不意味着令牌已过期。这只是意味着如果用户退出,他将无法再次使用 Twitter 帐户进行另一次身份验证,因为访问权限已被撤销。不幸的是,您无法远程强制用户退出,因为您也不可能以某种方式访问用户的设备并删除令牌。任何注销都需要在用户登录的设备上进行。
因此,即使您从 Firebase 控制台禁用该用户的帐户,该用户仍可以继续访问长达一个小时。如果这不是您想要的,有一种解决方法,您可以在 Cloud Firestore 或 Firebase 实时数据库中添加和维护“已撤销”用户列表,然后使用Firebase Security Rules 对其进行检查。
例如,在实时数据库中,如果用户 id 的撤销列表可能如下所示:
revoked
|
--- uidOne: true
|
--- uidTwo: true
然后相应的安全规则可能如下所示:
".read": "auth.uid !== null && !root.child('revoked').child(auth.uid).exists()"
推荐阅读
- javascript - Javascript将变量分配给名称以数字开头的对象字段
- python - 是否有一个 Geopy Python 函数可以将数据框列(纬度/经度)从“度分秒”转换为“度小数”
- javascript - 有没有办法获得多个输入值?
- python - 为什么我的网络抓取没有返回任何内容?
- angular - 获取参数 Angular
- excel - 如果与 Power Query 中的多个列匹配
- react-native - 运行请求的 app expo ios 时出现问题
- c# - 如何从连接字符串中删除“Provider=...”
- excel - 从 Word 粘贴到 Excel 时,Word VBA 宏有时会锁定
- java - 与扩展和字段混淆