Java Code Examples for com.google.android.gms.auth.api.signin.GoogleSignInResult#getSignInAccount()

The following examples show how to use com.google.android.gms.auth.api.signin.GoogleSignInResult#getSignInAccount() . 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: SignInController.java    From PGSGP with MIT License 6 votes vote down vote up
public void onSignInActivityResult(GoogleSignInResult googleSignInResult) {
    if (googleSignInResult != null && googleSignInResult.isSuccess()) {
        GoogleSignInAccount googleSignInAccount = googleSignInResult.getSignInAccount();
        String accId = "";
        if (googleSignInAccount != null && googleSignInAccount.getId() != null) {
        	accId = googleSignInAccount.getId();
        }
        enablePopUps();
        godotCallbacksUtils.invokeGodotCallback(GodotCallbacksUtils.SIGNIN_SUCCESSFUL, new Object[]{accId});
    } else {
    	int statusCode = Integer.MIN_VALUE;
    	if (googleSignInResult != null && googleSignInResult.getStatus() != null){
    		statusCode = googleSignInResult.getStatus().getStatusCode();
    	}
        godotCallbacksUtils.invokeGodotCallback(GodotCallbacksUtils.SIGNIN_FAILED, new Object[]{statusCode});
    }
}
 
Example 2
Source File: UpdateFragment.java    From Android-nRF-Beacon-for-Eddystone with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void handleSignInResult(GoogleSignInResult result) {
    Log.d(Utils.TAG, "handleSignInResult:" + result.isSuccess());
    if (result.isSuccess()) {
        mSilentSignInFailed = false;
        // Signed in successfully, show authenticated UI.
        GoogleSignInAccount acct = result.getSignInAccount();
        mServerAuthCode = acct.getServerAuthCode();
        if(!checkIfAccessTokenExists()) {
            if (!Utils.UTILS_CLIENT_ID.equals(getString(R.string.server_client_id))) {
                new RequestAccessTokenTask(getActivity(), mRequestAccessTokenCallback, "https://www.googleapis.com/oauth2/v4/token", getString(R.string.server_client_id), acct.getServerAuthCode()).execute();
            } else {
                showToast(getString(R.string.error_server_client_id));
            }
        }
    } else {
        mSilentSignInFailed = true;
    }
}
 
Example 3
Source File: GoogleLogin.java    From Android-Smart-Login with Apache License 2.0 6 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data, SmartLoginConfig config) {
    ProgressDialog progress = ProgressDialog.show(config.getActivity(), "", config.getActivity().getString(R.string.getting_data), true);
    GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
    Log.d("GOOGLE SIGN IN", "handleSignInResult:" + result.isSuccess());
    if (result.isSuccess()) {
        // Signed in successfully, show authenticated UI.
        GoogleSignInAccount acct = result.getSignInAccount();
        SmartGoogleUser googleUser = UserUtil.populateGoogleUser(acct);
        // Save the user
        UserSessionManager.setUserSession(config.getActivity(), googleUser);
        config.getCallback().onLoginSuccess(googleUser);
        progress.dismiss();
    } else {
        Log.d("GOOGLE SIGN IN", "" + requestCode);
        // Signed out, show unauthenticated UI.
        progress.dismiss();
        config.getCallback().onLoginFailure(new SmartLoginException("Google login failed", LoginType.Google));
    }
}
 
Example 4
Source File: SignInBaseActivity.java    From Expert-Android-Programming with MIT License 6 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
    if (requestCode == RC_SIGN_IN) {
        GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
        if (result.isSuccess()) {
            // Google Sign In was successful, authenticate with FireBase
            GoogleSignInAccount account = result.getSignInAccount();
            firebaseAuthWithGoogle(account);
        }
    } else {
        callbackManager.onActivityResult(requestCode, resultCode, data);
    }
}
 
