Search in sources :

Example 1 with IdpResponse

use of com.firebase.ui.auth.IdpResponse in project FirebaseUI-Android by firebase.

the class WelcomeBackIdpPrompt method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.welcome_back_idp_prompt_layout);
    IdpResponse newUserIdpResponse = IdpResponse.fromResultIntent(getIntent());
    mPrevCredential = AuthCredentialHelper.getAuthCredential(newUserIdpResponse);
    User oldUser = User.getUser(getIntent());
    String providerId = oldUser.getProvider();
    for (IdpConfig idpConfig : mActivityHelper.getFlowParams().providerInfo) {
        if (providerId.equals(idpConfig.getProviderId())) {
            switch(providerId) {
                case GoogleAuthProvider.PROVIDER_ID:
                    mIdpProvider = new GoogleProvider(this, idpConfig, oldUser.getEmail());
                    break;
                case FacebookAuthProvider.PROVIDER_ID:
                    mIdpProvider = new FacebookProvider(this, idpConfig, mActivityHelper.getFlowParams().themeId);
                    break;
                case TwitterAuthProvider.PROVIDER_ID:
                    mIdpProvider = new TwitterProvider(this);
                    break;
                default:
                    Log.w(TAG, "Unknown provider: " + providerId);
                    finish(ResultCodes.CANCELED, IdpResponse.getErrorCodeIntent(ErrorCodes.UNKNOWN_ERROR));
                    return;
            }
        }
    }
    if (mIdpProvider == null) {
        Log.w(TAG, "Firebase login unsuccessful." + " Account linking failed due to provider not enabled by application: " + providerId);
        finish(ResultCodes.CANCELED, IdpResponse.getErrorCodeIntent(ErrorCodes.UNKNOWN_ERROR));
        return;
    }
    ((TextView) findViewById(R.id.welcome_back_idp_prompt)).setText(getIdpPromptString(oldUser.getEmail()));
    mIdpProvider.setAuthenticationCallback(this);
    findViewById(R.id.welcome_back_idp_button).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            mActivityHelper.showLoadingDialog(R.string.progress_dialog_signing_in);
            mIdpProvider.startLogin(WelcomeBackIdpPrompt.this);
        }
    });
}
Also used : IdpConfig(com.firebase.ui.auth.AuthUI.IdpConfig) TwitterProvider(com.firebase.ui.auth.provider.TwitterProvider) FirebaseUser(com.google.firebase.auth.FirebaseUser) User(com.firebase.ui.auth.ui.User) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) GoogleProvider(com.firebase.ui.auth.provider.GoogleProvider) View(android.view.View) TextView(android.widget.TextView) IdpResponse(com.firebase.ui.auth.IdpResponse) FacebookProvider(com.firebase.ui.auth.provider.FacebookProvider)

Example 2 with IdpResponse

use of com.firebase.ui.auth.IdpResponse in project FirebaseUI-Android by firebase.

the class AuthUiActivity method handleSignInResponse.

@MainThread
private void handleSignInResponse(int resultCode, Intent data) {
    IdpResponse response = IdpResponse.fromResultIntent(data);
    // Successfully signed in
    if (resultCode == ResultCodes.OK) {
        startActivity(SignedInActivity.createIntent(this, response));
        finish();
        return;
    } else {
        // Sign in failed
        if (response == null) {
            // User pressed back button
            showSnackbar(R.string.sign_in_cancelled);
            return;
        }
        if (response.getErrorCode() == ErrorCodes.NO_NETWORK) {
            showSnackbar(R.string.no_internet_connection);
            return;
        }
        if (response.getErrorCode() == ErrorCodes.UNKNOWN_ERROR) {
            showSnackbar(R.string.unknown_error);
            return;
        }
    }
    showSnackbar(R.string.unknown_sign_in_response);
}
Also used : IdpResponse(com.firebase.ui.auth.IdpResponse) MainThread(android.support.annotation.MainThread)

Example 3 with IdpResponse

use of com.firebase.ui.auth.IdpResponse in project FirebaseUI-Android by firebase.

the class RegisterEmailActivity method onExistingIdpUser.

