Search in sources :

Example 1 with FacebookProvider

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

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

the class AuthMethodPickerActivity method populateIdpList.

private void populateIdpList(List<IdpConfig> providers) {
    mIdpProviders = new ArrayList<>();
    for (IdpConfig idpConfig : providers) {
        switch(idpConfig.getProviderId()) {
            case AuthUI.GOOGLE_PROVIDER:
                mIdpProviders.add(new GoogleProvider(this, idpConfig));
                break;
            case AuthUI.FACEBOOK_PROVIDER:
                mIdpProviders.add(new FacebookProvider(this, idpConfig, mActivityHelper.getFlowParams().themeId));
                break;
            case AuthUI.TWITTER_PROVIDER:
                mIdpProviders.add(new TwitterProvider(this));
                break;
            case AuthUI.EMAIL_PROVIDER:
                findViewById(R.id.email_provider).setVisibility(View.VISIBLE);
                break;
            default:
                Log.e(TAG, "Encountered unknown IDPProvider parcel with type: " + idpConfig.getProviderId());
        }
    }
    ViewGroup btnHolder = (ViewGroup) findViewById(R.id.btn_holder);
    for (final IdpProvider provider : mIdpProviders) {
        View loginButton = null;
        switch(provider.getProviderId()) {
            case GoogleAuthProvider.PROVIDER_ID:
                loginButton = getLayoutInflater().inflate(R.layout.idp_button_google, btnHolder, false);
                break;
            case FacebookAuthProvider.PROVIDER_ID:
                loginButton = getLayoutInflater().inflate(R.layout.idp_button_facebook, btnHolder, false);
                break;
            case TwitterAuthProvider.PROVIDER_ID:
                loginButton = getLayoutInflater().inflate(R.layout.idp_button_twitter, btnHolder, false);
                break;
            default:
                Log.e(TAG, "No button for provider " + provider.getProviderId());
        }
        if (loginButton != null) {
            loginButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    mActivityHelper.showLoadingDialog(R.string.progress_dialog_loading);
                    provider.startLogin(AuthMethodPickerActivity.this);
                }
            });
            provider.setAuthenticationCallback(this);
            btnHolder.addView(loginButton, 0);
        }
    }
}
Also used : IdpConfig(com.firebase.ui.auth.AuthUI.IdpConfig) IdpProvider(com.firebase.ui.auth.provider.IdpProvider) TwitterProvider(com.firebase.ui.auth.provider.TwitterProvider) ViewGroup(android.view.ViewGroup) GoogleProvider(com.firebase.ui.auth.provider.GoogleProvider) ImageView(android.widget.ImageView) View(android.view.View) FacebookProvider(com.firebase.ui.auth.provider.FacebookProvider)

Example 3 with FacebookProvider

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

FacebookProvider (com.firebase.ui.auth.provider.FacebookProvider)3 GoogleProvider (com.firebase.ui.auth.provider.GoogleProvider)3 TwitterProvider (com.firebase.ui.auth.provider.TwitterProvider)3 View (android.view.View)2 IdpConfig (com.firebase.ui.auth.AuthUI.IdpConfig)2 User (com.firebase.ui.auth.ui.User)2 OnClickListener (android.view.View.OnClickListener)1 ViewGroup (android.view.ViewGroup)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 AuthUI (com.firebase.ui.auth.AuthUI)1 IdpResponse (com.firebase.ui.auth.IdpResponse)1 IdpProvider (com.firebase.ui.auth.provider.IdpProvider)1 FirebaseUser (com.google.firebase.auth.FirebaseUser)1