com.google.firebase.auth.TwitterAuthProvider Java Examples

The following examples show how to use com.google.firebase.auth.TwitterAuthProvider. 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: FirestackAuth.java    From react-native-firestack with MIT License 6 votes vote down vote up
@ReactMethod
public void twitterLogin(String Token, String Secret, final Callback callback) {
    mAuth = FirebaseAuth.getInstance();

    AuthCredential credential = TwitterAuthProvider.getCredential(Token, Secret);
    mAuth.signInWithCredential(credential)
            .addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                  if (task.isSuccessful()) {
                      FirestackAuthModule.this.user = task.getResult().getUser();
                      userCallback(FirestackAuthModule.this.user, callback);
                  }else{
                      // userErrorCallback(task, callback);
                  }
                }
            }).addOnFailureListener(new OnFailureListener() {
          @Override
          public void onFailure(@NonNull Exception ex) {
            userExceptionCallback(ex, callback);
          }
        });
}
 
Example #2
Source File: IdpResponse.java    From FirebaseUI-Android with Apache License 2.0 6 votes vote down vote up
public IdpResponse build() {
    if (mPendingCredential != null && mUser == null) {
        return new IdpResponse(mPendingCredential, new FirebaseUiException(ErrorCodes
                .ANONYMOUS_UPGRADE_MERGE_CONFLICT));
    }

    String providerId = mUser.getProviderId();
    if (AuthUI.SOCIAL_PROVIDERS.contains(providerId) && TextUtils.isEmpty(mToken)) {
        throw new IllegalStateException(
                "Token cannot be null when using a non-email provider.");
    }
    if (providerId.equals(TwitterAuthProvider.PROVIDER_ID)
            && TextUtils.isEmpty(mSecret)) {
        throw new IllegalStateException(
                "Secret cannot be null when using the Twitter provider.");
    }
    return new IdpResponse(mUser, mToken, mSecret, mPendingCredential, mIsNewUser);
}
 
Example #3
Source File: ProviderUtils.java    From FirebaseUI-Android with Apache License 2.0 6 votes vote down vote up
@NonNull
@AuthUI.SupportedProvider
public static String signInMethodToProviderId(@NonNull String method) {
    switch (method) {
        case GoogleAuthProvider.GOOGLE_SIGN_IN_METHOD:
            return GoogleAuthProvider.PROVIDER_ID;
        case FacebookAuthProvider.FACEBOOK_SIGN_IN_METHOD:
            return FacebookAuthProvider.PROVIDER_ID;
        case TwitterAuthProvider.TWITTER_SIGN_IN_METHOD:
            return TwitterAuthProvider.PROVIDER_ID;
        case GithubAuthProvider.GITHUB_SIGN_IN_METHOD:
            return GithubAuthProvider.PROVIDER_ID;
        case PhoneAuthProvider.PHONE_SIGN_IN_METHOD:
            return PhoneAuthProvider.PROVIDER_ID;
        case EmailAuthProvider.EMAIL_PASSWORD_SIGN_IN_METHOD:
            return EmailAuthProvider.PROVIDER_ID;
        case EmailAuthProvider.EMAIL_LINK_SIGN_IN_METHOD:
            return EMAIL_LINK_PROVIDER;
        default:
            return method;
    }
}
 