@Override
public void onExistingIdpUser(User user) {
    // Existing social user, direct them to sign in using their chosen provider.
    Intent intent = WelcomeBackIdpPrompt.createIntent(this, mActivityHelper.getFlowParams(), user, new IdpResponse(EmailAuthProvider.PROVIDER_ID, user.getEmail()));
    mActivityHelper.startActivityForResult(intent, RC_WELCOME_BACK_IDP);
    setSlideAnimation();
}
Also used : Intent(android.content.Intent) IdpResponse(com.firebase.ui.auth.IdpResponse)

Example 4 with IdpResponse

use of com.firebase.ui.auth.IdpResponse in project FirebaseUI-Android by firebase.

the class CredentialSignInHandlerTest method testSignInSucceeded.

@Test
public void testSignInSucceeded() {
    AppCompatBase mockActivity = mock(AppCompatBase.class);
    ActivityHelper mockActivityHelper = mock(ActivityHelper.class);
    FirebaseUser mockFirebaseUser = TestHelper.makeMockFirebaseUser();
    IdpResponse idpResponse = new IdpResponse(GoogleAuthProvider.PROVIDER_ID, TestConstants.EMAIL);
    SaveSmartLock smartLock = mock(SaveSmartLock.class);
    CredentialSignInHandler credentialSignInHandler = new CredentialSignInHandler(mockActivity, mockActivityHelper, smartLock, RC_ACCOUNT_LINK, idpResponse);
    Task signInTask = Tasks.forResult(new FakeAuthResult(mockFirebaseUser));
    when(mockActivityHelper.getFlowParams()).thenReturn(TestHelper.getFlowParameters(Collections.<String>emptyList()));
    credentialSignInHandler.onComplete(signInTask);
    ArgumentCaptor<SaveSmartLock> smartLockCaptor = ArgumentCaptor.forClass(SaveSmartLock.class);
    ArgumentCaptor<Activity> activityCaptor = ArgumentCaptor.forClass(Activity.class);
    ArgumentCaptor<FirebaseUser> firebaseUserCaptor = ArgumentCaptor.forClass(FirebaseUser.class);
    ArgumentCaptor<IdpResponse> idpResponseCaptor = ArgumentCaptor.forClass(IdpResponse.class);
    verify(mockActivityHelper).saveCredentialsOrFinish(smartLockCaptor.capture(), activityCaptor.capture(), firebaseUserCaptor.capture(), idpResponseCaptor.capture());
    assertEquals(smartLock, smartLockCaptor.getValue());
    assertEquals(mockActivity, activityCaptor.getValue());
    assertEquals(mockFirebaseUser, firebaseUserCaptor.getValue());
    assertEquals(idpResponse.getProviderType(), idpResponseCaptor.getValue().getProviderType());
    assertEquals(idpResponse.getEmail(), idpResponseCaptor.getValue().getEmail());
    assertEquals(idpResponse.getIdpToken(), idpResponseCaptor.getValue().getIdpToken());
    assertEquals(idpResponse.getIdpSecret(), idpResponseCaptor.getValue().getIdpSecret());
}
Also used : Task(com.google.android.gms.tasks.Task) AutoCompleteTask(com.firebase.ui.auth.testhelpers.AutoCompleteTask) AppCompatBase(com.firebase.ui.auth.ui.AppCompatBase) Activity(android.app.Activity) FirebaseUser(com.google.firebase.auth.FirebaseUser) FakeAuthResult(com.firebase.ui.auth.testhelpers.FakeAuthResult) ActivityHelper(com.firebase.ui.auth.ui.ActivityHelper) SaveSmartLock(com.firebase.ui.auth.util.signincontainer.SaveSmartLock) IdpResponse(com.firebase.ui.auth.IdpResponse) Test(org.junit.Test)

Example 5 with IdpResponse

use of com.firebase.ui.auth.IdpResponse in project FirebaseUI-Android by firebase.

the class CredentialSignInHandlerTest method testSignInFailed_withFacebookAlreadyLinked.

