Search in sources :

Example 11 with ActionCodeSettings

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

the class EmailActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.fui_activity_register_email);
    if (savedInstanceState != null) {
        return;
    }
    // Get email from intent (can be null)
    String email = getIntent().getExtras().getString(ExtraConstants.EMAIL);
    IdpResponse responseForLinking = getIntent().getExtras().getParcelable(ExtraConstants.IDP_RESPONSE);
    if (email != null && responseForLinking != null) {
        // got here from WelcomeBackEmailLinkPrompt
        AuthUI.IdpConfig emailConfig = ProviderUtils.getConfigFromIdpsOrThrow(getFlowParams().providers, EMAIL_LINK_PROVIDER);
        ActionCodeSettings actionCodeSettings = emailConfig.getParams().getParcelable(ExtraConstants.ACTION_CODE_SETTINGS);
        EmailLinkPersistenceManager.getInstance().saveIdpResponseForLinking(getApplication(), responseForLinking);
        boolean forceSameDevice = emailConfig.getParams().getBoolean(ExtraConstants.FORCE_SAME_DEVICE);
        EmailLinkFragment fragment = EmailLinkFragment.newInstance(email, actionCodeSettings, responseForLinking, forceSameDevice);
        switchFragment(fragment, R.id.fragment_register_email, EmailLinkFragment.TAG);
    } else {
        AuthUI.IdpConfig emailConfig = ProviderUtils.getConfigFromIdps(getFlowParams().providers, EmailAuthProvider.PROVIDER_ID);
        if (emailConfig != null) {
            email = emailConfig.getParams().getString(ExtraConstants.DEFAULT_EMAIL);
            ;
        }
        // Start with check email
        CheckEmailFragment fragment = CheckEmailFragment.newInstance(email);
        switchFragment(fragment, R.id.fragment_register_email, CheckEmailFragment.TAG);
    }
}
Also used : ActionCodeSettings(com.google.firebase.auth.ActionCodeSettings) AuthUI(com.firebase.ui.auth.AuthUI) IdpResponse(com.firebase.ui.auth.IdpResponse)

Example 12 with ActionCodeSettings

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

the class ConfigurationUtils method getConfiguredProviders.

@NonNull
public static List<AuthUI.IdpConfig> getConfiguredProviders(@NonNull Context context) {
    List<AuthUI.IdpConfig> providers = new ArrayList<>();
    if (!isGoogleMisconfigured(context)) {
        providers.add(new AuthUI.IdpConfig.GoogleBuilder().build());
    }
    if (!isFacebookMisconfigured(context)) {
        providers.add(new AuthUI.IdpConfig.FacebookBuilder().build());
    }
    ActionCodeSettings actionCodeSettings = ActionCodeSettings.newBuilder().setAndroidPackageName("com.firebase.uidemo", true, null).setHandleCodeInApp(true).setUrl("https://google.com").build();
    providers.add(new AuthUI.IdpConfig.EmailBuilder().setAllowNewAccounts(true).enableEmailLinkSignIn().setActionCodeSettings(actionCodeSettings).build());
    providers.add(new AuthUI.IdpConfig.TwitterBuilder().build());
    providers.add(new AuthUI.IdpConfig.PhoneBuilder().build());
    providers.add(new AuthUI.IdpConfig.MicrosoftBuilder().build());
    providers.add(new AuthUI.IdpConfig.YahooBuilder().build());
    providers.add(new AuthUI.IdpConfig.AppleBuilder().build());
    return providers;
}
Also used : ArrayList(java.util.ArrayList) AuthUI(com.firebase.ui.auth.AuthUI) ActionCodeSettings(com.google.firebase.auth.ActionCodeSettings) NonNull(androidx.annotation.NonNull)

Example 13 with ActionCodeSettings

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

the class AuthUiActivity method getSelectedProviders.

