com.google.firebase.auth.FacebookAuthProvider Java Examples

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

    AuthCredential credential = FacebookAuthProvider.getCredential(Token);
    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 #3
Source File: AuthUI.java    From FirebaseUI-Android with Apache License 2.0 6 votes vote down vote up
public FacebookBuilder() {
    super(FacebookAuthProvider.PROVIDER_ID);
    if (!ProviderAvailability.IS_FACEBOOK_AVAILABLE) {
        throw new RuntimeException(
                "Facebook provider cannot be configured " +
                        "without dependency. Did you forget to add " +
                        "'com.facebook.android:facebook-login:VERSION' dependency?");
    }
    Preconditions.checkConfigured(getApplicationContext(),
            "Facebook provider unconfigured. Make sure to add a" +
                    " `facebook_application_id` string. See the docs for more info:" +
                    " https://github" +
                    ".com/firebase/FirebaseUI-Android/blob/master/auth/README" +
                    ".md#facebook",
            R.string.facebook_application_id);
    if (getApplicationContext().getString(R.string.facebook_login_protocol_scheme)
            .equals("fbYOUR_APP_ID")) {
        Log.w(TAG, "Facebook provider unconfigured for Chrome Custom Tabs.");
    }
}
 
Example #4
Source File: FireSignin.java    From Learning-Resources with MIT License 6 votes vote down vote up
private void firebaseAuthWithFacebook(AccessToken accessToken) {

        mPrgrsbrMain.setVisibility(View.VISIBLE);

        LogManager.printLog(LOGTYPE_INFO, "signInWithFacebookToken: " + accessToken);

        AuthCredential credential = FacebookAuthProvider.getCredential(accessToken.getToken());
        mFireAuth.signInWithCredential(credential)
                .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {

                        LogManager.printLog(LOGTYPE_DEBUG, "signInWithCredential:onComplete:" + task.isSuccessful());

                        if (!task.isSuccessful()) {

                            mPrgrsbrMain.setVisibility(View.GONE);
                            Log.w(LOG_TAG, "signInWithCredential", task.getException());
                            Snackbar.make(mCrdntrlyot, "Authentication failed.\n" + task.getException().getMessage(),
                                    Snackbar.LENGTH_LONG).show();
                        } else
                            successLoginGetData(task);
                    }
                });
    }
 
Example #5
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 #6
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 #7
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 #8
Source File: LoginActivity.java    From android-paypal-example with Apache License 2.0 6 votes vote down vote up
private void handleFacebookAccessToken(AccessToken token) {

        Log.d(TAG, "handleFacebookAccessToken:" + token);

        AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken());
        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");
                            updateUI(mAuth.getCurrentUser());
                        } else {
                            // If sign in fails, display a message to the user.
                            Log.w(TAG, "signInWithCredential:failure", task.getException());
                            Toast.makeText(LoginActivity.this, "Authentication failed.",
                                    Toast.LENGTH_SHORT).show();
                        }

                    }
                });
    }
 
Example #9
Source File: EmailLinkSignInHandlerTest.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
private IdpResponse buildFacebookIdpResponse() {
    User user = new User.Builder(FacebookAuthProvider.PROVIDER_ID, TestConstants.EMAIL)
            .build();

    return new IdpResponse.Builder(user)
            .setToken(TestConstants.TOKEN)
            .setSecret(TestConstants.SECRET)
            .build();
}
 
Example #10
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 #11
Source File: ProviderUtils.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
@Nullable
public static AuthCredential getAuthCredential(IdpResponse response) {
    if (response.hasCredentialForLinking()) {
        return response.getCredentialForLinking();
    }
    switch (response.getProviderType()) {
        case GoogleAuthProvider.PROVIDER_ID:
            return GoogleAuthProvider.getCredential(response.getIdpToken(), null);
        case FacebookAuthProvider.PROVIDER_ID:
            return FacebookAuthProvider.getCredential(response.getIdpToken());
        default:
            return null;
    }
}
 
