com.google.firebase.auth.GoogleAuthProvider Java Examples

The following examples show how to use com.google.firebase.auth.GoogleAuthProvider. 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: SaveReports.java    From Crimson with Apache License 2.0 6 votes vote down vote up
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {

        Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId());

        showProgressDialog();

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

                        if (!task.isSuccessful()) {
                            Log.w(TAG, "signInWithCredential", task.getException());
                            Toast.makeText(SaveReports.this, "Authentication failed.",
                                    Toast.LENGTH_SHORT).show();
                        }
                        hideProgressDialog();
                    }
                });
    }
 
Example #2
Source File: ProfileActivity.java    From friendlypix-android with Apache License 2.0 6 votes vote down vote up
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
    Log.d(TAG, "firebaseAuthWithGooogle:" + acct.getId());
    AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
    showProgressDialog(getString(R.string.profile_progress_message));
    mAuth.signInWithCredential(credential)
            .addOnSuccessListener(this, new OnSuccessListener<AuthResult>() {
                @Override
                public void onSuccess(AuthResult result) {
                    handleFirebaseAuthResult(result);
                }
            })
            .addOnFailureListener(this, new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    FirebaseCrash.logcat(Log.ERROR, TAG, "auth:onFailure:" + e.getMessage());
                    handleFirebaseAuthResult(null);
                }
            });
}
 
Example #3
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 #4
Source File: SignInActivity.java    From codelab-friendlychat-android with Apache License 2.0 6 votes vote down vote up
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
    Log.d(TAG, "firebaseAuthWithGooogle:" + acct.getId());
    AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
    mFirebaseAuth.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(SignInActivity.this, "Authentication failed.",
                                Toast.LENGTH_SHORT).show();
                    } else {
                        startActivity(new Intent(SignInActivity.this, MainActivity.class));
                        finish();
                    }
                }
            });
}
 
Example #5
Source File: LoginActivity.java    From triviums with MIT License 6 votes vote down vote up
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
    binding.signInButton.setVisibility(View.GONE);
    binding.progressBar.setVisibility(View.VISIBLE);

    AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
    mAuth.signInWithCredential(credential)
            .addOnCompleteListener(this, task -> {
                if (task.isSuccessful()) {
                    viewModel.setLoggedIn(true);
                    // Sign in success, update UI with the signed-in user's information
                    binding.progressBar.setVisibility(View.GONE);
                } else {
                    // If sign in fails, display a message to the user.
                    Toast.makeText(LoginActivity.this, "Authentication failed.",
                            Toast.LENGTH_SHORT).show();
                }

            });
}
 
Example #6
Source File: SignInActivity.java    From Duolingo-Clone with MIT License 6 votes vote down vote up
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {

        AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
        mAuth.signInWithCredential(credential)
                .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        if (task.isSuccessful()) {

                            //take me to main page
                            Toast.makeText(context, "itworked", Toast.LENGTH_SHORT).show();

                            ActivityNavigation.getInstance(SignInActivity.this).takeToRandomTask();

                        } else {

                            Toast.makeText(context, getString(R.string.auth_failed), Toast.LENGTH_SHORT).show();
                        }
                    }
                });
    }
 
Example #7
Source File: SignInActivity.java    From budgetto with MIT License 6 votes vote down vote up
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
    AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
    mAuth.signInWithCredential(credential)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if (task.isSuccessful()) {
                        FirebaseUser user = mAuth.getCurrentUser();
                        updateUI(user);
                    } else {
                        loginError("Firebase auth failed.");
                        hideProgressView();
                    }
                }
            });
}
 
Example #8
Source File: LoginActivity.java    From NaviBee with GNU General Public License v3.0 6 votes vote down vote up
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
//        Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId());

        AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
        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");
                            checkSignIn();
                        } else {
                            // If sign in fails, display a message to the user.
                            Toast.makeText(LoginActivity.this, "Sign in fails", Toast.LENGTH_LONG).show();
                        }

                    }
                });
    }
 
