gpt4 book ai didi

java - 调用 AuthUI.getInstance().delete() 时 AuthUI 正在删除什么?

转载 作者:行者123 更新时间:2023-12-02 01:10:36 25 4
gpt4 key购买 nike

我目前正在从我的应用中删除 FirebaseUI Auth,并将其替换为“原始”Firebase Auth 代码。

现在,我通过 GoogleSignInClient.silentSignIn()GoogleSignInClient.getSignInIntent() 登录 Google Sign-In 用户,并且通过 GoogleSignInClient.signOut() 注销用户。

通过 FirebaseUser.delete() 删除 Firebase 用户时,我还需要调用 AuthUI.delete()。我假设 AuthUI 是 FirebaseUI 的一部分,它为所有 OAuth 提供者提供通用接口(interface)。在搜索等效的 GoogleSignInClient.delete() 时,我没有找到任何内容。

由于我将不再使用 FirebaseUI Auth,因此对 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...

关于java - 调用 AuthUI.getInstance().delete() 时 AuthUI 正在删除什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59453355/

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