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 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; }
public void signup(int mifosSavingsProductId) { showProgressDialog(Constants.PLEASE_WAIT); Intent intent = new Intent(LoginActivity.this, MobileVerificationActivity.class); intent.putExtra(Constants.MIFOS_SAVINGS_PRODUCT_ID, mMifosSavingProductId); if (account != null) { intent.putExtra(Constants.GOOGLE_PHOTO_URI, account.getPhotoUrl()); intent.putExtra(Constants.GOOGLE_DISPLAY_NAME, account.getDisplayName()); intent.putExtra(Constants.GOOGLE_EMAIL, account.getEmail()); intent.putExtra(Constants.GOOGLE_FAMILY_NAME, account.getFamilyName()); intent.putExtra(Constants.GOOGLE_GIVEN_NAME, account.getGivenName()); } hideProgressDialog(); startActivity(intent); if (googleSignInClient != null) { googleSignInClient.signOut().addOnCompleteListener(this, new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { account = null; } }); } } }
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(); } } }); }
@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) { if (BuildConfig.DEBUG) { Log.d(MCXApplication.LOG_TAG, "handleSignInResult:" + result.isSuccess() + " " + result.getStatus().getStatusCode() + result.getStatus().hasResolution()); } if (result.isSuccess()) { // Signed in successfully, show authenticated UI. GoogleSignInAccount acct = result.getSignInAccount(); User user = new User(); user.setProvider(PROVIDER_NAME); user.setProviderDisplayName("Google+"); user.setUserId(acct.getId()); user.setUserName(acct.getId()); user.setDisplayName(acct.getDisplayName()); user.setMail(acct.getEmail()); this.mUserHelper.setCurrentUser(user); if (this.mUserSessionCallback != null) { this.mUserSessionCallback.onLogin(); } } else { // Signed out, show unauthenticated UI. this.mUserSessionCallback.onLogout(); } }
@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(); } } });
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_CODE_OAUTH) { if (resultCode == Activity.RESULT_OK && data != null) { // Extract the server auth code and user email GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data); if (result.isSuccess() && result.getSignInAccount() != null) { AuthenticationInfo auth = new AuthenticationInfo(); auth.serverAuthCode = result.getSignInAccount().getServerAuthCode(); auth.accountEmail = result.getSignInAccount().getEmail(); Preferences.setAuthenticationInfo(getContext(), Provider.GDRIVE, auth); requestAccessToken(); return; } } handleError(); } }
private void firebaseAuthWithPlayGames(GoogleSignInAccount acct) { Log.d(TAG, "firebaseAuthWithPlayGames:" + acct.getId()); final FirebaseAuth auth = FirebaseAuth.getInstance(); AuthCredential credential = PlayGamesAuthProvider.getCredential(acct.getServerAuthCode()); auth.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 = auth.getCurrentUser(); 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(); updateUI(null); } // ... } }); } // [END games_auth_with_firebase]
private void handleSignInResult(Task<GoogleSignInAccount> completedTask) { try { GoogleSignInAccount account = completedTask.getResult(ApiException.class); firebaseAuthWithGoogle(account); Log.i(TAG, account.getDisplayName()); } catch (ApiException e) { // The ApiException status code indicates the detailed failure reason. // Please refer to the GoogleSignInStatusCodes class reference for more information. Log.w(TAG, "TAG:failed code=" + e.getStatusCode()); Toast.makeText(this, ":" + e.getStatusCode(), Toast.LENGTH_SHORT).show(); } }
@Override protected void onPostExecute(String token) { GoogleSignInAccount acct = result.getSignInAccount(); mListener.onGoogleAuthSignIn(token, acct.getId()); } };
private void handleGooglSignInResult(final GoogleSignInResult result) { if (result == null) { Log.e(TAG, "Got a null GoogleSignInResult"); return; } Log.d(TAG, "handleGooglSignInResult:" + result.isSuccess()); if (result.isSuccess()) { final GoogleCredential googleCredential = new GoogleCredential(result.getSignInAccount().getServerAuthCode()); _client.getAuth().loginWithCredential(googleCredential).addOnCompleteListener(new OnCompleteListener<StitchUser>() { @Override public void onComplete(@NonNull final Task<StitchUser> task) { if (task.isSuccessful()) { initTodoView(); } else { Log.e(TAG, "Error logging in with Google", task.getException()); } } }); } }
String personName = acct.getDisplayName(); String personGivenName = acct.getGivenName(); String personFamilyName = acct.getFamilyName(); String personEmail = acct.getEmail(); String personId = acct.getId(); Uri personPhoto = acct.getPhotoUrl();
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) { 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 handleSignInSuccess(GoogleSignInAccount account) { Toast.makeText(getActivity(), getString(R.string.welcome_user, account.getDisplayName()), Toast.LENGTH_LONG).show(); ((BikestoreApplication) getActivity().getApplication()).login(account.getEmail()); getActivity().setResult(Activity.RESULT_OK); getActivity().finish(); }
private void handleSignInResult(GoogleSignInResult result) { if (result.isSuccess()) { Log.d("G + login success"); GoogleSignInAccount acct = result.getSignInAccount(); SocialProfile socialProfile = new SocialProfile(PROVIDER_GOOGLE, acct.getId(), acct.getPhotoUrl()==null?null:acct.getPhotoUrl().toString()); user = new User(acct.getEmail(), acct.getDisplayName(), socialProfile); loggedInMode = USER_LOGIN_GOOGLE; loginUser(user.getProvider() != null); } else { // Signed out, show unauthenticated UI. Log.d("G + logout"); } }
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 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(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(); } } }); }