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

因此,现在我要通过GoogleSignInClient.silentSignIn()GoogleSignInClient.getSignInIntent()登录Google登录用户,并通过GoogleSignInClient.signOut()注销用户。

通过FirebaseUser.delete()删除Firebase用户时,我还需要致电AuthUI.delete()。我认为AuthUIFirebaseUI的一部分,它为所有OAuth提供程序提供了通用接口。在搜索等效的GoogleSignInClient.delete()时,我什么也没找到。

由于我将不再使用FirebaseUI Auth,因此对AuthUI.delete()的此调用将作废,但我想知道该调用执行了什么。与Google登录有关吗?我还需要删除一些内容吗?

最佳答案

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...

08-07 00:56