Example #4
Source File: ProviderUtils.java    From FirebaseUI-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Translate a Firebase Auth provider ID (such as {@link GoogleAuthProvider#PROVIDER_ID}) to a
 * Credentials API account type (such as {@link IdentityProviders#GOOGLE}).
 */
public static String providerIdToAccountType(
        @AuthUI.SupportedProvider @NonNull String providerId) {
    switch (providerId) {
        case GoogleAuthProvider.PROVIDER_ID:
            return IdentityProviders.GOOGLE;
        case FacebookAuthProvider.PROVIDER_ID:
            return IdentityProviders.FACEBOOK;
        case TwitterAuthProvider.PROVIDER_ID:
            return IdentityProviders.TWITTER;
        case GithubAuthProvider.PROVIDER_ID:
            return GITHUB_IDENTITY;
        case PhoneAuthProvider.PROVIDER_ID:
            return PHONE_IDENTITY;
        // The account type for email/password creds is null
        case EmailAuthProvider.PROVIDER_ID:
        default:
            return null;
    }
}
 
Example #5
Source File: ProviderUtils.java    From FirebaseUI-Android with Apache License 2.0 6 votes vote down vote up
@AuthUI.SupportedProvider
public static String accountTypeToProviderId(@NonNull String accountType) {
    switch (accountType) {
        case IdentityProviders.GOOGLE:
            return GoogleAuthProvider.PROVIDER_ID;
        case IdentityProviders.FACEBOOK:
            return FacebookAuthProvider.PROVIDER_ID;
        case IdentityProviders.TWITTER:
            return TwitterAuthProvider.PROVIDER_ID;
        case GITHUB_IDENTITY:
            return GithubAuthProvider.PROVIDER_ID;
        case PHONE_IDENTITY:
            return PhoneAuthProvider.PROVIDER_ID;
        default:
            return null;
    }
}
 
Example #6
Source File: ProviderUtils.java    From FirebaseUI-Android with Apache License 2.0 6 votes vote down vote up
public static String providerIdToProviderName(@NonNull String providerId) {
    switch (providerId) {
        case GoogleAuthProvider.PROVIDER_ID:
            return AuthUI.getApplicationContext().getString(R.string.fui_idp_name_google);
        case FacebookAuthProvider.PROVIDER_ID:
            return AuthUI.getApplicationContext().getString(R.string.fui_idp_name_facebook);
        case TwitterAuthProvider.PROVIDER_ID:
            return AuthUI.getApplicationContext().getString(R.string.fui_idp_name_twitter);
        case GithubAuthProvider.PROVIDER_ID:
            return AuthUI.getApplicationContext().getString(R.string.fui_idp_name_github);
        case PhoneAuthProvider.PROVIDER_ID:
            return AuthUI.getApplicationContext().getString(R.string.fui_idp_name_phone);
        case EmailAuthProvider.PROVIDER_ID:
        case EMAIL_LINK_PROVIDER:
            return AuthUI.getApplicationContext().getString(R.string.fui_idp_name_email);
        default:
            return null;
    }
}
 
Example #7
Source File: AuthMethodPickerActivityTest.java    From FirebaseUI-Android with Apache License 2.0 6 votes vote down vote up
@Test
public void testAllProvidersArePopulated() {
    // Exclude Facebook until the `NoClassDefFoundError: com/facebook/common/R$style` exception
    // is fixed.
    List<String> providers = Arrays.asList(
            GoogleAuthProvider.PROVIDER_ID,
            TwitterAuthProvider.PROVIDER_ID,
            EmailAuthProvider.PROVIDER_ID,
            PhoneAuthProvider.PROVIDER_ID,
            AuthUI.ANONYMOUS_PROVIDER);

    AuthMethodPickerActivity authMethodPickerActivity = createActivity(providers);

    assertEquals(providers.size(),
            ((LinearLayout) authMethodPickerActivity.findViewById(R.id.btn_holder))
                    .getChildCount());
}
 
Example #8
Source File: LoginActivity.java    From Simple-Blog-App with MIT License 5 votes vote down vote up
private void handleTwitterSession(TwitterSession session) {
    Log.d(TAG, "handleTwitterSession:" + session);
    mProgressbar.setMessage("Checking LOGIN.....");
    mProgressbar.show();
    AuthCredential credential = TwitterAuthProvider.getCredential(
            session.getAuthToken().token,
            session.getAuthToken().secret);

    mAuth.signInWithCredential(credential)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if (task.isSuccessful()) {
                        // Sign in success, update UI with the signed-in user's information
                        Log.d(TAG, "signInWithCredential:success");
                        Toast.makeText(LoginActivity.this, "Welcome", Toast.LENGTH_LONG).show();
                        checkUserExist();
                        mProgressbar.dismiss();
                        //***** updateUI(user);
                    } else {
                        // If sign in fails, display a message to the user.
                        Log.w(TAG, "signInWithCredential:failure", task.getException());

                        Toast.makeText(LoginActivity.this, "Failed276" + task.getException().getMessage(),
                                Toast.LENGTH_SHORT).show();
                        mProgressbar.dismiss();
                        //**** updateUI(null);
                    }
                }
            });
}
 
Example #9
Source File: TwitterLoginActivity.java    From endpoints-samples with Apache License 2.0 5 votes vote down vote up
private void handleTwitterSession(TwitterSession session) {
    Log.d(TAG, "handleTwitterSession:" + session);
    // [START_EXCLUDE silent]
    showProgressDialog();
    // [END_EXCLUDE]

    AuthCredential credential = TwitterAuthProvider.getCredential(
            session.getAuthToken().token,
            session.getAuthToken().secret);

    mAuth.signInWithCredential(credential)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful());

                    // If sign in fails, display a message to the user. If sign in succeeds
                    // the auth state listener will be notified and logic to handle the
                    // signed in user can be handled in the listener.
                    if (!task.isSuccessful()) {
                        Log.w(TAG, "signInWithCredential", task.getException());
                        Toast.makeText(TwitterLoginActivity.this, "Authentication failed.",
                                Toast.LENGTH_SHORT).show();
                    }

                    // [START_EXCLUDE]
                    hideProgressDialog();
                    // [END_EXCLUDE]
                }
            });
}
 
