Java Code Examples for com.firebase.ui.auth.AuthUI#IdpConfig

The following examples show how to use com.firebase.ui.auth.AuthUI#IdpConfig . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GenericIdpSignInHandlerTest.java    From FirebaseUI-Android with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
    TestHelper.initialize();
    MockitoAnnotations.initMocks(this);

    FlowParameters testParams
            = TestHelper.getFlowParameters(
            Arrays.asList(MICROSOFT_PROVIDER, GoogleAuthProvider.PROVIDER_ID),
            /* enableAnonymousUpgrade= */ true);
    when(mMockActivity.getFlowParams()).thenReturn(testParams);

    mHandler = new GenericIdpSignInHandler(
            (Application) ApplicationProvider.getApplicationContext());

    Map<String, String> customParams = new HashMap<>();
    customParams.put(CUSTOM_PARAMETER_KEY, CUSTOM_PARAMETER_VALUE);

    AuthUI.IdpConfig config
            = new AuthUI.IdpConfig.MicrosoftBuilder()
            .setScopes(Arrays.asList(SCOPE))
            .setCustomParameters(customParams)
            .build();
    mHandler.initializeForTesting(config);
    mHandler.getOperation().observeForever(mResponseObserver);
}
 
Example 2
Source File: GenericIdpAnonymousUpgradeLinkingHandlerTest.java    From FirebaseUI-Android with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
    TestHelper.initialize();
    MockitoAnnotations.initMocks(this);

    FlowParameters testParams
            = TestHelper.getFlowParameters(
            Arrays.asList(MICROSOFT_PROVIDER, GoogleAuthProvider.PROVIDER_ID),
            /* enableAnonymousUpgrade= */ true);
    when(mMockActivity.getFlowParams()).thenReturn(testParams);
    when(mMockWelcomeBackIdpPrompt.getFlowParams()).thenReturn(testParams);

    mHandler = new GenericIdpAnonymousUpgradeLinkingHandler(
            (Application) ApplicationProvider.getApplicationContext());

    Map<String, String> customParams = new HashMap<>();
    customParams.put(CUSTOM_PARAMETER_KEY, CUSTOM_PARAMETER_VALUE);

    AuthUI.IdpConfig config
            = new AuthUI.IdpConfig.MicrosoftBuilder()
            .setScopes(Arrays.asList(SCOPE))
            .setCustomParameters(customParams)
            .build();
    mHandler.initializeForTesting(config);
    mHandler.getOperation().observeForever(mResponseObserver);
}
 
Example 3
Source File: FirebaseUIActivity.java    From snippets-android with Apache License 2.0 6 votes vote down vote up
public void createSignInIntent() {
    // [START auth_fui_create_intent]
    // Choose authentication providers
    List<AuthUI.IdpConfig> providers = Arrays.asList(
            new AuthUI.IdpConfig.EmailBuilder().build(),
            new AuthUI.IdpConfig.PhoneBuilder().build(),
            new AuthUI.IdpConfig.GoogleBuilder().build(),
            new AuthUI.IdpConfig.FacebookBuilder().build(),
            new AuthUI.IdpConfig.TwitterBuilder().build());

    // Create and launch sign-in intent
    startActivityForResult(
            AuthUI.getInstance()
                    .createSignInIntentBuilder()
                    .setAvailableProviders(providers)
                    .build(),
            RC_SIGN_IN);
    // [END auth_fui_create_intent]
}
 
Example 4
Source File: SignInKickstarter.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
private List<String> getCredentialAccountTypes() {
    List<String> accounts = new ArrayList<>();
    for (AuthUI.IdpConfig idpConfig : getArguments().providers) {
        @AuthUI.SupportedProvider String providerId = idpConfig.getProviderId();
        if (providerId.equals(GoogleAuthProvider.PROVIDER_ID)) {
            accounts.add(ProviderUtils.providerIdToAccountType(providerId));
        }
    }
    return accounts;
}
 
