Search in sources :

Example 1 with AuthResult

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

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

the class ChatActivity method signInAnonymously.

private void signInAnonymously() {
    Toast.makeText(this, "Signing in...", Toast.LENGTH_SHORT).show();
    mAuth.signInAnonymously().addOnSuccessListener(this, new OnSuccessListener<AuthResult>() {

        @Override
        public void onSuccess(AuthResult result) {
            attachRecyclerViewAdapter();
        }
    }).addOnCompleteListener(new SignInResultNotifier(this));
}
Also used : SignInResultNotifier(com.firebase.uidemo.util.SignInResultNotifier) AuthResult(com.google.firebase.auth.AuthResult) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener)

Example 3 with AuthResult

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

the class RegisterEmailActivityTest method testSignUpButton_successfulRegistrationShouldContinueToSaveCredentials.

@Test
@Config(shadows = { BaseHelperShadow.class, ActivityHelperShadow.class })
public void testSignUpButton_successfulRegistrationShouldContinueToSaveCredentials() {
    // init mocks
    new BaseHelperShadow();
    reset(BaseHelperShadow.sSaveSmartLock);
    TestHelper.initializeApp(RuntimeEnvironment.application);
    RegisterEmailActivity registerEmailActivity = createActivity();
    // Trigger new user UI (bypassing check email)
    registerEmailActivity.onNewUser(new User.Builder(TestConstants.EMAIL).setName(TestConstants.NAME).setPhotoUri(TestConstants.PHOTO_URI).build());
    EditText name = (EditText) registerEmailActivity.findViewById(R.id.name);
    EditText password = (EditText) registerEmailActivity.findViewById(R.id.password);
    name.setText(TestConstants.NAME);
    password.setText(TestConstants.PASSWORD);
    FirebaseUser mockFirebaseUser = Mockito.mock(FirebaseUser.class);
    when(mockFirebaseUser.getEmail()).thenReturn(TestConstants.EMAIL);
    when(mockFirebaseUser.getDisplayName()).thenReturn(TestConstants.NAME);
    when(mockFirebaseUser.getPhotoUrl()).thenReturn(TestConstants.PHOTO_URI);
    when(mockFirebaseUser.updateProfile((UserProfileChangeRequest) Mockito.any())).thenReturn(new AutoCompleteTask<Void>(null, true, null));
    when(BaseHelperShadow.sFirebaseAuth.createUserWithEmailAndPassword(TestConstants.EMAIL, TestConstants.PASSWORD)).thenReturn(new AutoCompleteTask<AuthResult>(new FakeAuthResult(mockFirebaseUser), true, null));
    Button button = (Button) registerEmailActivity.findViewById(R.id.button_create);
    button.performClick();
    TestHelper.verifySmartLockSave(EmailAuthProvider.PROVIDER_ID, TestConstants.EMAIL, TestConstants.PASSWORD);
}
Also used : EditText(android.widget.EditText) Button(android.widget.Button) BaseHelperShadow(com.firebase.ui.auth.testhelpers.BaseHelperShadow) 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 4 with AuthResult

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

the class AuthMethodPickerActivityTest method testFacebookLoginFlow.

@Test
@Config(shadows = { BaseHelperShadow.class, ActivityHelperShadow.class })
public void testFacebookLoginFlow() {
    // initialize mocks
    new ActivityHelperShadow();
    reset(ActivityHelperShadow.sSaveSmartLock);
    FirebaseUser mockFirebaseUser = TestHelper.makeMockFirebaseUser();
    when(mockFirebaseUser.getProviders()).thenReturn(Arrays.asList(FacebookAuthProvider.PROVIDER_ID));
    when(ActivityHelperShadow.sFirebaseAuth.signInWithCredential((AuthCredential) any())).thenReturn(new AutoCompleteTask<AuthResult>(new FakeAuthResult(mockFirebaseUser), true, null));
    List<String> providers = Arrays.asList(AuthUI.FACEBOOK_PROVIDER);
    AuthMethodPickerActivity authMethodPickerActivity = createActivity(providers);
    FacebookSdk.sdkInitialize(authMethodPickerActivity);
    Button facebookButton = (Button) authMethodPickerActivity.findViewById(R.id.facebook_button);
    assertNotNull(facebookButton);
    facebookButton.performClick();
    verifySmartLockSave(AuthUI.FACEBOOK_PROVIDER, TestConstants.EMAIL, null);
}
Also used : ActivityHelperShadow(com.firebase.ui.auth.testhelpers.ActivityHelperShadow) Button(android.widget.Button) 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 5 with AuthResult

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

the class AuthMethodPickerActivityTest method testGoogleLoginFlow.

@Test
@Config(shadows = { GoogleProviderShadow.class, BaseHelperShadow.class, ActivityHelperShadow.class })
public void testGoogleLoginFlow() {
    // initialize mocks
    new ActivityHelperShadow();
    reset(ActivityHelperShadow.sSaveSmartLock);
    List<String> providers = Arrays.asList(AuthUI.GOOGLE_PROVIDER);
    AuthMethodPickerActivity authMethodPickerActivity = createActivity(providers);
    FirebaseUser mockFirebaseUser = TestHelper.makeMockFirebaseUser();
    when(mockFirebaseUser.getProviders()).thenReturn(Arrays.asList(GoogleAuthProvider.PROVIDER_ID));
    when(ActivityHelperShadow.sFirebaseAuth.signInWithCredential((AuthCredential) any())).thenReturn(new AutoCompleteTask<AuthResult>(new FakeAuthResult(mockFirebaseUser), true, null));
    Button googleButton = (Button) authMethodPickerActivity.findViewById(R.id.google_button);
    assertNotNull(googleButton);
    googleButton.performClick();
    verifySmartLockSave(AuthUI.GOOGLE_PROVIDER, TestConstants.EMAIL, null);
}
Also used : ActivityHelperShadow(com.firebase.ui.auth.testhelpers.ActivityHelperShadow) Button(android.widget.Button) 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)

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