Example 5
Source File: FireSignin.java    From Learning-Resources with MIT License 6 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    mCallbackManager.onActivityResult(requestCode, resultCode, data);

    if (requestCode == REQUESTCODE_SIGN_IN_GOOGLE) {
        GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
        if (result.isSuccess()) {

            // Google Sign In was successful, authenticate with Firebase
            GoogleSignInAccount account = result.getSignInAccount();
            firebaseAuthWithGoogle(account);
        } else {
            mPrgrsbrMain.setVisibility(View.GONE);
            Snackbar.make(mCrdntrlyot, "Google authentication failed.", Snackbar.LENGTH_LONG).show();
        }
    }
}
 
Example 6
Source File: Fido2DemoActivity.java    From android-fido with Apache License 2.0 6 votes vote down vote up
private void handleSignInResult(GoogleSignInResult result) {
    Log.d(TAG, "handleSignInResult:" + result.isSuccess());
    Log.d(TAG, "sign in result: " + result.getStatus().toString());
    if (result.isSuccess()) {
        GoogleSignInAccount acct = result.getSignInAccount();
        saveAccountSignInStatus();
        Log.d(TAG, "account email" + acct.getEmail());
        Log.d(TAG, "account displayName" + acct.getDisplayName());
        Log.d(TAG, "account id" + acct.getId());
        Log.d(TAG, "account idToken" + acct.getIdToken());
        Log.d(TAG, "account scopes" + acct.getGrantedScopes());
    } else {
        clearAccountSignInStatus();
    }
    updateUI();
}
 
Example 7
Source File: Loginactivity.java    From LuxVilla with Apache License 2.0 6 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
    if (requestCode == RC_SIGN_IN) {
        GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
        if (result.isSuccess()) {
            // Google Sign In was successful, authenticate with Firebase
            GoogleSignInAccount account = result.getSignInAccount();
            firebaseAuthWithGoogle(account);
        } else {
            linearLayout.setVisibility(View.VISIBLE);
            layoutprogressbar.setVisibility(View.GONE);
            Snackbar.make(linearLayout,"Ocorreu um erro ao conectar", Snackbar.LENGTH_LONG).show();
        }
    }
}
 
Example 8
Source File: SignInActivity.java    From jterm-cswithandroid with Apache License 2.0 6 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
    if (requestCode == RC_SIGN_IN) {
        GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
        if (result.isSuccess()) {
            // Google Sign In was successful, authenticate with Firebase
            GoogleSignInAccount account = result.getSignInAccount();
            firebaseAuthWithGoogle(account);
        } else {
            // Google Sign In failed
            Log.e(TAG, "Google Sign In failed.");
        }
    }
}
 
Example 9
Source File: Home.java    From UberClone with MIT License 6 votes vote down vote up
private void handleSignInResult(GoogleSignInResult result) {
    if (result.isSuccess()) {
        account = result.getSignInAccount();
        Common.userID=account.getId();
        loadUser();
    }else if(isLoggedInFacebook){
        GraphRequest request = GraphRequest.newMeRequest(
                accessToken,
                new GraphRequest.GraphJSONObjectCallback() {
                    @Override
                    public void onCompleted(JSONObject object, GraphResponse response) {
                        String id=object.optString("id");
                        Common.userID=id;
                        loadUser();
                    }
                });
        request.executeAsync();
    }else{
        Common.userID=FirebaseAuth.getInstance().getCurrentUser().getUid();
        loadUser();
    }
}
 
Example 10
Source File: LoginPresenter.java    From FastAccess with GNU General Public License v3.0 6 votes vote down vote up
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == SIGN_IN_REQUEST_CODE) {
        if (isAttached()) {
            GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
            if (result.isSuccess()) {
                GoogleSignInAccount account = result.getSignInAccount();
                if (account != null) {
                    getView().onSignedIn(account);
                } else {
                    getView().onShowMessage(R.string.failed_login);
                }
            } else {
                getView().onShowMessage(R.string.failed_login);
            }
        }
    }

}
 