Example #9
Source File: EmailActivityTest.java    From FirebaseUI-Android with Apache License 2.0 6 votes vote down vote up
@Test
public void testOnCreate_emailLinkLinkingFlow_expectSendEmailLinkFlowStarted() {
    // This is normally done by EmailLinkSendEmailHandler, saving the IdpResponse is done
    // in EmailActivity but it will not be saved if we haven't previously set the email
    EmailLinkPersistenceManager.getInstance().saveEmail(ApplicationProvider.getApplicationContext(),
            EMAIL, TestConstants.SESSION_ID, TestConstants.UID);

    EmailActivity emailActivity = createActivity(AuthUI.EMAIL_LINK_PROVIDER, true);

    EmailLinkFragment fragment = (EmailLinkFragment) emailActivity
            .getSupportFragmentManager().findFragmentByTag(EmailLinkFragment.TAG);
    assertThat(fragment).isNotNull();

    EmailLinkPersistenceManager persistenceManager = EmailLinkPersistenceManager.getInstance();
    IdpResponse response = persistenceManager.retrieveSessionRecord(
            ApplicationProvider.getApplicationContext()).getIdpResponseForLinking();

    assertThat(response.getProviderType()).isEqualTo(GoogleAuthProvider.PROVIDER_ID);
    assertThat(response.getEmail()).isEqualTo(EMAIL);
    assertThat(response.getIdpToken()).isEqualTo(ID_TOKEN);
    assertThat(response.getIdpSecret()).isEqualTo(SECRET);
}
 
Example #10
Source File: SigninActivity.java    From wmn-safety with MIT License 6 votes vote down vote up
private void firebaseAuthWithGoogle(final GoogleSignInAccount account) {
    AuthCredential mCredential = GoogleAuthProvider.getCredential(account.getIdToken(), null);
    mFirebaseAuth.signInWithCredential(mCredential)
            .addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if (task.isSuccessful()) {
                        String email = account.getEmail();
                        String name = account.getDisplayName();
                        String userID = mFirebaseAuth.getCurrentUser().getUid();
                        boolean newUser = task.getResult().getAdditionalUserInfo().isNewUser();
                        addNewUser(email, name, "", userID, newUser);
                    } else {
                        Log.w(TAG, task.getException().toString());
                        Toast.makeText(SigninActivity.this, task.getException().toString(), Toast.LENGTH_SHORT)
                                .show();
                    }
                }
            });
}
 
Example #11
Source File: LoginPresenter.java    From social-app-android with Apache License 2.0 6 votes vote down vote up
public void handleGoogleSignInResult(GoogleSignInResult result) {
    ifViewAttached(view -> {
        if (result.isSuccess()) {
            view.showProgress();

            GoogleSignInAccount account = result.getSignInAccount();

            view.setProfilePhotoUrl(buildGooglePhotoUrl(account.getPhotoUrl()));

            AuthCredential credential = GoogleAuthProvider.getCredential(account.getIdToken(), null);
            view.firebaseAuthWithCredentials(credential);

            LogUtil.logDebug(TAG, "firebaseAuthWithGoogle:" + account.getId());

        } else {
            LogUtil.logDebug(TAG, "SIGN_IN_GOOGLE failed :" + result);
            view.hideProgress();
        }
    });
}
 
Example #12
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 #13
Source File: SocialProviderResponseHandlerTest.java    From FirebaseUI-Android with Apache License 2.0 6 votes vote down vote up
@Test
public void testSignInIdp_anonymousUserUpgradeEnabledAndNewUser_expectSuccess() {
    mHandler.getOperation().observeForever(mResultObserver);
    setupAnonymousUpgrade();

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

    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()));
    inOrder.verify(mResultObserver)
            .onChanged(argThat(ResourceMatchers.<IdpResponse>isSuccess()));
}
 