Example #12
Source File: AuthMethodPickerActivity.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
private void populateIdpList(List<IdpConfig> providerConfigs) {

        ViewModelProvider supplier = ViewModelProviders.of(this);
        mProviders = new ArrayList<>();
        for (IdpConfig idpConfig : providerConfigs) {
            @LayoutRes int buttonLayout;

            final String providerId = idpConfig.getProviderId();
            switch (providerId) {
                case GoogleAuthProvider.PROVIDER_ID:
                    buttonLayout = R.layout.fui_idp_button_google;
                    break;
                case FacebookAuthProvider.PROVIDER_ID:
                    buttonLayout = R.layout.fui_idp_button_facebook;
                    break;
                case EMAIL_LINK_PROVIDER:
                case EmailAuthProvider.PROVIDER_ID:
                    buttonLayout = R.layout.fui_provider_button_email;
                    break;
                case PhoneAuthProvider.PROVIDER_ID:
                    buttonLayout = R.layout.fui_provider_button_phone;
                    break;
                case AuthUI.ANONYMOUS_PROVIDER:
                    buttonLayout = R.layout.fui_provider_button_anonymous;
                    break;
                default:
                    if (!TextUtils.isEmpty(
                            idpConfig.getParams().getString(GENERIC_OAUTH_PROVIDER_ID))) {
                        buttonLayout = idpConfig.getParams().getInt(GENERIC_OAUTH_BUTTON_ID);
                        break;
                    }
                    throw new IllegalStateException("Unknown provider: " + providerId);
            }

            View loginButton = getLayoutInflater().inflate(buttonLayout, mProviderHolder, false);
            handleSignInOperation(idpConfig, loginButton);
            mProviderHolder.addView(loginButton);
        }
    }
 
Example #13
Source File: EmailLinkSendEmailHandlerTest.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
private IdpResponse buildFacebookIdpResponseForLinking() {
    User user = new User.Builder(FacebookAuthProvider.PROVIDER_ID, TestConstants.EMAIL)
            .build();
    return new IdpResponse.Builder(user)
            .setToken(TestConstants.TOKEN)
            .setSecret(TestConstants.SECRET)
            .build();
}
 
Example #14
Source File: LinkingSocialProviderResponseHandlerTest.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
@Test
public void testSignIn_genericIdpLinkingFlow_expectImmediateLink() {
    mHandler.getOperation().observeForever(mResponseObserver);

    // Set Facebook credential
    AuthCredential facebookAuthCredential =
            FacebookAuthProvider.getCredential(TestConstants.TOKEN);
    mHandler.setRequestedSignInCredentialForEmail(facebookAuthCredential, TestConstants.EMAIL);

    // Fake social response from Microsoft
    IdpResponse idpResponse = new IdpResponse.Builder(
            new User.Builder(MICROSOFT_PROVIDER, TestConstants.EMAIL)
                    .setName(DISPLAY_NAME)
                    .build())
            .build();

    when(mMockAuth.getCurrentUser()).thenReturn(mMockUser);
    when(mMockUser.linkWithCredential(any(AuthCredential.class)))
            .thenReturn(AutoCompleteTask.forSuccess(FakeAuthResult.INSTANCE));

    mHandler.startSignIn(idpResponse);

    InOrder inOrder = inOrder(mResponseObserver);
    inOrder.verify(mResponseObserver)
            .onChanged(argThat(ResourceMatchers.<IdpResponse>isLoading()));

    ArgumentCaptor<Resource<IdpResponse>> resolveCaptor =
            ArgumentCaptor.forClass(Resource.class);
    inOrder.verify(mResponseObserver).onChanged(resolveCaptor.capture());

    assertThat(resolveCaptor.getValue().getValue()).isNotNull();
}
 