@Test
public void testSignInFailed_withFacebookAlreadyLinked() {
    AppCompatBase mockActivity = mock(AppCompatBase.class);
    ActivityHelper mockActivityHelper = mock(ActivityHelper.class);
    FirebaseAuth mockFirebaseAuth = mock(FirebaseAuth.class);
    IdpResponse idpResponse = new IdpResponse(GoogleAuthProvider.PROVIDER_ID, TestConstants.EMAIL);
    CredentialSignInHandler credentialSignInHandler = new CredentialSignInHandler(mockActivity, mockActivityHelper, null, RC_ACCOUNT_LINK, idpResponse);
    FlowParameters mockFlowParams = mock(FlowParameters.class);
    when(mockActivityHelper.getFirebaseAuth()).thenReturn(mockFirebaseAuth);
    when(mockActivityHelper.getFlowParams()).thenReturn(mockFlowParams);
    // pretend the account has Facebook linked already
    when(mockFirebaseAuth.fetchProvidersForEmail(TestConstants.EMAIL)).thenReturn(new AutoCompleteTask<ProviderQueryResult>(new FakeProviderQueryResult(Arrays.asList(FacebookAuthProvider.PROVIDER_ID)), true, null));
    // pretend there was already an account with this email
    Task exceptionTask = Tasks.forException(new FirebaseAuthUserCollisionException(LINKING_ERROR, LINKING_EXPLANATION));
    credentialSignInHandler.onComplete(exceptionTask);
    ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
    ArgumentCaptor<Integer> intCaptor = ArgumentCaptor.forClass(Integer.class);
    verify(mockActivity).startActivityForResult(intentCaptor.capture(), intCaptor.capture());
    Intent capturedIntent = intentCaptor.getValue();
    User capturedUser = User.getUser(capturedIntent);
    assertEquals(RC_ACCOUNT_LINK, (int) intCaptor.getValue());
    assertEquals(WelcomeBackIdpPrompt.class.getName(), capturedIntent.getComponent().getClassName());
    assertEquals(TestConstants.EMAIL, capturedUser.getEmail());
    assertEquals(FacebookAuthProvider.PROVIDER_ID, capturedUser.getProvider());
}
Also used : Task(com.google.android.gms.tasks.Task) AutoCompleteTask(com.firebase.ui.auth.testhelpers.AutoCompleteTask) FirebaseUser(com.google.firebase.auth.FirebaseUser) User(com.firebase.ui.auth.ui.User) AppCompatBase(com.firebase.ui.auth.ui.AppCompatBase) Intent(android.content.Intent) FakeProviderQueryResult(com.firebase.ui.auth.testhelpers.FakeProviderQueryResult) ProviderQueryResult(com.google.firebase.auth.ProviderQueryResult) ActivityHelper(com.firebase.ui.auth.ui.ActivityHelper) FlowParameters(com.firebase.ui.auth.ui.FlowParameters) FirebaseAuthUserCollisionException(com.google.firebase.auth.FirebaseAuthUserCollisionException) WelcomeBackIdpPrompt(com.firebase.ui.auth.ui.accountlink.WelcomeBackIdpPrompt) FakeProviderQueryResult(com.firebase.ui.auth.testhelpers.FakeProviderQueryResult) FirebaseAuth(com.google.firebase.auth.FirebaseAuth) IdpResponse(com.firebase.ui.auth.IdpResponse) Test(org.junit.Test)

Aggregations

IdpResponse (com.firebase.ui.auth.IdpResponse)81 Test (org.junit.Test)45 Resource (com.firebase.ui.auth.data.model.Resource)35 AuthCredential (com.google.firebase.auth.AuthCredential)31 InOrder (org.mockito.InOrder)31 FirebaseUiException (com.firebase.ui.auth.FirebaseUiException)22 FirebaseAuthAnonymousUpgradeException (com.firebase.ui.auth.FirebaseAuthAnonymousUpgradeException)19 FirebaseAuthUserCollisionException (com.google.firebase.auth.FirebaseAuthUserCollisionException)19 User (com.firebase.ui.auth.data.model.User)18 FirebaseUser (com.google.firebase.auth.FirebaseUser)15 AuthOperationManager (com.firebase.ui.auth.util.data.AuthOperationManager)12 EmailAuthCredential (com.google.firebase.auth.EmailAuthCredential)11 OnFailureListener (com.google.android.gms.tasks.OnFailureListener)10 OnSuccessListener (com.google.android.gms.tasks.OnSuccessListener)10 AuthResult (com.google.firebase.auth.AuthResult)10 Intent (android.content.Intent)9 Nullable (androidx.annotation.Nullable)9 IntentRequiredException (com.firebase.ui.auth.data.model.IntentRequiredException)9 Task (com.google.android.gms.tasks.Task)9 Application (android.app.Application)8