Example 11
Source File: Fido2DemoActivity.java    From security-samples with Apache License 2.0 6 votes vote down vote up
private void handleSignInResult(GoogleSignInResult result) {
    Log.d(TAG, "handleSignInResult:" + result.isSuccess());
    Log.d(TAG, "sign in result: " + result.getStatus().toString());
    if (result.isSuccess()) {
        GoogleSignInAccount acct = result.getSignInAccount();
        saveAccountSignInStatus();
        Log.d(TAG, "account email" + acct.getEmail());
        Log.d(TAG, "account displayName" + acct.getDisplayName());
        Log.d(TAG, "account id" + acct.getId());
        Log.d(TAG, "account idToken" + acct.getIdToken());
        Log.d(TAG, "account scopes" + acct.getGrantedScopes());
    } else {
        clearAccountSignInStatus();
    }
    updateUI();
}
 
Example 12
Source File: ProfileActivity.java    From friendlypix-android with Apache License 2.0 5 votes vote down vote up
private void handleGoogleSignInResult(GoogleSignInResult result) {
    Log.d(TAG, "handleSignInResult:" + result.getStatus());
    if (result.isSuccess()) {
        // Successful Google sign in, authenticate with Firebase.
        GoogleSignInAccount acct = result.getSignInAccount();
        firebaseAuthWithGoogle(acct);
    } else {
        // Unsuccessful Google Sign In, show signed-out UI
        Log.d(TAG, "Google Sign-In failed.");
    }
}
 
Example 13
Source File: Login.java    From UberClone with MIT License 5 votes vote down vote up
private void handleSignInResult(GoogleSignInResult result) {
    if (result.isSuccess()){
        account = result.getSignInAccount();
        firebaseHelper.registerByGoogleAccount(account);
    }else{
        Message.messageError(this, Errors.ERROR_LOGIN_GOOGLE);
    }
}
 
Example 14
Source File: EasyFirebaseAuth.java    From EasyFirebase with Apache License 2.0 5 votes vote down vote up
public void onActivityResult(int requestCode, Intent data) {
    if (requestCode == RC_SIGN_IN) {
        // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
        GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
        if (result.isSuccess()) {
            // Google Sign In was successful, authenticate with Firebase
            googleSignInAccount = result.getSignInAccount();
            AuthCredential credential = GoogleAuthProvider.getCredential(googleSignInAccount.getIdToken(), null);
            mAuth.signInWithCredential(credential)
                    .addOnCompleteListener(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());
                            }
                            // ...
                        }
                    });
        } else {
            if (firebaseUserSubscriber != null) {
                firebaseUserSubscriber.onError(new Throwable("error while signing with google"));
            }
            // Google Sign In failed, update UI appropriately
            // ...
        }
    }
}
 
Example 15
Source File: LoginActivity.java    From buddysearch with Apache License 2.0 5 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == RC_SIGN_IN) {
        view.hideProgress();
        GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
        if (result.isSuccess()) {
            view.showProgress(getString(R.string.authenticating));
            GoogleSignInAccount account = result.getSignInAccount();
            presenter.signInWithGoogle(account);
        }
    }
}
 
Example 16
Source File: LoginActivity.java    From android with MIT License 5 votes vote down vote up
private void handleGoogleSignInResult(GoogleSignInResult result) {
    if (result.isSuccess()) {
        // Signed in successfully
        final GoogleSignInAccount account = result.getSignInAccount();
        runSocialLoginTask(Const.ApiValues.OAUTH_TYPE_GOOGLEPLUS, account.getIdToken());
    } else if (result.getStatus().hasResolution()) {
        try {
            result.getStatus().startResolutionForResult(this, Const.RequestCodes.AUTH_LOGIN_GOOGLE_RESOLVE);
        } catch (IntentSender.SendIntentException e) {
            e.printStackTrace();
        }
    } else {
        final Status status = result.getStatus();
        if (status.isCanceled() || status.isInterrupted()) {
            return;
        }

        String msg = GoogleApiAvailability.getInstance()
                .getErrorString(status.getStatusCode());
        if (TextUtils.isEmpty(msg)) {
            msg = String.valueOf(status.getStatusCode());
        }

        final String message = String.format(
                getResources().getString(R.string.snackbar_auth_error_google),
                msg
        );
        RedSnackbar.make(findViewById(R.id.root_view),
                message,
                Snackbar.LENGTH_LONG)
                .show();
    }
}
 