Example #14
Source File: SignInBaseActivity.java    From Expert-Android-Programming with MIT License 6 votes vote down vote up
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
    MyLg.d(TAG, "firebaseAuthWithGoogle:" + acct.getId()+" "+acct.getPhotoUrl());
    showProgressDialog();

    AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
    mAuth.signInWithCredential(credential)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    MyLg.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()) {
                        MyLg.w(TAG, "signInWithCredential");
                        Toas.show(context, "Authentication failed.");
                    }
                    hideProgressDialog();
                }
            });
}
 
Example #15
Source File: SocialProviderResponseHandlerTest.java    From FirebaseUI-Android with Apache License 2.0 6 votes vote down vote up
@Test
public void testSignInIdp_disabled() {
    mHandler.getOperation().observeForever(mResultObserver);

    when(mMockAuth.signInWithCredential(any(AuthCredential.class)))
            .thenReturn(AutoCompleteTask.<AuthResult>forFailure(
                    new FirebaseAuthException("ERROR_USER_DISABLED", "disabled")));

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

    verify(mResultObserver).onChanged(
            argThat(ResourceMatchers.<IdpResponse>isFailureWithCode(ErrorCodes.ERROR_USER_DISABLED)));
}
 
Example #16
Source File: GoogleProviderHandler.java    From capacitor-firebase-auth with MIT License 6 votes vote down vote up
@Override
public void handleOnActivityResult(int requestCode, int resultCode, Intent data) {
    Log.d(GOOGLE_TAG, "Google SignIn activity result.");

    try {
        Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
        // Google Sign In was successful, authenticate with Firebase
        GoogleSignInAccount account = task.getResult(ApiException.class);

        if (account != null) {
            Log.d(GOOGLE_TAG, "Google Sign In succeed.");
            AuthCredential credential = GoogleAuthProvider.getCredential(account.getIdToken(), null);
            this.plugin.handleAuthCredentials(credential);
            return;
        }
    } catch (ApiException exception) {
        // Google Sign In failed, update UI appropriately
        Log.w(GOOGLE_TAG, GoogleSignInStatusCodes.getStatusCodeString(exception.getStatusCode()), exception);
        plugin.handleFailure("Google Sign In failure.", exception);
        return;
    }

    plugin.handleFailure("Google Sign In failure.", null);
}
 
Example #17
Source File: BaseAuthActivity.java    From MangoBloggerAndroidApp with Mozilla Public License 2.0 6 votes vote down vote up
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
        Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId());

        AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
        mAuth.signInWithCredential(credential)
                .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        if (task.isSuccessful()) {
                            hideProgressDialog();
                            // Sign in success, update UI with the signed-in user's information
                            Log.d(TAG, "signInWithCredential:success");
//                            FirebaseUser user = mAuth.getCurrentUser();
                            startApp();
                        } else {
                            hideProgressDialog();
                            // If sign in fails, display a message to the user.
                            Log.w(TAG, "signInWithCredential:failure", task.getException());
                            Toast.makeText(BaseAuthActivity.this, "Authentication failed.",
                                    Toast.LENGTH_SHORT).show();
                        }

                        // ...
                    }
                });
    }
 
Example #18
Source File: LoginPresenter.java    From social-app-android with Apache License 2.0 6 votes vote down vote up
public void handleGoogleSignInResult(GoogleSignInResult result) {
    ifViewAttached(view -> {
        if (result.isSuccess()) {
            view.showProgress();

            GoogleSignInAccount account = result.getSignInAccount();

            view.setProfilePhotoUrl(buildGooglePhotoUrl(account.getPhotoUrl()));

            AuthCredential credential = GoogleAuthProvider.getCredential(account.getIdToken(), null);
            view.firebaseAuthWithCredentials(credential);

            LogUtil.logDebug(TAG, "firebaseAuthWithGoogle:" + account.getId());

        } else {
            LogUtil.logDebug(TAG, "SIGN_IN_GOOGLE failed :" + result);
            view.hideProgress();
        }
    });
}
 
