Search in sources :

Example 1 with TaskFailureLogger

use of com.firebase.ui.auth.ui.TaskFailureLogger in project FirebaseUI-Android by firebase.

the class WelcomeBackIdpPrompt method onSuccess.

@Override
public void onSuccess(final IdpResponse idpResponse) {
    if (idpResponse == null) {
        // do nothing
        return;
    }
    AuthCredential newCredential = AuthCredentialHelper.getAuthCredential(idpResponse);
    if (newCredential == null) {
        Log.e(TAG, "No credential returned");
        finish(ResultCodes.CANCELED, IdpResponse.getErrorCodeIntent(ErrorCodes.UNKNOWN_ERROR));
        return;
    }
    FirebaseUser currentUser = mActivityHelper.getCurrentUser();
    if (currentUser == null) {
        mActivityHelper.getFirebaseAuth().signInWithCredential(newCredential).addOnSuccessListener(new OnSuccessListener<AuthResult>() {

            @Override
            public void onSuccess(AuthResult result) {
                if (mPrevCredential != null) {
                    result.getUser().linkWithCredential(mPrevCredential).addOnFailureListener(new TaskFailureLogger(TAG, "Error signing in with previous credential " + idpResponse.getProviderType())).addOnCompleteListener(new FinishListener(idpResponse));
                } else {
                    finish(ResultCodes.OK, IdpResponse.getIntent(idpResponse));
                }
            }
        }).addOnFailureListener(new OnFailureListener() {

            @Override
            public void onFailure(@NonNull Exception e) {
                finishWithError();
            }
        }).addOnFailureListener(new TaskFailureLogger(TAG, "Error signing in with new credential " + idpResponse.getProviderType()));
    } else {
        currentUser.linkWithCredential(newCredential).addOnFailureListener(new TaskFailureLogger(TAG, "Error linking with credential " + idpResponse.getProviderType())).addOnCompleteListener(new FinishListener(idpResponse));
    }
}
Also used : AuthCredential(com.google.firebase.auth.AuthCredential) TaskFailureLogger(com.firebase.ui.auth.ui.TaskFailureLogger) NonNull(android.support.annotation.NonNull) AuthResult(com.google.firebase.auth.AuthResult) FirebaseUser(com.google.firebase.auth.FirebaseUser) OnFailureListener(com.google.android.gms.tasks.OnFailureListener)

Example 2 with TaskFailureLogger

use of com.firebase.ui.auth.ui.TaskFailureLogger in project FirebaseUI-Android by firebase.

the class CredentialSignInHandler method onComplete.

@Override
public void onComplete(@NonNull Task<AuthResult> task) {
    if (task.isSuccessful()) {
        FirebaseUser firebaseUser = task.getResult().getUser();
        mHelper.saveCredentialsOrFinish(mSmartLock, mActivity, firebaseUser, mResponse);
    } else {
        if (task.getException() instanceof FirebaseAuthUserCollisionException) {
            final String email = mResponse.getEmail();
            if (email != null) {
                mHelper.getFirebaseAuth().fetchProvidersForEmail(email).addOnFailureListener(new TaskFailureLogger(TAG, "Error fetching providers for email")).addOnSuccessListener(new StartWelcomeBackFlow()).addOnFailureListener(new OnFailureListener() {

                    @Override
                    public void onFailure(@NonNull Exception e) {
                    // TODO: What to do when signing in with Credential fails
                    // and we can't continue to Welcome back flow without
                    // knowing providers?
                    }
                });
                return;
            }
        } else {
            Log.e(TAG, "Unexpected exception when signing in with credential " + mResponse.getProviderType() + " unsuccessful. Visit https://console.firebase.google.com to enable it.", task.getException());
        }
        mHelper.dismissDialog();
    }
}
Also used : TaskFailureLogger(com.firebase.ui.auth.ui.TaskFailureLogger) FirebaseAuthUserCollisionException(com.google.firebase.auth.FirebaseAuthUserCollisionException) FirebaseUser(com.google.firebase.auth.FirebaseUser) OnFailureListener(com.google.android.gms.tasks.OnFailureListener) FirebaseAuthUserCollisionException(com.google.firebase.auth.FirebaseAuthUserCollisionException)

Example 3 with TaskFailureLogger

use of com.firebase.ui.auth.ui.TaskFailureLogger in project FirebaseUI-Android by firebase.

the class IdpSignInContainer method onSuccess.

@Override
public void onSuccess(final IdpResponse response) {
    AuthCredential credential = AuthCredentialHelper.getAuthCredential(response);
    mHelper.getFirebaseAuth().signInWithCredential(credential).addOnFailureListener(new TaskFailureLogger(TAG, "Failure authenticating with credential " + credential.getProvider())).addOnCompleteListener(new CredentialSignInHandler(getActivity(), mHelper, mSaveSmartLock, RC_WELCOME_BACK_IDP, response));
}
Also used : AuthCredential(com.google.firebase.auth.AuthCredential) TaskFailureLogger(com.firebase.ui.auth.ui.TaskFailureLogger) CredentialSignInHandler(com.firebase.ui.auth.ui.idp.CredentialSignInHandler)

Example 4 with TaskFailureLogger

use of com.firebase.ui.auth.ui.TaskFailureLogger in project FirebaseUI-Android by firebase.

the class RegisterEmailFragment method registerUser.

