title: Symfony - Authentication lost after redirection
body: <p>I'm facing a problem with my Symfony project.</p>
  
  <p>I have two Symfony apps (let's call them A and B) who can communicate with each other by Web Service. In one of them (app A), I store my list of users, and I'm trying to authenticate an user through app B.
  The expected behavior is :
  - User enters his username and password
  - App B gets the username/password
  - App B calls App A through a WS, asking if this user is OK
  - If user OK, App B creates a session token and authentifies the user.</p>
  
  <p>At the moment, I'm able to authenticate my user, but every time I navigate through app B, I lose my session token (so I'm redirected to my /login page).
  The weird thing is that I'm still authenticated, but the session token doesn't contain my User object anymore (it contains a User object with every attribute "null").</p>
  
  <p>Here is my security.yml :</p>
  
  <pre><code>providers:
      webservice:
          id: webservice_user_provider
  
  firewalls:
      login:
          pattern: ^/login$|^/check$|^/_wdt
          anonymous: true
      secured:
          pattern: ^/
          anonymous: false
          form_login:
              check_path: /login_check
              login_path: login
              username_parameter:  username
              password_parameter:  password
              default_target_path: /
          logout:
              path:   logout
  
  access_control:
  </code></pre>
  
  <p>My LoginController (app B) :
      public function checkAction(Request $request)
      {<br>
          // Récupération du login et du mot de passe dans les paramètres de la requête
          if ($request->getMethod() == "POST")
          {
              $username = $request->get("username");
              $password = $request->get("password");</p>
  
  <pre><code>        // Interrogation du repo pour savoir si l'utilisateur existe
          $repo = $this-&gt;getDoctrine()-&gt;getRepository("EntrepotEntitiesBundle:Utilisateurecommercant");
  
          /* @var $repo \Entrepot\EntitiesBundle\Repository\UtilisateurecommercantRepository */
          $user = $repo-&gt;findByLoginAndPassword($username, $password);
  
          if ($user != null) // On a retrouvé un utilisateur =&gt; OK
          {
              // On sérialise alors un token de connexion dans la session
              $this-&gt;login($request, $user);
              return $this-&gt;indexAction();
          }
      }
  
      return $this-&gt;render('EntrepotUtilisateurBundle::index.html.twig', array(
          'last_username' =&gt; $this-&gt;getRequest()-&gt;getSession()-&gt;get(SecurityContext::LAST_USERNAME),
      ));
  }
  
  
  public function login(Request $request, UserInterface $user)
  {
      $token = new UsernamePasswordToken($user, $user-&gt;getPassword(), 'secured', $user-&gt;getRoles());
      $request-&gt;getSession()-&gt;set('_security_secured', serialize($token));
      $this-&gt;get("security.context")-&gt;setToken($token);
  
      // Et on lève un évènement "login"
      $event = new InteractiveLoginEvent($request, $token);
      $this-&gt;get("event_dispatcher")-&gt;dispatch("security.interactive_login", $event);
  }
  </code></pre>
  
  <p>One thing I don't understand, is when and how the <code>checkAction()</code> should be called. At this moment, it is only called when my user validates his login form. Should it be called every time I try to navigate to a new page ? I don't really understand how it works, and I'd like to understand it better...</p>
  
  <p>Did I forget something ?</p>
  
  <p>Thanks.</p>