Search in sources :

Example 1 with AuthCredential

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));
    }
}
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 AuthCredential

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));
}
Also used : AuthCredential(com.google.firebase.auth.AuthCredential) TaskFailureLogger(com.firebase.ui.auth.ui.TaskFailureLogger) CredentialSignInHandler(com.firebase.ui.auth.ui.idp.CredentialSignInHandler)

Example 3 with AuthCredential

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]
}
Also used : AuthCredential(com.google.firebase.auth.AuthCredential) AuthResult(com.google.firebase.auth.AuthResult)

Example 4 with AuthCredential

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();
            }
        }
    });
}
Also used : AuthCredential(com.google.firebase.auth.AuthCredential) AuthResult(com.google.firebase.auth.AuthResult) Intent(android.content.Intent)

Example 5 with AuthCredential

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]
        }
    });
}
Also used : AuthCredential(com.google.firebase.auth.AuthCredential) AuthResult(com.google.firebase.auth.AuthResult)

Aggregations

AuthCredential (com.google.firebase.auth.AuthCredential)9 AuthResult (com.google.firebase.auth.AuthResult)7 TaskFailureLogger (com.firebase.ui.auth.ui.TaskFailureLogger)4 OnFailureListener (com.google.android.gms.tasks.OnFailureListener)2 Intent (android.content.Intent)1 NonNull (android.support.annotation.NonNull)1 IdpResponse (com.firebase.ui.auth.IdpResponse)1 CredentialSignInHandler (com.firebase.ui.auth.ui.idp.CredentialSignInHandler)1 OnSuccessListener (com.google.android.gms.tasks.OnSuccessListener)1 FirebaseAuth (com.google.firebase.auth.FirebaseAuth)1 FirebaseUser (com.google.firebase.auth.FirebaseUser)1