Search in sources :

Example 1 with User

use of com.firebase.ui.auth.ui.User 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 User

use of com.firebase.ui.auth.ui.User 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)

Example 3 with User

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

the class IdpSignInContainer method onCreate.

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mSaveSmartLock = mHelper.getSaveSmartLockInstance(getActivity());
    User user = User.getUser(getArguments());
    String provider = user.getProvider();
    AuthUI.IdpConfig providerConfig = null;
    for (AuthUI.IdpConfig config : mHelper.getFlowParams().providerInfo) {
        if (config.getProviderId().equalsIgnoreCase(provider)) {
            providerConfig = config;
            break;
        }
    }
    if (providerConfig == null) {
        // we don't have a provider to handle this
        finish(ResultCodes.CANCELED, IdpResponse.getErrorCodeIntent(ErrorCodes.UNKNOWN_ERROR));
        return;
    }
    if (provider.equalsIgnoreCase(GoogleAuthProvider.PROVIDER_ID)) {
        mIdpProvider = new GoogleProvider(getActivity(), providerConfig, user.getEmail());
    } else if (provider.equalsIgnoreCase(FacebookAuthProvider.PROVIDER_ID)) {
        mIdpProvider = new FacebookProvider(getContext(), providerConfig, mHelper.getFlowParams().themeId);
    } else if (provider.equalsIgnoreCase(TwitterAuthProvider.PROVIDER_ID)) {
        mIdpProvider = new TwitterProvider(getContext());
    }
    mIdpProvider.setAuthenticationCallback(this);
    if (savedInstanceState == null) {
        mIdpProvider.startLogin(getActivity());
    }
}
Also used : TwitterProvider(com.firebase.ui.auth.provider.TwitterProvider) User(com.firebase.ui.auth.ui.User) GoogleProvider(com.firebase.ui.auth.provider.GoogleProvider) AuthUI(com.firebase.ui.auth.AuthUI) FacebookProvider(com.firebase.ui.auth.provider.FacebookProvider)

Aggregations

User (com.firebase.ui.auth.ui.User)3 IdpResponse (com.firebase.ui.auth.IdpResponse)2 FacebookProvider (com.firebase.ui.auth.provider.FacebookProvider)2 GoogleProvider (com.firebase.ui.auth.provider.GoogleProvider)2 TwitterProvider (com.firebase.ui.auth.provider.TwitterProvider)2 FirebaseUser (com.google.firebase.auth.FirebaseUser)2 Intent (android.content.Intent)1 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 TextView (android.widget.TextView)1 AuthUI (com.firebase.ui.auth.AuthUI)1 IdpConfig (com.firebase.ui.auth.AuthUI.IdpConfig)1 AutoCompleteTask (com.firebase.ui.auth.testhelpers.AutoCompleteTask)1 FakeProviderQueryResult (com.firebase.ui.auth.testhelpers.FakeProviderQueryResult)1 ActivityHelper (com.firebase.ui.auth.ui.ActivityHelper)1 AppCompatBase (com.firebase.ui.auth.ui.AppCompatBase)1 FlowParameters (com.firebase.ui.auth.ui.FlowParameters)1 WelcomeBackIdpPrompt (com.firebase.ui.auth.ui.accountlink.WelcomeBackIdpPrompt)1 Task (com.google.android.gms.tasks.Task)1 FirebaseAuth (com.google.firebase.auth.FirebaseAuth)1