Example #15
Source File: SocialProviderResponseHandlerTest.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
@Test
public void testSignInIdp_resolution() {
    mHandler.getOperation().observeForever(mResultObserver);

    when(mMockAuth.signInWithCredential(any(AuthCredential.class)))
            .thenReturn(AutoCompleteTask.<AuthResult>forFailure(
                    new FirebaseAuthUserCollisionException("foo", "bar")));
    when(mMockAuth.fetchSignInMethodsForEmail(any(String.class)))
            .thenReturn(AutoCompleteTask.<SignInMethodQueryResult>forSuccess(
                    new FakeSignInMethodQueryResult(Collections.singletonList(
                            FacebookAuthProvider.FACEBOOK_SIGN_IN_METHOD))));

    IdpResponse response = new IdpResponse.Builder(new User.Builder(
            GoogleAuthProvider.PROVIDER_ID, TestConstants.EMAIL).build())
            .setToken(TestConstants.TOKEN)
            .build();

    mHandler.startSignIn(response);

    verify(mMockAuth).signInWithCredential(any(AuthCredential.class));
    verify(mMockAuth).fetchSignInMethodsForEmail(any(String.class));

    InOrder inOrder = inOrder(mResultObserver);
    inOrder.verify(mResultObserver)
            .onChanged(argThat(ResourceMatchers.<IdpResponse>isLoading()));

    ArgumentCaptor<Resource<IdpResponse>> resolveCaptor =
            ArgumentCaptor.forClass(Resource.class);
    inOrder.verify(mResultObserver).onChanged(resolveCaptor.capture());

    // Call activity result
    IntentRequiredException e =
            ((IntentRequiredException) resolveCaptor.getValue().getException());
    mHandler.onActivityResult(e.getRequestCode(), Activity.RESULT_OK, response.toIntent());

    // Make sure we get success
    inOrder.verify(mResultObserver)
            .onChanged(argThat(ResourceMatchers.<IdpResponse>isSuccess()));
}
 
Example #16
Source File: FacebookSignInHandler.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
private static IdpResponse createIdpResponse(
        LoginResult result, @Nullable String email, String name, Uri photoUri) {
    return new IdpResponse.Builder(
            new User.Builder(FacebookAuthProvider.PROVIDER_ID, email)
                    .setName(name)
                    .setPhotoUri(photoUri)
                    .build())
            .setToken(result.getAccessToken().getToken())
            .build();
}
 
Example #17
Source File: SocialProviderResponseHandlerTest.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
@Test
public void testSignInIdp_anonymousUserUpgradeEnabledAndExistingUserWithSameIdp_expectMergeFailure() {
    mHandler.getOperation().observeForever(mResultObserver);
    setupAnonymousUpgrade();

    when(mMockAuth.getCurrentUser().linkWithCredential(any(AuthCredential.class)))
            .thenReturn(AutoCompleteTask.<AuthResult>forFailure(
                    new FirebaseAuthUserCollisionException("foo", "bar")));

    // Case 1: Anon user signing in with a Google credential that belongs to an existing user.
    when(mMockAuth.fetchSignInMethodsForEmail(any(String.class)))
            .thenReturn(AutoCompleteTask.<SignInMethodQueryResult>forSuccess(
                    new FakeSignInMethodQueryResult(Arrays.asList(
                            GoogleAuthProvider.GOOGLE_SIGN_IN_METHOD,
                            FacebookAuthProvider.FACEBOOK_SIGN_IN_METHOD))));


    IdpResponse response = new IdpResponse.Builder(new User.Builder(
            GoogleAuthProvider.PROVIDER_ID, TestConstants.EMAIL).build())
            .setToken(TestConstants.TOKEN)
            .build();

    mHandler.startSignIn(response);

    verify(mMockAuth.getCurrentUser()).linkWithCredential(any(AuthCredential.class));

    InOrder inOrder = inOrder(mResultObserver);
    inOrder.verify(mResultObserver)
            .onChanged(argThat(ResourceMatchers.<IdpResponse>isLoading()));

    ArgumentCaptor<Resource<IdpResponse>> resolveCaptor =
            ArgumentCaptor.forClass(Resource.class);
    inOrder.verify(mResultObserver).onChanged(resolveCaptor.capture());

    FirebaseAuthAnonymousUpgradeException e =
            (FirebaseAuthAnonymousUpgradeException) resolveCaptor.getValue().getException();

    assertThat(e.getResponse().getCredentialForLinking()).isNotNull();
}
 
