@Override public Completable loginWithGoogle(final Activity activity) { return Single.create((SingleOnSubscribe<AuthCredential>) e -> { googleClient = new GoogleApiClient.Builder(activity) .addApi(Auth.GOOGLE_SIGN_IN_API, gso) .build(); Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(googleClient); activity.startActivityForResult(signInIntent, RC_GOOGLE_SIGN_IN); googleSignInCompleteListener = result -> { if(result.isSuccess()) { AuthCredential credential = GoogleAuthProvider.getCredential(result.getSignInAccount().getIdToken(), null); e.onSuccess(credential); } else { e.onError(new Exception(result.getStatus().toString())); } }; }).flatMapCompletable(authCredential -> signInWithCredential(activity, authCredential)); }
private void handleSignInResult(GoogleSignInResult result){ Log.i("robin", "handleSignInResult:" + result.isSuccess()); if(result.isSuccess()){ Log.i("robin", "成功"); GoogleSignInAccount acct = result.getSignInAccount(); if(acct!=null){ Log.i("robin", "用户名是:" + acct.getDisplayName()); Log.i("robin", "用户email是:" + acct.getEmail()); Log.i("robin", "用户头像是:" + acct.getPhotoUrl()); Log.i("robin", "用户Id是:" + acct.getId());//之后就可以更新UI了 Log.i("robin", "用户IdToken是:" + acct.getIdToken()); tvMsg.setText("用户名是:" + acct.getDisplayName()+"\n用户email是:" + acct.getEmail()+"\n用户头像是:" + acct.getPhotoUrl()+ "\n用户Id是:" + acct.getId()+"\n用户IdToken是:" + acct.getIdToken()); } }else{ tvMsg.setText("登录失败"); Log.i("robin", "没有成功"+result.getStatus()); } }
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) { Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful()); if (!task.isSuccessful()) { Log.d("Reached", "2"); Log.w(TAG, "signInWithCredential", task.getException()); Toast.makeText(Login.this, "Authentication failed.", Toast.LENGTH_SHORT).show(); } } }); }
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) { AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null); mFirebaseAuth.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"); // Signed in successfully, show authenticated UI. showDashboard(); } else { // If sign in fails, display a message to the user. Log.w(TAG, "signInWithCredential:failure", task.getException()); } } }); }
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(); } } }); }
private void firebaseAuthWithGoogle(GoogleSignInAccount account) { AuthCredential credential = GoogleAuthProvider.getCredential(account.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(MainActivity.this, "Authentication failed.", Toast.LENGTH_SHORT).show(); } // ... } }); }
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) { AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null); mAuth.signInWithCredential(credential) .addOnCompleteListener(this, task -> { if (task.isSuccessful()) { FirebaseUser user = mAuth.getCurrentUser(); finish(); } else { Toast.makeText(getApplicationContext(), "Authentication failed", Toast.LENGTH_SHORT ).show(); } }); } }
.login("google-oauth2-token", account.getIdToken()) .enqueue(new DefaultCallback<LoginResponse>() {
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()) { Log.d(TAG, "signInWithCredential:success"); FirebaseUser user = mAuth.getCurrentUser(); Toast.makeText(LoginActivity.this, "Signed in", Toast.LENGTH_SHORT).show(); Intent intent = new Intent(LoginActivity.this, MainActivity.class); startActivity(intent); } else { Log.w(TAG, "signInWithCredential:failure", task.getException()); Toast.makeText(LoginActivity.this, "Authentication failed.", Toast.LENGTH_SHORT).show(); } // The Hide Progress Bar Always Called After Request Completion hideProgress(); } }); } @Override
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); } }); }
private GoogleAuthUser parseToGoogleUser(GoogleSignInAccount account) { GoogleAuthUser user = new GoogleAuthUser(); user.name = account.getDisplayName(); user.familyName = account.getFamilyName(); user.idToken = account.getIdToken(); user.email = account.getEmail(); user.photoUrl = account.getPhotoUrl(); return user; }
private void firebaseAuthWithGoogle(GoogleSignInAccount account) { AuthCredential credential = GoogleAuthProvider.getCredential(account.getIdToken(), null); mAuth.signInWithCredential(credential).addOnCompleteListener(this, task -> { if (task.isSuccessful()) { // Sign in success, update UI with the signed-in user's information FirebaseUser user = mAuth.getCurrentUser(); if (user != null) { mPresenter.handleLoginSuccess(user.getEmail(), user.getDisplayName() , user.getPhotoUrl()); } else { mPresenter.handleLoginFailure(0, getString(R.string.unable_to_login)); } } else { // If sign in fails, display a message to the user. mPresenter.handleLoginFailure(0, getString(R.string.something_went_wrong)); } }); } }