use of com.firebase.ui.auth.util.data.TaskFailureLogger in project FirebaseUI-Android by firebase.
the class ProfileMerger method then.
@Override
public Task<AuthResult> then(@NonNull Task<AuthResult> task) {
final AuthResult authResult = task.getResult();
FirebaseUser firebaseUser = authResult.getUser();
String name = firebaseUser.getDisplayName();
Uri photoUri = firebaseUser.getPhotoUrl();
if (!TextUtils.isEmpty(name) && photoUri != null) {
return Tasks.forResult(authResult);
}
User user = mResponse.getUser();
if (TextUtils.isEmpty(name)) {
name = user.getName();
}
if (photoUri == null) {
photoUri = user.getPhotoUri();
}
return firebaseUser.updateProfile(new UserProfileChangeRequest.Builder().setDisplayName(name).setPhotoUri(photoUri).build()).addOnFailureListener(new TaskFailureLogger(TAG, "Error updating profile")).continueWithTask(task1 -> Tasks.forResult(authResult));
}
use of com.firebase.ui.auth.util.data.TaskFailureLogger in project FirebaseUI-Android by firebase.
the class EmailProviderResponseHandler method startSignIn.
public void startSignIn(@NonNull final IdpResponse response, @NonNull final String password) {
if (!response.isSuccessful()) {
setResult(Resource.forFailure(response.getError()));
return;
}
if (!response.getProviderType().equals(EmailAuthProvider.PROVIDER_ID)) {
throw new IllegalStateException("This handler can only be used with the email provider");
}
setResult(Resource.forLoading());
final AuthOperationManager authOperationManager = AuthOperationManager.getInstance();
final String email = response.getEmail();
authOperationManager.createOrLinkUserWithEmailAndPassword(getAuth(), getArguments(), email, password).continueWithTask(new ProfileMerger(response)).addOnFailureListener(new TaskFailureLogger(TAG, "Error creating user")).addOnSuccessListener(result -> handleSuccess(response, result)).addOnFailureListener(e -> {
if (e instanceof FirebaseAuthUserCollisionException) {
if (authOperationManager.canUpgradeAnonymous(getAuth(), getArguments())) {
AuthCredential credential = EmailAuthProvider.getCredential(email, password);
handleMergeFailure(credential);
} else {
Log.w(TAG, "Got a collision error during a non-upgrade flow", e);
// Collision with existing user email without anonymous upgrade
// it should be very hard for the user to even get to this error
// due to CheckEmailFragment.
ProviderUtils.fetchTopProvider(getAuth(), getArguments(), email).addOnSuccessListener(new StartWelcomeBackFlow(email)).addOnFailureListener(e1 -> setResult(Resource.forFailure(e1)));
}
} else {
setResult(Resource.forFailure(e));
}
});
}
use of com.firebase.ui.auth.util.data.TaskFailureLogger in project FirebaseUI-Android by firebase.
the class EmailLinkSignInHandler method handleLinkingFlow.
private void handleLinkingFlow(final AuthOperationManager authOperationManager, final EmailLinkPersistenceManager persistenceManager, final IdpResponse response, final String link) {
final AuthCredential storedCredentialForLink = ProviderUtils.getAuthCredential(response);
final AuthCredential emailLinkCredential = EmailAuthProvider.getCredentialWithLink(response.getEmail(), link);
if (authOperationManager.canUpgradeAnonymous(getAuth(), getArguments())) {
authOperationManager.safeLink(emailLinkCredential, storedCredentialForLink, getArguments()).addOnCompleteListener(task -> {
persistenceManager.clearAllData(getApplication());
if (task.isSuccessful()) {
handleMergeFailure(storedCredentialForLink);
} else {
setResult(Resource.forFailure(task.getException()));
}
});
} else {
getAuth().signInWithCredential(emailLinkCredential).continueWithTask(task -> {
persistenceManager.clearAllData(getApplication());
if (!task.isSuccessful()) {
return task;
}
return task.getResult().getUser().linkWithCredential(storedCredentialForLink).continueWithTask(new ProfileMerger(response)).addOnFailureListener(new TaskFailureLogger(TAG, "linkWithCredential+merge failed."));
}).addOnSuccessListener(authResult -> {
FirebaseUser user = authResult.getUser();
IdpResponse response1 = new IdpResponse.Builder(new User.Builder(EmailAuthProvider.EMAIL_LINK_SIGN_IN_METHOD, user.getEmail()).setName(user.getDisplayName()).setPhotoUri(user.getPhotoUrl()).build()).build();
handleSuccess(response1, authResult);
}).addOnFailureListener(e -> setResult(Resource.forFailure(e)));
}
}
use of com.firebase.ui.auth.util.data.TaskFailureLogger in project FirebaseUI-Android by firebase.
the class WelcomeBackPasswordHandler method startSignIn.
/**
* Kick off the sign-in process.
*/
public void startSignIn(@NonNull final String email, @NonNull final String password, @NonNull final IdpResponse inputResponse, @Nullable final AuthCredential credential) {
setResult(Resource.forLoading());
// Store the password before signing in so it can be used for later credential building
mPendingPassword = password;
// Build appropriate IDP response based on inputs
final IdpResponse outputResponse;
if (credential == null) {
// New credential for the email provider
outputResponse = new IdpResponse.Builder(new User.Builder(EmailAuthProvider.PROVIDER_ID, email).build()).build();
} else {
// New credential for an IDP (Phone or Social)
outputResponse = new IdpResponse.Builder(inputResponse.getUser()).setPendingCredential(inputResponse.getCredentialForLinking()).setToken(inputResponse.getIdpToken()).setSecret(inputResponse.getIdpSecret()).build();
}
final AuthOperationManager authOperationManager = AuthOperationManager.getInstance();
if (authOperationManager.canUpgradeAnonymous(getAuth(), getArguments())) {
final AuthCredential credToValidate = EmailAuthProvider.getCredential(email, password);
// Check to see if we need to link (for social providers with the same email)
if (AuthUI.SOCIAL_PROVIDERS.contains(inputResponse.getProviderType())) {
// Add the provider to the same account before triggering a merge failure.
authOperationManager.safeLink(credToValidate, credential, getArguments()).addOnSuccessListener(result -> handleMergeFailure(credToValidate)).addOnFailureListener(e -> setResult(Resource.forFailure(e)));
} else {
// The user has not tried to log in with a federated IDP containing the same email.
// In this case, we just need to verify that the credential they provided is valid.
// No linking is done for non-federated IDPs.
// A merge failure occurs because the account exists and the user is anonymous.
authOperationManager.validateCredential(credToValidate, getArguments()).addOnCompleteListener(task -> {
if (task.isSuccessful()) {
handleMergeFailure(credToValidate);
} else {
setResult(Resource.forFailure(task.getException()));
}
});
}
} else {
// Kick off the flow including signing in, linking accounts, and saving with SmartLock
getAuth().signInWithEmailAndPassword(email, password).continueWithTask(task -> {
// Forward task failure by asking for result
AuthResult result = task.getResult(Exception.class);
// Task succeeded, link user if necessary
if (credential == null) {
return Tasks.forResult(result);
} else {
return result.getUser().linkWithCredential(credential).continueWithTask(new ProfileMerger(outputResponse)).addOnFailureListener(new TaskFailureLogger(TAG, "linkWithCredential+merge failed."));
}
}).addOnSuccessListener(result -> handleSuccess(outputResponse, result)).addOnFailureListener(e -> setResult(Resource.forFailure(e))).addOnFailureListener(new TaskFailureLogger(TAG, "signInWithEmailAndPassword failed."));
}
}
Aggregations