Example #18
Source File: LoginPresenter.java    From social-app-android with Apache License 2.0 5 votes vote down vote up
public void handleFacebookSignInResult(LoginResult loginResult) {
    ifViewAttached(view -> {
        LogUtil.logDebug(TAG, "handleFacebookSignInResult: " + loginResult);
        view.setProfilePhotoUrl(buildFacebookPhotoUrl(loginResult.getAccessToken().getUserId()));
        view.showProgress();
        AuthCredential credential = FacebookAuthProvider.getCredential(loginResult.getAccessToken().getToken());
        view.firebaseAuthWithCredentials(credential);
    });
}
 
Example #19
Source File: LoginPresenter.java    From social-app-android with Apache License 2.0 5 votes vote down vote up
public void handleFacebookSignInResult(LoginResult loginResult) {
    ifViewAttached(view -> {
        LogUtil.logDebug(TAG, "handleFacebookSignInResult: " + loginResult);
        view.setProfilePhotoUrl(buildFacebookPhotoUrl(loginResult.getAccessToken().getUserId()));
        view.showProgress();
        AuthCredential credential = FacebookAuthProvider.getCredential(loginResult.getAccessToken().getToken());
        view.firebaseAuthWithCredentials(credential);
    });
}
 
Example #20
Source File: LogoutHelper.java    From social-app-android with Apache License 2.0 5 votes vote down vote up
private static void logoutByProvider(String providerId, GoogleApiClient mGoogleApiClient, FragmentActivity fragmentActivity) {
    switch (providerId) {
        case GoogleAuthProvider.PROVIDER_ID:
            logoutGoogle(mGoogleApiClient, fragmentActivity);
            break;

        case FacebookAuthProvider.PROVIDER_ID:
            logoutFacebook(fragmentActivity.getApplicationContext());
            break;
    }
}
 
Example #21
Source File: MainActivity.java    From Beginner-Level-Android-Studio-Apps with GNU General Public License v3.0 5 votes vote down vote up
private void handleFacebookAccessToken(AccessToken token) {
    Log.d(TAG, "handleFacebookAccessToken:" + token);

    AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken());
    //sign with credential which create from firebase auth
    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");
                        FirebaseUser user = mAuth.getCurrentUser();
                        btnFacebook.setEnabled(true);
                        updateUI(user);
                    } else {
                        // If sign in fails, display a message to the user.
                        Log.w(TAG, "signInWithCredential:failure", task.getException());
                        Toast.makeText(MainActivity.this, "Authentication failed.",
                                Toast.LENGTH_SHORT).show();
                        btnFacebook.setEnabled(true);
                        updateUI(null);
                    }

                    // ...
                }
            });
}
 
Example #22
Source File: FacebookSign.java    From FeedFire with MIT License 5 votes vote down vote up
private void handleFacebookAccessToken(AccessToken token) {
    FirebaseAuth auth = FirebaseAuth.getInstance();
    AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken());
    auth.signInWithCredential(credential)
            .addOnCompleteListener(mActivity, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if (!task.isSuccessful()) {
                        mFaceCallback.cancelLoginFace();
                    }else{
                       mFaceCallback.getInfoFace();
                    }
                }
            });
}
 
Example #23
Source File: SignInBaseActivity.java    From Expert-Android-Programming with MIT License 5 votes vote down vote up
private void handleFacebookAccessToken(final AccessToken token) {
    MyLg.d("KOI", "handleFacebookAccessToken:" + token);

    AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken());
    mAuth.signInWithCredential(credential)
            .addOnCompleteListener((Activity) context, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    MyLg.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful());

                }
            });
}
 