private void registerUser(final String email, final String name, final String password) {
    mHelper.getFirebaseAuth().createUserWithEmailAndPassword(email, password).addOnFailureListener(new TaskFailureLogger(TAG, "Error creating user")).addOnSuccessListener(new OnSuccessListener<AuthResult>() {

        @Override
        public void onSuccess(AuthResult authResult) {
            // Set display name
            UserProfileChangeRequest changeNameRequest = new UserProfileChangeRequest.Builder().setDisplayName(name).setPhotoUri(mUser.getPhotoUri()).build();
            final FirebaseUser user = authResult.getUser();
            user.updateProfile(changeNameRequest).addOnFailureListener(new TaskFailureLogger(TAG, "Error setting display name")).addOnCompleteListener(new OnCompleteListener<Void>() {

                @Override
                public void onComplete(@NonNull Task<Void> task) {
                    // This executes even if the name change fails, since
                    // the account creation succeeded and we want to save
                    // the credential to SmartLock (if enabled).
                    mHelper.saveCredentialsOrFinish(mSaveSmartLock, getActivity(), user, password, new IdpResponse(EmailAuthProvider.PROVIDER_ID, email));
                }
            });
        }
    }).addOnFailureListener(getActivity(), new OnFailureListener() {

        @Override
        public void onFailure(@NonNull Exception e) {
            mHelper.dismissDialog();
            if (e instanceof FirebaseAuthWeakPasswordException) {
                // Password too weak
                mPasswordInput.setError(getResources().getQuantityString(R.plurals.error_weak_password, R.integer.min_password_length));
            } else if (e instanceof FirebaseAuthInvalidCredentialsException) {
                // Email address is malformed
                mEmailInput.setError(getString(R.string.invalid_email_address));
            } else if (e instanceof FirebaseAuthUserCollisionException) {
                // Collision with existing user email, it should be very hard for
                // the user to even get to this error due to CheckEmailFragment.
                mEmailInput.setError(getString(R.string.error_user_collision));
            } else {
                // General error message, this branch should not be invoked but
                // covers future API changes
                mEmailInput.setError(getString(R.string.email_account_creation_error));
            }
        }
    });
}
Also used : TaskFailureLogger(com.firebase.ui.auth.ui.TaskFailureLogger) FirebaseAuthWeakPasswordException(com.google.firebase.auth.FirebaseAuthWeakPasswordException) UserProfileChangeRequest(com.google.firebase.auth.UserProfileChangeRequest) AuthResult(com.google.firebase.auth.AuthResult) FirebaseUser(com.google.firebase.auth.FirebaseUser) FirebaseAuthWeakPasswordException(com.google.firebase.auth.FirebaseAuthWeakPasswordException) FirebaseAuthInvalidCredentialsException(com.google.firebase.auth.FirebaseAuthInvalidCredentialsException) FirebaseAuthUserCollisionException(com.google.firebase.auth.FirebaseAuthUserCollisionException) FirebaseAuthInvalidCredentialsException(com.google.firebase.auth.FirebaseAuthInvalidCredentialsException) FirebaseAuthUserCollisionException(com.google.firebase.auth.FirebaseAuthUserCollisionException) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) OnFailureListener(com.google.android.gms.tasks.OnFailureListener) IdpResponse(com.firebase.ui.auth.IdpResponse)

Example 5 with TaskFailureLogger

use of com.firebase.ui.auth.ui.TaskFailureLogger in project FirebaseUI-Android by firebase.

the class AuthMethodPickerActivity method onSuccess.

@Override
public void onSuccess(final IdpResponse response) {
    AuthCredential credential = AuthCredentialHelper.getAuthCredential(response);
    mActivityHelper.getFirebaseAuth().signInWithCredential(credential).addOnFailureListener(new TaskFailureLogger(TAG, "Firebase sign in with credential " + credential.getProvider() + " unsuccessful. Visit https://console.firebase.google.com to enable it.")).addOnCompleteListener(new CredentialSignInHandler(this, mActivityHelper, mSaveSmartLock, RC_ACCOUNT_LINK, response));
}
Also used : AuthCredential(com.google.firebase.auth.AuthCredential) TaskFailureLogger(com.firebase.ui.auth.ui.TaskFailureLogger)

Aggregations

TaskFailureLogger (com.firebase.ui.auth.ui.TaskFailureLogger)7 OnFailureListener (com.google.android.gms.tasks.OnFailureListener)5 AuthCredential (com.google.firebase.auth.AuthCredential)4 OnSuccessListener (com.google.android.gms.tasks.OnSuccessListener)3 AuthResult (com.google.firebase.auth.AuthResult)3 FirebaseUser (com.google.firebase.auth.FirebaseUser)3 IdpResponse (com.firebase.ui.auth.IdpResponse)2 FirebaseAuthUserCollisionException (com.google.firebase.auth.FirebaseAuthUserCollisionException)2 NonNull (android.support.annotation.NonNull)1 CredentialSignInHandler (com.firebase.ui.auth.ui.idp.CredentialSignInHandler)1 FirebaseAuth (com.google.firebase.auth.FirebaseAuth)1 FirebaseAuthInvalidCredentialsException (com.google.firebase.auth.FirebaseAuthInvalidCredentialsException)1 FirebaseAuthInvalidUserException (com.google.firebase.auth.FirebaseAuthInvalidUserException)1 FirebaseAuthWeakPasswordException (com.google.firebase.auth.FirebaseAuthWeakPasswordException)1 UserProfileChangeRequest (com.google.firebase.auth.UserProfileChangeRequest)1