Example 5
Source File: ProviderUtils.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
@NonNull
public static AuthUI.IdpConfig getConfigFromIdpsOrThrow(List<AuthUI.IdpConfig> idps,
                                                        String id) {
    AuthUI.IdpConfig config = getConfigFromIdps(idps, id);
    if (config == null) {
        throw new IllegalStateException("Provider " + id + " not found.");
    }
    return config;
}
 
Example 6
Source File: ProviderUtils.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
@Nullable
public static AuthUI.IdpConfig getConfigFromIdps(List<AuthUI.IdpConfig> idps, String id) {
    for (AuthUI.IdpConfig idp : idps) {
        if (idp.getProviderId().equals(id)) {
            return idp;
        }
    }
    return null;
}
 
Example 7
Source File: EmailActivity.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
private void showRegisterEmailLinkFragment(AuthUI.IdpConfig emailConfig,
                                           String email) {
    ActionCodeSettings actionCodeSettings = emailConfig.getParams().getParcelable
            (ExtraConstants.ACTION_CODE_SETTINGS);
    EmailLinkFragment fragment = EmailLinkFragment.newInstance(email,
            actionCodeSettings);
    switchFragment(fragment, R.id.fragment_register_email, EmailLinkFragment.TAG);
}
 
Example 8
Source File: EmailActivity.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
@Override
public void onClickResendEmail(String email) {
    if (getSupportFragmentManager().getBackStackEntryCount() > 0) {
        // We're assuming that to get to the TroubleSigningInFragment, we went through
        // the EmailLinkFragment, which was added to the fragment back stack.
        // From here, we're going to register the EmailLinkFragment again, meaning we'd have to
        // pop off the back stack twice to return to the nascar screen. To avoid this,
        // we pre-emptively pop off the last EmailLinkFragment here.
        getSupportFragmentManager().popBackStack();
    }
    AuthUI.IdpConfig emailConfig = ProviderUtils.getConfigFromIdpsOrThrow(
            getFlowParams().providers, EmailAuthProvider.EMAIL_LINK_SIGN_IN_METHOD);
    showRegisterEmailLinkFragment(
            emailConfig, email);
}
 
Example 9
Source File: EmailActivity.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
@Override
public void onNewUser(User user) {
    // New user, direct them to create an account with email/password
    // if account creation is enabled in SignInIntentBuilder

    TextInputLayout emailLayout = findViewById(R.id.email_layout);
    AuthUI.IdpConfig emailConfig = ProviderUtils.getConfigFromIdps(getFlowParams().providers,
            EmailAuthProvider.PROVIDER_ID);

    if (emailConfig == null) {
        emailConfig = ProviderUtils.getConfigFromIdps(getFlowParams().providers,
                EMAIL_LINK_PROVIDER);
    }

    if (emailConfig.getParams().getBoolean(ExtraConstants.ALLOW_NEW_EMAILS, true)) {
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        if (emailConfig.getProviderId().equals(EMAIL_LINK_PROVIDER)) {
            showRegisterEmailLinkFragment(emailConfig, user.getEmail());
        } else {
            RegisterEmailFragment fragment = RegisterEmailFragment.newInstance(user);
            ft.replace(R.id.fragment_register_email, fragment, RegisterEmailFragment.TAG);
            if (emailLayout != null) {
                String emailFieldName = getString(R.string.fui_email_field_name);
                ViewCompat.setTransitionName(emailLayout, emailFieldName);
                ft.addSharedElement(emailLayout, emailFieldName);
            }
            ft.disallowAddToBackStack().commit();
        }
    } else {
        emailLayout.setError(getString(R.string.fui_error_email_does_not_exist));
    }
}
 
Example 10
Source File: EmailActivity.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
@Override
public void onExistingEmailUser(User user) {
    if (user.getProviderId().equals(EMAIL_LINK_PROVIDER)) {
        AuthUI.IdpConfig emailConfig = ProviderUtils.getConfigFromIdpsOrThrow(
                getFlowParams().providers, EMAIL_LINK_PROVIDER);
        showRegisterEmailLinkFragment(
                emailConfig, user.getEmail());
    } else {
        startActivityForResult(
                WelcomeBackPasswordPrompt.createIntent(
                        this, getFlowParams(), new IdpResponse.Builder(user).build()),
                RequestCodes.WELCOME_BACK_EMAIL_FLOW);
        setSlideAnimation();
    }
}
 