Example #10
Source File: FirestackAuth.java    From react-native-firestack with MIT License 5 votes vote down vote up
@ReactMethod
public void reauthenticateWithCredentialForProvider(final String provider, final String authToken, final String authSecret, final Callback callback) {
    AuthCredential credential;

    if (provider.equals("facebook")) {
        credential = FacebookAuthProvider.getCredential(authToken);
    } else if (provider.equals("google")) {
        credential = GoogleAuthProvider.getCredential(authToken, null);
    } else if (provider.equals("twitter")) {
        credential = TwitterAuthProvider.getCredential(authToken, authSecret);
    } else {
        // TODO:
        FirestackUtils.todoNote(TAG, "reauthenticateWithCredentialForProvider", callback);
        // AuthCredential credential;
        // Log.d(TAG, "reauthenticateWithCredentialForProvider called with: " + provider);
        return;
    }

    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
    if (user != null) {
        user.reauthenticate(credential)
            .addOnCompleteListener(new OnCompleteListener<Void>() {
                @Override
                public void onComplete(@NonNull Task<Void> task) {
                    if (task.isSuccessful()) {
                        Log.d(TAG, "User re-authenticated with " + provider);
                        FirebaseUser u = FirebaseAuth.getInstance().getCurrentUser();
                        userCallback(u, callback);
                    } else {
                        // userErrorCallback(task, callback);
                    }
                }
            });
    } else {
        WritableMap err = Arguments.createMap();
        err.putInt("errorCode", NO_CURRENT_USER);
        err.putString("errorMessage", "No current user");
        callback.invoke(err);
    }
}
 
Example #11
Source File: SignedInActivity.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
private void populateProfile(@Nullable IdpResponse response) {
    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
    if (user.getPhotoUrl() != null) {
        GlideApp.with(this)
                .load(user.getPhotoUrl())
                .fitCenter()
                .into(mUserProfilePicture);
    }

    mUserEmail.setText(
            TextUtils.isEmpty(user.getEmail()) ? "No email" : user.getEmail());
    mUserPhoneNumber.setText(
            TextUtils.isEmpty(user.getPhoneNumber()) ? "No phone number" : user.getPhoneNumber());
    mUserDisplayName.setText(
            TextUtils.isEmpty(user.getDisplayName()) ? "No display name" : user.getDisplayName());

    if (response == null) {
        mIsNewUser.setVisibility(View.GONE);
    } else {
        mIsNewUser.setVisibility(View.VISIBLE);
        mIsNewUser.setText(response.isNewUser() ? "New user" : "Existing user");
    }

    List<String> providers = new ArrayList<>();
    if (user.getProviderData().isEmpty()) {
        providers.add(getString(R.string.providers_anonymous));
    } else {
        for (UserInfo info : user.getProviderData()) {
            switch (info.getProviderId()) {
                case GoogleAuthProvider.PROVIDER_ID:
                    providers.add(getString(R.string.providers_google));
                    break;
                case FacebookAuthProvider.PROVIDER_ID:
                    providers.add(getString(R.string.providers_facebook));
                    break;
                case TwitterAuthProvider.PROVIDER_ID:
                    providers.add(getString(R.string.providers_twitter));
                    break;
                case EmailAuthProvider.PROVIDER_ID:
                    providers.add(getString(R.string.providers_email));
                    break;
                case PhoneAuthProvider.PROVIDER_ID:
                    providers.add(getString(R.string.providers_phone));
                    break;
                case EMAIL_LINK_PROVIDER:
                    providers.add(getString(R.string.providers_email_link));
                    break;
                case FirebaseAuthProvider.PROVIDER_ID:
                    // Ignore this provider, it's not very meaningful
                    break;
                default:
                    providers.add(info.getProviderId());
            }
        }
    }

    mEnabledProviders.setText(getString(R.string.used_providers, providers));
}
 