Example #24
Source File: LogoutHelper.java    From social-app-android with Apache License 2.0 5 votes vote down vote up
private static void logoutByProvider(String providerId, GoogleApiClient mGoogleApiClient, FragmentActivity fragmentActivity) {
    switch (providerId) {
        case GoogleAuthProvider.PROVIDER_ID:
            logoutGoogle(mGoogleApiClient, fragmentActivity);
            break;

        case FacebookAuthProvider.PROVIDER_ID:
            logoutFacebook(fragmentActivity.getApplicationContext());
            break;
    }
}
 
Example #25
Source File: LoginActivity.java    From Simple-Blog-App with MIT License 5 votes vote down vote up
private void signInWithFacebook(AccessToken token) {
        Log.d(TAG, "signInWithFacebook:" + token.getToken());
        AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken());
        final String tokenString = token.getToken();
        mAuth.signInWithCredential(credential)
                .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful());
//
//                        startActivity(new Intent(SignUp09.this, Dashboard.class));
                        // 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(LoginActivity.this, "Sorry for inconvenience,Please try again..",
                                    Toast.LENGTH_SHORT).show();
                        } else {
                            //signInFacebook(tokenString);
                            Toast.makeText(LoginActivity.this, "Welcome..!", Toast.LENGTH_SHORT).show();
                            checkUserExist();
                        }
                    }


                });
    }
 
Example #26
Source File: FacebookLoginActivity.java    From quickstart-android with Apache License 2.0 5 votes vote down vote up
private void handleFacebookAccessToken(AccessToken token) {
    Log.d(TAG, "handleFacebookAccessToken:" + token);
    // [START_EXCLUDE silent]
    showProgressBar();
    // [END_EXCLUDE]

    AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken());
    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");
                        FirebaseUser user = mAuth.getCurrentUser();
                        updateUI(user);
                    } else {
                        // If sign in fails, display a message to the user.
                        Log.w(TAG, "signInWithCredential:failure", task.getException());
                        Toast.makeText(FacebookLoginActivity.this, "Authentication failed.",
                                Toast.LENGTH_SHORT).show();
                        updateUI(null);
                    }

                    // [START_EXCLUDE]
                    hideProgressBar();
                    // [END_EXCLUDE]
                }
            });
}
 
Example #27
Source File: FacebookLoginActivity.java    From endpoints-samples with Apache License 2.0 5 votes vote down vote up
private void handleFacebookAccessToken(AccessToken token) {
    Log.d(TAG, "handleFacebookAccessToken:" + token);
    // [START_EXCLUDE silent]
    showProgressDialog();
    // [END_EXCLUDE]

    AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken());
    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(FacebookLoginActivity.this, "Authentication failed.",
                                Toast.LENGTH_SHORT).show();
                    }

                    // [START_EXCLUDE]
                    hideProgressDialog();
                    // [END_EXCLUDE]
                }
            });
}
 
Example #28
Source File: RegisterActivity.java    From kute with Apache License 2.0 5 votes vote down vote up
private void handleFacebookAccessToken(AccessToken token) {
    Log.d(TAG, "handleFacebookAccessToken:" + token);
    // [START_EXCLUDE silent]
    Toast.makeText(getApplicationContext(),"Facebook  show dialog",Toast.LENGTH_LONG).show();
    //showProgressDialog();
    // [END_EXCLUDE]

    AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken());
    mAuth.signInWithCredential(credential)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    try{
                    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()) {
                        //make user partial login to logout
                        signOut();
                        Log.w(TAG, "signInWithCredential", task.getException());
                        Toast.makeText(RegisterActivity.this, "Authentication failed.",
                                Toast.LENGTH_SHORT).show();
                    }

                    // [START_EXCLUDE]
                    Toast.makeText(getApplicationContext(),"Facebook  hide dialog",Toast.LENGTH_LONG).show();
                    //hideProgressDialog();
                    // [END_EXCLUDE]
                    }
                    catch (Exception e){
                        e.printStackTrace();

                    }
                }
            });
}
 
Example #29
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 #30
Source File: FacebookProviderHandler.java    From capacitor-firebase-auth with MIT License 4 votes vote down vote up
private void handleFacebookAccessToken(AccessToken token) {
    AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken());
    this.plugin.handleAuthCredentials(credential);
}