Can't log in user with Rest service i'm trying to build a Headless Drupal app with symfony, i'm stuck with login, i build a custom module for drupal 8 with four functions, (login,logout,register,login_status):

&lt;?php

/**
 * @file
 * Contains \Drupal\remoteuser\Controller\RemoteUserController
 */

 namespace Drupal\remoteuser\Controller;

 use Drupal\Core\Controller\ControllerBase;
 use Drupal\Core\Form\FormState;
 use Drupal\Core\Entity;
 use Drupal\user\Controller;
 use Symfony\Component\HttpFoundation\JsonResponse;

class RemoteUserController extends ControllerBase
{
  public function login() {
    $form_state = (new FormState())-&gt;setValues($_POST);
    \Drupal::formBuilder()-&gt;submitForm('\Drupal\user\Form\UserLoginForm', $form_state);

    // Check for errors from the from
    if ($errors = $form_state-&gt;getErrors()) {
      // Return errors to notify the client.
      return new JsonResponse( array( 'error' =&gt; $errors ) );
    }
    else {
      // Return new user session to client.
      $uid = \Drupal::service('user.auth')-&gt;authenticate($_POST['name'], $_POST['pass']);
      $session_manager = \Drupal::service('session_manager');
      $session_id = $session_manager-&gt;getId();
      return new JsonResponse( array( 'uid' =&gt; $uid, 'session_id' =&gt; $session_id ) );
    }
  }

  public function register() {
    // Validate the e-mail address first.
    if (!\Drupal::service('email.validator')-&gt;isValid($_POST['mail'])) {
      return new JsonResponse( array( 'error' =&gt; 'Invalid e-mail address' ) );
    }

    // Create password if it was not provided.
    $password = $_POST['pass'] ? $_POST['pass'] : user_password();

    /** @var \Drupal\user\Entity\User $user */
    $user = entity_create('user', array(
      'name' =&gt; $_POST['name'],
      'mail' =&gt; $_POST['mail'],
      'pass' =&gt; $password,
    ));

    // Validate the object.
    $errors = $user-&gt;validate();

    if ($errors-&gt;count() &gt; 0) {
      // Return errors to notify the client.
      return new JsonResponse( array( 'error' =&gt; $errors-&gt;__toString() ) );
    } else {
      // Save new user
      $user-&gt;save();
      // Return new user credentials
      return new JsonResponse( array( 'user' =&gt; $user-&gt;toArray() ) );
    }
  }

  public function logout() {
    $result = user_logout();

    return new JsonResponse($result);
  }

  public function login_status() {
    $uid = \Drupal::currentUser()-&gt;id();

    $session_manager = \Drupal::service('session_manager');
    $session_id = $session_manager-&gt;getId();

    return new JsonResponse( array( 'uid' =&gt; $uid, 'session_id' =&gt; $session_id ) );
  }
}


all working great except for login !, it authenticate and returns successfully the user, but when i check with login_status, it returns an anonymous user !!. but the magic is that when i test with Postman google chrome plugin, login_status returns successfully the logged in user !!, maybe the cookies are not handled correctly in symfony !! i tried also with Drupal 7 Rest services, same problem, the user is not logged in !!
Finally, it works :D, I'll just put this answer here to help how still don't know how to login user via my custom Web Services API, i had to manage the cookies from the frontend, I use symfony, after sending a POST request to /{endpoint}/user/login, and receive the response that will look like this:

{
    "sessid": "ZkJ26dMEQQ-K3VkE9zv2Cni2lWergSOOnPlF3jkiF-Q",
    "session_name": "SESS948facaca231cedd9a2a526239dcb6dc",
    "token": "icfD3CNT4r4QAlEGiYmqzez0MVmsPbAowVR8HtfaD4Y",
    "user": {
        "uid": "1",
        "name": "admin",
        "mail": "contact@headless.com",
        "theme": "",
        "signature": "",
        "signature_format": null,
        "created": "1459037019",
        "access": "1459439836",
        "login": 1459440402,
        "status": "1",
        "timezone": "Europe/Paris",
        "language": "",
        "picture": "0",
        "init": "contact@headless.com",
        "data": false,
        "roles": {
            "2": "authenticated user"
        }
    }
}


i create a cookie with (any name) and the value will be "session_name=sessid", don't forget the "=".
and finally to see if the user is logged in, you need the token and the cookie that you created, send a POST request to {endpoint}/system/connect WITH this HEADERS:

X-CSRF-Token: token from the login response
Cookie: SESS948facaca231cedd9a2a526239dcb6dc=ZkJ26dMEQQ-K3VkE9zv2Cni2lWergSOOnPlF3jkiF-Q (session_name=sessid)


and voila :D, you get a response like this:

{
    "sessid": "ZkJ26dMEQQ-K3VkE9zv2Cni2lWergSOOnPlF3jkiF-Q",
    "session_name": "SESS948facaca231cedd9a2a526239dcb6dc",
    "user": {
        "uid": "1",
        "name": "admin",
        "mail": "contact@headless.com",
        "theme": "",
        "signature": "",
        "signature_format": null,
        "created": "1459037019",
        "access": "1459440402",
        "login": "1459440402",
        "status": "1",
        "timezone": "Europe/Paris",
        "language": "",
        "picture": "0",
        "init": "contact@headless.com",
        "data": false,
        "sid": "ZkJ26dMEQQ-K3VkE9zv2Cni2lWergSOOnPlF3jkiF-Q",
        "ssid": "",
        "hostname": "127.0.0.1",
        "timestamp": "1459440402",
        "cache": "0",
        "session": "",
        "roles": {
            "2": "authenticated user"
        }
    }
}


i hope my answer help any one how is looking for how to login users via Drupal Services.