private List<IdpConfig> getSelectedProviders() {
    List<IdpConfig> selectedProviders = new ArrayList<>();
    if (mBinding.googleProvider.isChecked()) {
        selectedProviders.add(new IdpConfig.GoogleBuilder().setScopes(getGoogleScopes()).build());
    }
    if (mBinding.facebookProvider.isChecked()) {
        selectedProviders.add(new IdpConfig.FacebookBuilder().setPermissions(getFacebookPermissions()).build());
    }
    if (mBinding.emailProvider.isChecked()) {
        selectedProviders.add(new IdpConfig.EmailBuilder().setRequireName(mBinding.requireName.isChecked()).setAllowNewAccounts(mBinding.allowNewEmailAccounts.isChecked()).build());
    }
    if (mBinding.emailLinkProvider.isChecked()) {
        ActionCodeSettings actionCodeSettings = ActionCodeSettings.newBuilder().setAndroidPackageName("com.firebase.uidemo", true, null).setHandleCodeInApp(true).setUrl("https://google.com").build();
        selectedProviders.add(new IdpConfig.EmailBuilder().setAllowNewAccounts(mBinding.allowNewEmailAccounts.isChecked()).setActionCodeSettings(actionCodeSettings).enableEmailLinkSignIn().build());
    }
    if (mBinding.phoneProvider.isChecked()) {
        selectedProviders.add(new IdpConfig.PhoneBuilder().build());
    }
    if (mBinding.anonymousProvider.isChecked()) {
        selectedProviders.add(new IdpConfig.AnonymousBuilder().build());
    }
    if (mBinding.twitterProvider.isChecked()) {
        selectedProviders.add(new IdpConfig.TwitterBuilder().build());
    }
    if (mBinding.microsoftProvider.isChecked()) {
        selectedProviders.add(new IdpConfig.MicrosoftBuilder().build());
    }
    if (mBinding.yahooProvider.isChecked()) {
        selectedProviders.add(new IdpConfig.YahooBuilder().build());
    }
    if (mBinding.appleProvider.isChecked()) {
        selectedProviders.add(new IdpConfig.AppleBuilder().build());
    }
    if (mBinding.githubProvider.isChecked()) {
        selectedProviders.add(new IdpConfig.GitHubBuilder().build());
    }
    return selectedProviders;
}
Also used : IdpConfig(com.firebase.ui.auth.AuthUI.IdpConfig) ArrayList(java.util.ArrayList) ActionCodeSettings(com.google.firebase.auth.ActionCodeSettings)

Example 14 with ActionCodeSettings

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

the class EmailLinkFragment method onActivityCreated.

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    initHandler();
    String email = getArguments().getString(ExtraConstants.EMAIL);
    ActionCodeSettings actionCodeSettings = getArguments().getParcelable(ExtraConstants.ACTION_CODE_SETTINGS);
    IdpResponse idpResponseForLinking = getArguments().getParcelable(ExtraConstants.IDP_RESPONSE);
    boolean forceSameDevice = getArguments().getBoolean(ExtraConstants.FORCE_SAME_DEVICE);
    if (!mEmailSent) {
        mEmailLinkSendEmailHandler.sendSignInLinkToEmail(email, actionCodeSettings, idpResponseForLinking, forceSameDevice);
    }
}
Also used : ActionCodeSettings(com.google.firebase.auth.ActionCodeSettings) IdpResponse(com.firebase.ui.auth.IdpResponse)

Example 15 with ActionCodeSettings

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

the class EmailLinkSendEmailHandlerTest method testSendSignInLinkToEmail_linkingFlow_expectSuccess.

@Test
public void testSendSignInLinkToEmail_linkingFlow_expectSuccess() {
    mHandler.getOperation().observeForever(mResponseObserver);
    boolean forceSameDevice = true;
    ActionCodeSettings actionCodeSettings = ActionCodeSettings.newBuilder().setUrl(URL).build();
    when(mMockAuth.sendSignInLinkToEmail(any(String.class), any(ActionCodeSettings.class))).thenReturn(AutoCompleteTask.forFailure(new Exception()));
    IdpResponse idpResponseForLinking = buildFacebookIdpResponseForLinking();
    mHandler.sendSignInLinkToEmail(TestConstants.EMAIL, actionCodeSettings, idpResponseForLinking, forceSameDevice);
    ArgumentCaptor<ActionCodeSettings> acsCaptor = ArgumentCaptor.forClass(ActionCodeSettings.class);
    verify(mMockAuth).sendSignInLinkToEmail(eq(TestConstants.EMAIL), acsCaptor.capture());
    validateSessionIdAddedToContinueUrl(acsCaptor.getValue(), idpResponseForLinking.getProviderType(), forceSameDevice);
    ArgumentCaptor<Resource<String>> captor = ArgumentCaptor.forClass(Resource.class);
    InOrder inOrder = inOrder(mResponseObserver);
    inOrder.verify(mResponseObserver).onChanged(argThat(ResourceMatchers.isLoading()));
    inOrder.verify(mResponseObserver).onChanged(captor.capture());
    assertThat(captor.getValue().getState()).isEqualTo(State.FAILURE);
    assertThat(captor.getValue().getException()).isNotNull();
}
Also used : InOrder(org.mockito.InOrder) ActionCodeSettings(com.google.firebase.auth.ActionCodeSettings) Resource(com.firebase.ui.auth.data.model.Resource) IdpResponse(com.firebase.ui.auth.IdpResponse) Test(org.junit.Test)

Aggregations

ActionCodeSettings (com.google.firebase.auth.ActionCodeSettings)15 Test (org.junit.Test)8 IdpConfig (com.firebase.ui.auth.AuthUI.IdpConfig)6 IdpResponse (com.firebase.ui.auth.IdpResponse)3 Resource (com.firebase.ui.auth.data.model.Resource)3 InOrder (org.mockito.InOrder)3 AuthUI (com.firebase.ui.auth.AuthUI)2 ArrayList (java.util.ArrayList)2 NonNull (androidx.annotation.NonNull)1 FirebaseAuthActionCodeException (com.google.firebase.auth.FirebaseAuthActionCodeException)1 FirebaseAuthInvalidCredentialsException (com.google.firebase.auth.FirebaseAuthInvalidCredentialsException)1