use of com.google.firebase.auth.AuthCredential 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));
}
}
use of com.google.firebase.auth.AuthCredential 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));
}
use of com.google.firebase.auth.AuthCredential in project quickstart-android by firebase.
the class AnonymousAuthActivity method linkAccount.
private void linkAccount() {
// Make sure form is valid
if (!validateLinkForm()) {
return;
}
// Get email and password from form
String email = mEmailField.getText().toString();
String password = mPasswordField.getText().toString();
// Create EmailAuthCredential with email and password
AuthCredential credential = EmailAuthProvider.getCredential(email, password);
// Link the anonymous user to the email credential
showProgressDialog();
// [START link_credential]
mAuth.getCurrentUser().linkWithCredential(credential).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.d(TAG, "linkWithCredential:onComplete:" + task.isSuccessful());
// signed in user can be handled in the listener.
if (!task.isSuccessful()) {
Toast.makeText(AnonymousAuthActivity.this, "Authentication failed.", Toast.LENGTH_SHORT).show();
}
// [START_EXCLUDE]
hideProgressDialog();
// [END_EXCLUDE]
}
});
// [END link_credential]
}
use of com.google.firebase.auth.AuthCredential in project RSAndroidApp by RailwayStations.
the class SignInActivity method firebaseAuthWithGoogle.
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId());
AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
mFirebaseAuth.signInWithCredential(credential).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful());
// signed in user can be handled in the listener.
if (!task.isSuccessful()) {
Log.w(TAG, "signInWithCredential", task.getException());
Toast.makeText(SignInActivity.this, "Authentication failed.", Toast.LENGTH_SHORT).show();
} else {
((BaseApplication) getApplication()).saveSubscribtionStatus(true);
startActivity(new Intent(SignInActivity.this, AuthActivity.class));
finish();
}
}
});
}
use of com.google.firebase.auth.AuthCredential in project quickstart-android by firebase.
the class FacebookLoginActivity method handleFacebookAccessToken.
// [END on_activity_result]
// [START auth_with_facebook]
private void handleFacebookAccessToken(AccessToken token) {
Log.d(TAG, "handleFacebookAccessToken:" + token);
// [START_EXCLUDE silent]
showProgressDialog();
// [END_EXCLUDE]
AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken());
mAuth.signInWithCredential(credential).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful());
// signed in user can be handled in the listener.
if (!task.isSuccessful()) {
Log.w(TAG, "signInWithCredential", task.getException());
Toast.makeText(FacebookLoginActivity.this, "Authentication failed.", Toast.LENGTH_SHORT).show();
}
// [START_EXCLUDE]
hideProgressDialog();
// [END_EXCLUDE]
}
});
}
Aggregations