Example 17
Source File: HomeActivity.java    From Movie-Check with Apache License 2.0 5 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == RC_SIGN_IN) {
        GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
        if (result.isSuccess()) {
            GoogleSignInAccount googleSignInAccount = result.getSignInAccount();
            User user = new User(googleSignInAccount.getId(), googleSignInAccount.getDisplayName(),
                    googleSignInAccount.getEmail(), googleSignInAccount.getPhotoUrl().toString());
            presenter.login(user);
        }
    }
}
 
Example 18
Source File: GoogleSignInDialogFragment.java    From Android-nRF-Beacon-for-Eddystone with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void handleSignInResult(GoogleSignInResult result) {
    Log.d(Utils.TAG, "handleSignInResult:" + result.isSuccess());
    hideProgressDialog();
    if (result.isSuccess()) {
        // Signed in successfully, show authenticated UI.
        GoogleSignInAccount acct = result.getSignInAccount();
        Log.d(Utils.TAG, "handleSignInResult:" + acct.getEmail() + " " + acct.getDisplayName());
        mServerAuthCode = acct.getServerAuthCode();
        new RequestAccessTokenTask(getActivity(), mRequestAccessTokenCallback, "https://www.googleapis.com/oauth2/v4/token", getString(R.string.server_client_id), acct.getServerAuthCode()).execute();
    } else {
        Toast.makeText(getActivity(), getString(R.string.google_sign_in_denied), Toast.LENGTH_LONG).show();
    }
}
 
Example 19
Source File: PlayActivity.java    From firebase-android-client with Apache License 2.0 4 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == RC_SIGN_IN) {
        GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
        Log.d(TAG, "Google authentication status: " + result.getStatus().getStatusMessage());
        // If Google ID authentication is successful, obtain a token for Firebase authentication.
        if (result.isSuccess() && result.getSignInAccount() != null) {
            status.setText(getResources().getString(R.string.authenticating_label));
            AuthCredential credential = GoogleAuthProvider.getCredential(
                    result.getSignInAccount().getIdToken(), null);
            FirebaseAuth.getInstance().signInWithCredential(credential)
                    .addOnCompleteListener(this, task -> {
                        Log.d(TAG, "signInWithCredential:onComplete Successful: " + task.isSuccessful());
                        if (task.isSuccessful()) {
                            final FirebaseUser currentUser = FirebaseAuth.getInstance().getCurrentUser();
                            if (currentUser != null) {
                                inbox = "client-" + Integer.toString(Math.abs(currentUser.getUid().hashCode()));
                                requestLogger(() -> {
                                    Log.d(TAG, "onLoggerAssigned logger id: " + inbox);
                                    fbLog.log(inbox, "Signed in");
                                    updateUI();
                                });
                            } else {
                                updateUI();
                            }
                        } else {
                            Log.w(TAG, "signInWithCredential:onComplete", task.getException());
                            status.setText(String.format(
                                    getResources().getString(R.string.authentication_failed),
                                    task.getException())
                            );
                        }
                    });
        } else if (result.getStatus().isCanceled()) {
            String message = "Google authentication was canceled. "
                    + "Verify the SHA certificate fingerprint in the Firebase console.";
            Log.d(TAG, message);
            showErrorToast(new Exception(message));
        } else {
            Log.d(TAG, "Google authentication status: " + result.getStatus().toString());
            showErrorToast(new Exception(result.getStatus().toString()));
        }
    }
}
 
Example 20
Source File: DriverTracking.java    From UberClone with MIT License 4 votes vote down vote up
private void handleSignInResult(GoogleSignInResult result) {
    if (result.isSuccess()) {
        account = result.getSignInAccount();
    }
}