Example #12
Source File: AuthUI.java    From FirebaseUI-Android with Apache License 2.0 4 votes vote down vote up
public TwitterBuilder() {
    super(TwitterAuthProvider.PROVIDER_ID, PROVIDER_NAME,
            R.layout.fui_idp_button_twitter);
}
 
Example #13
Source File: AuthMethodPickerLayout.java    From FirebaseUI-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Set the ID of the Twitter sign in button in the custom layout.
 */
public AuthMethodPickerLayout.Builder setTwitterButtonId(@IdRes int twitterBtn) {
    providersMapping.put(TwitterAuthProvider.PROVIDER_ID, twitterBtn);
    return this;
}
 
Example #14
Source File: TestHelper.java    From FirebaseUI-Android with Apache License 2.0 4 votes vote down vote up
public static FlowParameters getFlowParameters(Collection<String> providerIds,
                                               boolean enableAnonymousUpgrade,
                                               AuthMethodPickerLayout customLayout) {
    List<IdpConfig> idpConfigs = new ArrayList<>();
    for (String providerId : providerIds) {
        switch (providerId) {
            case GoogleAuthProvider.PROVIDER_ID:
                idpConfigs.add(new IdpConfig.GoogleBuilder().build());
                break;
            case FacebookAuthProvider.PROVIDER_ID:
                idpConfigs.add(new IdpConfig.FacebookBuilder().build());
                break;
            case TwitterAuthProvider.PROVIDER_ID:
                idpConfigs.add(new IdpConfig.TwitterBuilder().build());
                break;
            case GithubAuthProvider.PROVIDER_ID:
                idpConfigs.add(new IdpConfig.GitHubBuilder().build());
                break;
            case EMAIL_LINK_PROVIDER:
                idpConfigs.add(new IdpConfig.EmailBuilder().enableEmailLinkSignIn()
                        .setActionCodeSettings(ActionCodeSettings.newBuilder().setUrl("URL")
                                .setHandleCodeInApp(true).build()).build());
                break;
            case EmailAuthProvider.PROVIDER_ID:
                idpConfigs.add(new IdpConfig.EmailBuilder().build());
                break;
            case PhoneAuthProvider.PROVIDER_ID:
                idpConfigs.add(new IdpConfig.PhoneBuilder().build());
                break;
            case AuthUI.ANONYMOUS_PROVIDER:
                idpConfigs.add(new IdpConfig.AnonymousBuilder().build());
                break;
            case MICROSOFT_PROVIDER:
                idpConfigs.add(new IdpConfig.MicrosoftBuilder().build());
                break;
            default:
                throw new IllegalArgumentException("Unknown provider: " + providerId);
        }
    }
    return new FlowParameters(
            DEFAULT_APP_NAME,
            idpConfigs,
            AuthUI.getDefaultTheme(),
            AuthUI.NO_LOGO,
            null,
            null,
            true,
            true,
            enableAnonymousUpgrade,
            false,
            null,
            customLayout);
}