Search in sources :

Example 1 with CredentialsClient

use of com.google.android.gms.auth.api.credentials.CredentialsClient in project FirebaseUI-Android by firebase.

the class AuthUI method delete.

/**
 * Delete the use from FirebaseAuth and delete any associated credentials from the Credentials
 * API. Returns a {@link Task} that succeeds if the Firebase Auth user deletion succeeds and
 * fails if the Firebase Auth deletion fails. Credentials deletion failures are handled
 * silently.
 *
 * @param context the calling {@link Context}.
 */
@NonNull
public Task<Void> delete(@NonNull final 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);
    // Ensure the order in which tasks are executed properly destructures the user.
    return signOutIdps(context).continueWithTask(task -> {
        // Propagate exception if there was one
        task.getResult();
        if (!GoogleApiUtils.isPlayServicesAvailable(context)) {
            Log.w(TAG, "Google Play services not available during delete");
            return Tasks.forResult((Void) null);
        }
        final CredentialsClient client = GoogleApiUtils.getCredentialsClient(context);
        List<Task<?>> credentialTasks = new ArrayList<>();
        for (Credential credential : credentials) {
            credentialTasks.add(client.delete(credential));
        }
        return Tasks.whenAll(credentialTasks).continueWith(task1 -> {
            Exception e = task1.getException();
            Throwable t = e == null ? null : e.getCause();
            if (!(t instanceof ApiException) || ((ApiException) t).getStatusCode() != CommonStatusCodes.CANCELED) {
                // doesn't mean fully deleting the user failed.
                return task1.getResult();
            }
            return null;
        });
    }).continueWithTask(task -> {
        // Propagate exception if there was one
        task.getResult();
        return currentUser.delete();
    });
}
Also used : Scope(com.google.android.gms.common.api.Scope) Arrays(java.util.Arrays) Bundle(android.os.Bundle) UserInfo(com.google.firebase.auth.UserInfo) NonNull(androidx.annotation.NonNull) GoogleApiUtils(com.firebase.ui.auth.util.GoogleApiUtils) DrawableRes(androidx.annotation.DrawableRes) PhoneAuthProvider(com.google.firebase.auth.PhoneAuthProvider) GoogleAuthProvider(com.google.firebase.auth.GoogleAuthProvider) GoogleSignIn(com.google.android.gms.auth.api.signin.GoogleSignIn) RestrictTo(androidx.annotation.RestrictTo) Locale(java.util.Locale) Map(java.util.Map) GoogleSignInAccount(com.google.android.gms.auth.api.signin.GoogleSignInAccount) ProviderAvailability(com.firebase.ui.auth.util.data.ProviderAvailability) Log(android.util.Log) ActionCodeSettings(com.google.firebase.auth.ActionCodeSettings) IdentityHashMap(java.util.IdentityHashMap) FirebaseAuthProvider(com.google.firebase.auth.FirebaseAuthProvider) FirebaseUser(com.google.firebase.auth.FirebaseUser) Set(java.util.Set) FacebookAuthProvider(com.google.firebase.auth.FacebookAuthProvider) CredentialRequest(com.google.android.gms.auth.api.credentials.CredentialRequest) StyleRes(androidx.annotation.StyleRes) LoginManager(com.facebook.login.LoginManager) FlowParameters(com.firebase.ui.auth.data.model.FlowParameters) Preconditions(com.firebase.ui.auth.util.Preconditions) List(java.util.List) Tasks(com.google.android.gms.tasks.Tasks) Nullable(androidx.annotation.Nullable) AuthResult(com.google.firebase.auth.AuthResult) PhoneNumberUtils(com.firebase.ui.auth.util.data.PhoneNumberUtils) ApiException(com.google.android.gms.common.api.ApiException) Context(android.content.Context) ProviderUtils(com.firebase.ui.auth.util.data.ProviderUtils) GithubAuthProvider(com.google.firebase.auth.GithubAuthProvider) Intent(android.content.Intent) ExtraConstants(com.firebase.ui.auth.util.ExtraConstants) TwitterAuthProvider(com.google.firebase.auth.TwitterAuthProvider) HashMap(java.util.HashMap) Parcel(android.os.Parcel) Task(com.google.android.gms.tasks.Task) Retention(java.lang.annotation.Retention) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AuthMethodPickerActivity(com.firebase.ui.auth.ui.idp.AuthMethodPickerActivity) CredentialUtils(com.firebase.ui.auth.util.CredentialUtils) CredentialsClient(com.google.android.gms.auth.api.credentials.CredentialsClient) StringDef(androidx.annotation.StringDef) FirebaseAuth(com.google.firebase.auth.FirebaseAuth) Parcelable(android.os.Parcelable) FirebaseAuthInvalidUserException(com.google.firebase.auth.FirebaseAuthInvalidUserException) TextUtils(android.text.TextUtils) CallSuper(androidx.annotation.CallSuper) CommonStatusCodes(com.google.android.gms.common.api.CommonStatusCodes) AuthCredential(com.google.firebase.auth.AuthCredential) Credential(com.google.android.gms.auth.api.credentials.Credential) EmailAuthProvider(com.google.firebase.auth.EmailAuthProvider) Collections(java.util.Collections) GoogleSignInOptions(com.google.android.gms.auth.api.signin.GoogleSignInOptions) FirebaseApp(com.google.firebase.FirebaseApp) RetentionPolicy(java.lang.annotation.RetentionPolicy) CredentialsClient(com.google.android.gms.auth.api.credentials.CredentialsClient) FirebaseAuthInvalidUserException(com.google.firebase.auth.FirebaseAuthInvalidUserException) AuthCredential(com.google.firebase.auth.AuthCredential) Credential(com.google.android.gms.auth.api.credentials.Credential) List(java.util.List) ArrayList(java.util.ArrayList) FirebaseUser(com.google.firebase.auth.FirebaseUser) ApiException(com.google.android.gms.common.api.ApiException) FirebaseAuthInvalidUserException(com.google.firebase.auth.FirebaseAuthInvalidUserException) ApiException(com.google.android.gms.common.api.ApiException) NonNull(androidx.annotation.NonNull)

Aggregations

Context (android.content.Context)1 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 Parcel (android.os.Parcel)1 Parcelable (android.os.Parcelable)1 TextUtils (android.text.TextUtils)1 Log (android.util.Log)1 CallSuper (androidx.annotation.CallSuper)1 DrawableRes (androidx.annotation.DrawableRes)1 NonNull (androidx.annotation.NonNull)1 Nullable (androidx.annotation.Nullable)1 RestrictTo (androidx.annotation.RestrictTo)1 StringDef (androidx.annotation.StringDef)1 StyleRes (androidx.annotation.StyleRes)1 LoginManager (com.facebook.login.LoginManager)1 FlowParameters (com.firebase.ui.auth.data.model.FlowParameters)1 AuthMethodPickerActivity (com.firebase.ui.auth.ui.idp.AuthMethodPickerActivity)1 CredentialUtils (com.firebase.ui.auth.util.CredentialUtils)1 ExtraConstants (com.firebase.ui.auth.util.ExtraConstants)1 GoogleApiUtils (com.firebase.ui.auth.util.GoogleApiUtils)1