Search in sources :

Example 6 with AuthCredential

use of com.google.firebase.auth.AuthCredential 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)

Example 7 with AuthCredential

use of com.google.firebase.auth.AuthCredential in project FirebaseUI-Android by firebase.

the class WelcomeBackPasswordPrompt method next.

private void next(final String email, final String password) {
    // Check for null or empty password
    if (TextUtils.isEmpty(password)) {
        mPasswordLayout.setError(getString(R.string.required_field));
        return;
    } else {
        mPasswordLayout.setError(null);
    }
    mActivityHelper.showLoadingDialog(R.string.progress_dialog_signing_in);
    final FirebaseAuth firebaseAuth = mActivityHelper.getFirebaseAuth();
    // Sign in with known email and the password provided
    firebaseAuth.signInWithEmailAndPassword(email, password).addOnFailureListener(new TaskFailureLogger(TAG, "Error signing in with email and password")).addOnSuccessListener(new OnSuccessListener<AuthResult>() {

        @Override
        public void onSuccess(AuthResult authResult) {
            AuthCredential authCredential = AuthCredentialHelper.getAuthCredential(mIdpResponse);
            // Otherwise, the user has an email account that we need to link to an idp.
            if (authCredential == null) {
                mActivityHelper.saveCredentialsOrFinish(mSaveSmartLock, authResult.getUser(), password, new IdpResponse(EmailAuthProvider.PROVIDER_ID, email));
            } else {
                authResult.getUser().linkWithCredential(authCredential).addOnFailureListener(new TaskFailureLogger(TAG, "Error signing in with credential " + authCredential.getProvider())).addOnSuccessListener(new OnSuccessListener<AuthResult>() {

                    @Override
                    public void onSuccess(AuthResult authResult) {
                        mActivityHelper.saveCredentialsOrFinish(mSaveSmartLock, authResult.getUser(), mIdpResponse);
                    }
                });
            }
        }
    }).addOnFailureListener(this, new OnFailureListener() {

        @Override
        public void onFailure(@NonNull Exception e) {
            mActivityHelper.dismissDialog();
            String error = e.getLocalizedMessage();
            mPasswordLayout.setError(error);
        }
    });
}
Also used : AuthCredential(com.google.firebase.auth.AuthCredential) TaskFailureLogger(com.firebase.ui.auth.ui.TaskFailureLogger) AuthResult(com.google.firebase.auth.AuthResult) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) OnFailureListener(com.google.android.gms.tasks.OnFailureListener) FirebaseAuth(com.google.firebase.auth.FirebaseAuth) IdpResponse(com.firebase.ui.auth.IdpResponse)

Example 8 with AuthCredential

use of com.google.firebase.auth.AuthCredential in project quickstart-android by firebase.

the class GoogleSignInActivity method firebaseAuthWithGoogle.

// [END onactivityresult]
// [START auth_with_google]
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
    Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId());
    // [START_EXCLUDE silent]
    showProgressDialog();
    // [END_EXCLUDE]
    AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
    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(GoogleSignInActivity.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)

Example 9 with AuthCredential

use of com.google.firebase.auth.AuthCredential in project quickstart-android by firebase.

the class TwitterLoginActivity method handleTwitterSession.

// [END on_activity_result]
// [START auth_with_twitter]
private void handleTwitterSession(TwitterSession session) {
    Log.d(TAG, "handleTwitterSession:" + session);
    // [START_EXCLUDE silent]
    showProgressDialog();
    // [END_EXCLUDE]
    AuthCredential credential = TwitterAuthProvider.getCredential(session.getAuthToken().token, session.getAuthToken().secret);
    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(TwitterLoginActivity.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