Search in sources :

Example 6 with AuthResult

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

the class AuthMethodPickerActivityTest method testTwitterLoginFlowStarts.

@Test
@Config(shadows = { ActivityHelperShadow.class })
public void testTwitterLoginFlowStarts() {
    List<String> providers = Arrays.asList(AuthUI.TWITTER_PROVIDER);
    AuthMethodPickerActivity authMethodPickerActivity = createActivity(providers);
    FirebaseUser mockFirebaseUser = TestHelper.makeMockFirebaseUser();
    when(mockFirebaseUser.getProviders()).thenReturn(Arrays.asList(TwitterAuthProvider.PROVIDER_ID));
    when(ActivityHelperShadow.sFirebaseAuth.signInWithCredential((AuthCredential) any())).thenReturn(new AutoCompleteTask<AuthResult>(new FakeAuthResult(mockFirebaseUser), true, null));
    Button twitterButton = (Button) authMethodPickerActivity.findViewById(R.id.twitter_button);
    assertNotNull(twitterButton);
    twitterButton.performClick();
    ShadowActivity.IntentForResult nextIntent = Shadows.shadowOf(authMethodPickerActivity).getNextStartedActivityForResult();
    assertTrue(nextIntent.intent.getComponent().getClassName().contains("com.twitter.sdk"));
}
Also used : Button(android.widget.Button) ShadowActivity(org.robolectric.shadows.ShadowActivity) FakeAuthResult(com.firebase.ui.auth.testhelpers.FakeAuthResult) AuthResult(com.google.firebase.auth.AuthResult) FirebaseUser(com.google.firebase.auth.FirebaseUser) FakeAuthResult(com.firebase.ui.auth.testhelpers.FakeAuthResult) Test(org.junit.Test) Config(org.robolectric.annotation.Config) BuildConfig(com.firebase.ui.auth.BuildConfig)

Example 7 with AuthResult

use of com.google.firebase.auth.AuthResult 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 8 with AuthResult

use of com.google.firebase.auth.AuthResult 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 9 with AuthResult

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

Example 10 with AuthResult

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

the class MainActivity method signInAnonymously.

private void signInAnonymously() {
    // Sign in anonymously. Authentication is required to read or write from Firebase Storage.
    showProgressDialog(getString(R.string.progress_auth));
    mAuth.signInAnonymously().addOnSuccessListener(this, new OnSuccessListener<AuthResult>() {

        @Override
        public void onSuccess(AuthResult authResult) {
            Log.d(TAG, "signInAnonymously:SUCCESS");
            hideProgressDialog();
            updateUI(authResult.getUser());
        }
    }).addOnFailureListener(this, new OnFailureListener() {

        @Override
        public void onFailure(@NonNull Exception exception) {
            Log.e(TAG, "signInAnonymously:FAILURE", exception);
            hideProgressDialog();
            updateUI(null);
        }
    });
}
Also used : AuthResult(com.google.firebase.auth.AuthResult) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) OnFailureListener(com.google.android.gms.tasks.OnFailureListener)

Aggregations

AuthResult (com.google.firebase.auth.AuthResult)15 AuthCredential (com.google.firebase.auth.AuthCredential)7 FirebaseUser (com.google.firebase.auth.FirebaseUser)7 Button (android.widget.Button)5 BuildConfig (com.firebase.ui.auth.BuildConfig)5 FakeAuthResult (com.firebase.ui.auth.testhelpers.FakeAuthResult)5 Test (org.junit.Test)5 Config (org.robolectric.annotation.Config)5 OnFailureListener (com.google.android.gms.tasks.OnFailureListener)4 OnSuccessListener (com.google.android.gms.tasks.OnSuccessListener)4 ActivityHelperShadow (com.firebase.ui.auth.testhelpers.ActivityHelperShadow)3 TaskFailureLogger (com.firebase.ui.auth.ui.TaskFailureLogger)3 EditText (android.widget.EditText)2 IdpResponse (com.firebase.ui.auth.IdpResponse)2 Intent (android.content.Intent)1 NonNull (android.support.annotation.NonNull)1 BaseHelperShadow (com.firebase.ui.auth.testhelpers.BaseHelperShadow)1 WelcomeBackPasswordPrompt (com.firebase.ui.auth.ui.accountlink.WelcomeBackPasswordPrompt)1 SignInResultNotifier (com.firebase.uidemo.util.SignInResultNotifier)1 FirebaseAuth (com.google.firebase.auth.FirebaseAuth)1