Example #19
Source File: SocialProviderResponseHandlerTest.java    From FirebaseUI-Android with Apache License 2.0 6 votes vote down vote up
@Test
public void testSignInIdp_success() {
    mHandler.getOperation().observeForever(mResultObserver);

    when(mMockAuth.signInWithCredential(any(AuthCredential.class)))
            .thenReturn(AutoCompleteTask.forSuccess(FakeAuthResult.INSTANCE));

    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));

    InOrder inOrder = inOrder(mResultObserver);
    inOrder.verify(mResultObserver)
            .onChanged(argThat(ResourceMatchers.<IdpResponse>isLoading()));
    inOrder.verify(mResultObserver)
            .onChanged(argThat(ResourceMatchers.<IdpResponse>isSuccess()));
}
 
Example #20
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 #21
Source File: LinkingSocialProviderResponseHandlerTest.java    From FirebaseUI-Android with Apache License 2.0 6 votes vote down vote up
@Test
public void testSignIn_withSameIdp_expectSuccess() {
    mHandler.getOperation().observeForever(mResponseObserver);

    // Fake social response from Google
    IdpResponse response = new IdpResponse.Builder(new User.Builder(
            GoogleAuthProvider.PROVIDER_ID, TestConstants.EMAIL).build())
            .setToken(TestConstants.TOKEN)
            .build();

    when(mMockAuth.signInWithCredential(any(AuthCredential.class)))
            .thenReturn(AutoCompleteTask.forSuccess(FakeAuthResult.INSTANCE));

    mHandler.startSignIn(response);

    verify(mMockAuth).signInWithCredential(any(GoogleAuthCredential.class));

    InOrder inOrder = inOrder(mResponseObserver);
    inOrder.verify(mResponseObserver)
            .onChanged(argThat(ResourceMatchers.<IdpResponse>isLoading()));
    inOrder.verify(mResponseObserver)
            .onChanged(argThat(ResourceMatchers.<IdpResponse>isSuccess()));
}
 
Example #22
Source File: SignInActivity.java    From jterm-cswithandroid with Apache License 2.0 6 votes vote down vote up
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
    Log.d(TAG, "firebaseAuthWithGooogle:" + acct.getId());
    AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
    mFirebaseAuth.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(SignInActivity.this, "Authentication failed.",
                                Toast.LENGTH_SHORT).show();
                    } else {
                        startActivity(new Intent(SignInActivity.this, MainActivity.class));
                        finish();
                    }
                }
            });
}
 
Example #23
Source File: FireSignin.java    From Learning-Resources with MIT License 6 votes vote down vote up
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {

        mPrgrsbrMain.setVisibility(View.VISIBLE);

        LogManager.printLog(LOGTYPE_INFO, "signInWithGoogleId: " + acct.getId());

        AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
        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 #24
Source File: LoginActivity.java    From FaceT with Mozilla Public License 2.0 6 votes vote down vote up
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
    Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId());

    final AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
    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(LoginActivity.this, "Authentication failed.",
                                Toast.LENGTH_SHORT).show();
                    } else {
                        mProgress.dismiss();
                        Snackbar snackbar = Snackbar.make(activity_login_layout, "Login successfully", Snackbar.LENGTH_SHORT);
                        snackbar.show();
                        checkUserExist();
                    }
                }
            });
}
 
Example #25
Source File: Loginactivity.java    From LuxVilla with Apache License 2.0 6 votes vote down vote up
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
    AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
    firebaseAuth.signInWithCredential(credential)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    // 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()) {
                        Snackbar.make(linearLayout,"Ocorreu um erro ao conectar", Snackbar.LENGTH_LONG).show();
                    } else {
                        startActivity(new Intent(Loginactivity.this, MainActivity.class));
                        finish();
                    }
                }
            });
}
 
Example #26
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 #27
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 #28
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 #29
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 #30
Source File: FirestackAuth.java    From react-native-firestack with MIT License 6 votes vote down vote up
@ReactMethod
public void googleLogin(String IdToken, final Callback callback) {
    mAuth = FirebaseAuth.getInstance();

    AuthCredential credential = GoogleAuthProvider.getCredential(IdToken, null);
    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);
          }
        });
}