我目前正在从我的应用中删除FirebaseUI Auth,并将其替换为"原始"Firebase Auth代码。
所以现在我通过GoogleSignInClient.silentSignIn()
和GoogleSignInClient.getSignInIntent()
登录Google 登录用户,并通过GoogleSignInClient.signOut()
注销用户。
通过FirebaseUser.delete()
删除Firebase用户时,我还需要调用AuthUI.delete()
。我假设AuthUI
是为所有OAuth提供程序提供通用接口的FirebaseUI
的一部分。在寻找等效GoogleSignInClient.delete()
时,我什么也没找到。
由于我将不再使用 FirebaseUI 身份验证,因此对AuthUI.delete()
的调用将过时,但我想知道该调用执行了什么。它与谷歌登录有关吗?我还需要删除某些内容吗?
AuthUI.delete()
用于删除用户,并在一个方法调用中删除与该用户相关的所有提供程序。源代码:
public Task<Void> delete(@NonNull Context context) {
final FirebaseUser currentUser = mAuth.getCurrentUser();
if (currentUser == null) {
return Tasks.forException(new FirebaseAuthInvalidUserException(
String.valueOf(CommonStatusCodes.SIGN_IN_REQUIRED),
"No currently signed in user."));
}
final List<Credential> credentials = getCredentialsFromFirebaseUser(currentUser);
final CredentialsClient client = GoogleApiUtils.getCredentialsClient(context);
// Ensure the order in which tasks are executed properly destructures the user.
return signOutIdps(context).continueWithTask(new Continuation<Void, Task<Void>>() {
@Override
public Task<Void> then(@NonNull Task<Void> task) {
task.getResult(); // Propagate exception if there was one
List<Task<?>> credentialTasks = new ArrayList<>();
for (Credential credential : credentials) {
credentialTasks.add(client.delete(credential));
}
return Tasks.whenAll(credentialTasks)
.continueWith(new Continuation<Void, Void>() {
@Override
public Void then(@NonNull Task<Void> task) {
Exception e = task.getException();
Throwable t = e == null ? null : e.getCause();
if (!(t instanceof ApiException)
|| ((ApiException) t).getStatusCode() !=
CommonStatusCodes.CANCELED) {
// Only propagate the exception if it isn't an invalid account
// one. This can occur if we failed to save the credential or it
// was deleted elsewhere. However, a lack of stored credential
// doesn't mean fully deleting the user failed.
return task.getResult();
}
return null;
}
});
}
}).continueWithTask(new Continuation<Void, Task<Void>>() {
@Override
public Task<Void> then(@NonNull Task<Void> task) {
task.getResult(); // Propagate exception if there was one
return currentUser.delete();
}
});
}
https://github.com/firebase/FirebaseUI-Android/blob/master/auth/src/main/java/com/firebase/ui/auth/AuthUI.java
如果您不想使用AuthUI
并且想要删除使用 Google 提供商登录的用户,则首先需要获取凭据,重新验证用户并删除。
例如:
AuthCredential credential = GoogleAuthProvider.getCredential(FirebaseAuth.getInstance().getCurrentUser().getUid(), null);
user.reauthenticate(credential).addOnCompleteListener...