to connect the user, you need this kind of code :
$args = array(
// args for searching the user
);
$wp_user_search = new \WP_User_Query($args);
$items = $wp_user_search->get_results();
$user = array_pop($items);
// connecting the user
wp_set_auth_cookie(
$user->ID
, TRUE // $remember
);
// redirect to admin root
wp_redirect(admin_url("https://wordpress.stackexchange.com/"));
exit();