Java Code Examples for com.google.firebase.auth.GoogleAuthProvider#getCredential()

The following examples show how to use com.google.firebase.auth.GoogleAuthProvider#getCredential() . 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: 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 2
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 3
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 4
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 5
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 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: 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 8
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 9
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);
          }
        });
}
 
Example 10
Source File: GoogleSignInActivity.java    From quickstart-android with Apache License 2.0 5 votes vote down vote up
private void firebaseAuthWithGoogle(String idToken) {
    // [START_EXCLUDE silent]
    showProgressBar();
    // [END_EXCLUDE]
    AuthCredential credential = GoogleAuthProvider.getCredential(idToken, 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");
                        FirebaseUser user = mAuth.getCurrentUser();
                        updateUI(user);
                    } else {
                        // If sign in fails, display a message to the user.
                        Log.w(TAG, "signInWithCredential:failure", task.getException());
                        Snackbar.make(mBinding.mainLayout, "Authentication Failed.", Snackbar.LENGTH_SHORT).show();
                        updateUI(null);
                    }

                    // [START_EXCLUDE]
                    hideProgressBar();
                    // [END_EXCLUDE]
                }
            });
}
 
Example 11
Source File: AuthManagerImpl.java    From buddysearch with Apache License 2.0 5 votes vote down vote up
@Override
public void signInGoogle(GoogleSignInAccount acct, Subscriber<String> subscriber, CreateUser createUser) {
    AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
    auth.signInWithCredential(credential)
            .addOnCompleteListener(task -> {
                if (!subscriber.isUnsubscribed()) {
                    if (task.isSuccessful()) {
                        saveUser(task.getResult().getUser(), subscriber, createUser);
                    } else {
                        subscriber.onError(new FirebaseException(task.getException().getMessage()));
                    }
                }
            });
}
 
Example 12
Source File: SplashActivity.java    From FChat with MIT License 5 votes vote down vote up
private void firebaseAuthWithGoogle(final GoogleSignInAccount acct) {
    AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
    mFirebaseAuth.signInWithCredential(credential).addOnCompleteListener(this, 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()) {
            customToast.showError(getString(R.string.error_authetication_failed));
        } else {
            ref = FirebaseDatabase.getInstance().getReference(USERS_CHILD);
            ref.addListenerForSingleValueEvent(new ValueEventListener() {
                @Override
                public void onDataChange(
                    @NotNull
                        DataSnapshot snapshot) {
                    final String usrNm = acct.getDisplayName();
                    final String usrId = acct.getId();
                    final String usrDp = acct.getPhotoUrl().toString();

                    set.addUpdateSettings(Constants.PREF_MY_ID, usrId);
                    set.addUpdateSettings(Constants.PREF_MY_NAME, usrNm);
                    set.addUpdateSettings(Constants.PREF_MY_DP, usrDp);

                    if (!snapshot.hasChild(usrId)) {
                        ref.child(usrId + "/" + NODE_NAME).setValue(usrNm);
                        ref.child(usrId + "/" + NODE_PHOTO).setValue(usrDp);
                        ref.child(usrId + "/" + NODE_USER_ID).setValue(usrId);
                    }
                }

                @Override
                public void onCancelled(DatabaseError databaseError) {
                }
            });

            startActivity(new Intent(SplashActivity.this, MainActivity.class));
            finish();
        }
    });
}
 
Example 13
Source File: GoogleSign.java    From FeedFire with MIT License 5 votes vote down vote up
private void firebaseAuthWithGoogle(final GoogleSignInAccount acct) {
    FirebaseAuth auth = FirebaseAuth.getInstance();
    AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
    auth.signInWithCredential(credential)
            .addOnCompleteListener(context, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if (!task.isSuccessful()) {
                        mGoogleCallback.loginFailed();
                    }else{
                        mGoogleCallback.getInfoLoginGoogle(acct);
                    }
                }
            });
}
 
Example 14
Source File: RegisterActivity.java    From kute with Apache License 2.0 5 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(RegisterActivity.this, "Authentication failed.",
                                Toast.LENGTH_SHORT).show();
                    } else {
                        Toast.makeText(RegisterActivity.this, "Authentication Done."+task.getResult().getUser().getDisplayName()+" - "+task.getResult().getUser().getDisplayName()+" - "+task.getResult().getUser().getEmail()+" - "+task.getResult().getUser().getPhotoUrl().getPath()+" - ",
                                Toast.LENGTH_SHORT).show();
                        getImage(task.getResult().getUser().getPhotoUrl().toString());

                        Intent intentdone=new Intent(RegisterActivity.this, SplashActivity.class);
                        startActivity(intentdone);

                    }
                }
            });
}
 
Example 15
Source File: MainActivity.java    From white-label-event-app with Apache License 2.0 5 votes vote down vote up
private void handleSignInResult(GoogleSignInResult result) {
    LOGGER.fine("handleSignInResult: " + result.isSuccess());
    LOGGER.fine("handleSignInResult: " + result.getStatus());
    if (result.isSuccess()) {
        final GoogleSignInAccount acct = result.getSignInAccount();
        final AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
        auth.signInWithCredential(credential)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    LOGGER.fine("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()) {
                        LOGGER.log(Level.SEVERE, "signInWithCredential", task.getException());
                        toastAuthFailed();
                    }
                }
            });

    }
    else {
        toastAuthFailed();
        navigationHeaderView.showViewId(R.id.button_sign_in);
    }
}
 
Example 16
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 17
Source File: LoginActivity.java    From TwrpBuilder with GNU General Public License v3.0 5 votes vote down vote up
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
    Log.d("TAG", "firebaseAuthWithGoogle:" + acct.getId());

    AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
    auth.signInWithCredential(credential)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if (task.isSuccessful()) {
                        startActivity(new Intent(LoginActivity.this, MainActivity.class));
                        finish();
                    }
                }
            });
}
 
Example 18
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 19
Source File: SettingsFragment.java    From YTPlayer with GNU General Public License v3.0 5 votes vote down vote up
private void firebaseAuthWithGoogle(final GoogleSignInAccount acct) {
    Log.d("firebaseAuth", "firebaseAuthWithGoogle:" + acct.getId());
    AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
    mAuth.signInWithCredential(credential)
            .addOnCompleteListener(activity, task -> {
                if (task.isSuccessful()) {
                    FirebaseUser user = mAuth.getCurrentUser();
                    account.setSummary(user.getUid());

                } else {
                    Log.e("GoogleSignFailed",task.getException().getMessage()+"");
                    Toast.makeText(activity,"Sign in failed!",Toast.LENGTH_SHORT).show();
                }
            });
}
 
Example 20
Source File: MainActivity.java    From snippets-android with Apache License 2.0 4 votes vote down vote up
public void getGoogleCredentials() {
    String googleIdToken = "";
    // [START auth_google_cred]
    AuthCredential credential = GoogleAuthProvider.getCredential(googleIdToken, null);
    // [END auth_google_cred]
}