Example 11
Source File: SignInKickstarter.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
private void startAuthMethodChoice() {
    // If there is only one provider selected, launch the flow directly
    if (!getArguments().shouldShowProviderChoice()) {
        AuthUI.IdpConfig firstIdpConfig = getArguments().providers.get(0);
        String firstProvider = firstIdpConfig.getProviderId();
        switch (firstProvider) {
            case EMAIL_LINK_PROVIDER:
            case EmailAuthProvider.PROVIDER_ID:
                setResult(Resource.<IdpResponse>forFailure(new IntentRequiredException(
                        EmailActivity.createIntent(getApplication(), getArguments()),
                        RequestCodes.EMAIL_FLOW)));
                break;
            case PhoneAuthProvider.PROVIDER_ID:
                setResult(Resource.<IdpResponse>forFailure(new IntentRequiredException(
                        PhoneActivity.createIntent(
                                getApplication(), getArguments(), firstIdpConfig.getParams()),
                        RequestCodes.PHONE_FLOW)));
                break;
            default:
                redirectSignIn(firstProvider, null);
                break;
        }
    } else {
        setResult(Resource.<IdpResponse>forFailure(new IntentRequiredException(
                AuthMethodPickerActivity.createIntent(getApplication(), getArguments()),
                RequestCodes.AUTH_PICKER_FLOW)));
    }
}
 
Example 12
Source File: ConfigurationUtils.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 13
Source File: AnonymousUpgradeActivity.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
@OnClick(R.id.begin_flow)
public void startAuthUI() {
    List<AuthUI.IdpConfig> providers = ConfigurationUtils.getConfiguredProviders(this);
    Intent intent = AuthUI.getInstance().createSignInIntentBuilder()
            .setLogo(R.drawable.firebase_auth_120dp)
            .setAvailableProviders(providers)
            .enableAnonymousUsersAutoUpgrade()
            .build();
    startActivityForResult(intent, RC_SIGN_IN);
}
 
Example 14
Source File: FirebaseUIActivity.java    From snippets-android with Apache License 2.0 5 votes vote down vote up
public void privacyAndTerms() {
    List<AuthUI.IdpConfig> providers = Collections.emptyList();
    // [START auth_fui_pp_tos]
    startActivityForResult(
            AuthUI.getInstance()
                    .createSignInIntentBuilder()
                    .setAvailableProviders(providers)
                    .setTosAndPrivacyPolicyUrls(
                            "https://example.com/terms.html",
                            "https://example.com/privacy.html")
                    .build(),
            RC_SIGN_IN);
    // [END auth_fui_pp_tos]
}
 
Example 15
Source File: FirebaseUIActivity.java    From snippets-android with Apache License 2.0 5 votes vote down vote up
public void themeAndLogo() {
    List<AuthUI.IdpConfig> providers = Collections.emptyList();

    // [START auth_fui_theme_logo]
    startActivityForResult(
            AuthUI.getInstance()
                    .createSignInIntentBuilder()
                    .setAvailableProviders(providers)
                    .setLogo(R.drawable.my_great_logo)      // Set logo drawable
                    .setTheme(R.style.MySuperAppTheme)      // Set theme
                    .build(),
            RC_SIGN_IN);
    // [END auth_fui_theme_logo]
}
 
Example 16
Source File: GoogleSignInHandler.java    From FirebaseUI-Android with Apache License 2.0 4 votes vote down vote up
public Params(AuthUI.IdpConfig config, @Nullable String email) {
    this.config = config;
    this.email = email;
}
 
Example 17
Source File: GoogleSignInHandler.java    From FirebaseUI-Android with Apache License 2.0 4 votes vote down vote up
public Params(AuthUI.IdpConfig config) {
    this(config, null);
}
 
Example 18
Source File: GenericIdpSignInHandler.java    From FirebaseUI-Android with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
public void initializeForTesting(AuthUI.IdpConfig idpConfig) {
    setArguments(idpConfig);
}