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 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()); } } }); } }
@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(); } }