title: Invalid CSRF token on my own login form
body: <p>I'm working on a symfony application using FOSUserBundle. I want to have a dropdown login form in the menubar if i am not authenticated, which have a complete different style that the one under /login. </p>
  
  <p>I'm getting 'Invalid CSRF token'. I'm a complete newbie to symfony2, so maybe i'm making an obvious mistake, but i can't find a solution googling. This is what i tried:</p>
  
  <p>Controller:</p>
  
  <pre><code>&lt;?php
  
  namespace RoiRodriguez\CustomUserBundle\Controller;
  
  use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  use Symfony\Component\Routing\Annotation\Route;
  use Symfony\Component\Security\Core\SecurityContext;
  
  class DefaultController extends Controller {
  
      /**
       * Para requests internos, renderiza la barra de navegación.
       * No tiene ruta.
       */
      public function navigationAction() {
          $params = array (
                  'csrf_token' =&gt; '',
                  'last_username' =&gt; '' 
          );
  
          if ($this-&gt;container-&gt;get ( 'security.context' )-&gt;isGranted ( 'IS_AUTHENTICATED_FULLY' )) {
              $session = $this-&gt;getRequest ()-&gt;getSession ();
              $params ['last_username'] = (null === $session) ? '' : $session-&gt;get ( SecurityContext::LAST_USERNAME );
              $params ['csrf_token'] = $this-&gt;container-&gt;get ( 'form.csrf_provider' )-&gt;generateCsrfToken ( 'authenticate' );
          }
  
          return $this-&gt;render ( 'CustomUserBundle:Default:navigation.html.twig', $params );
      }
  }
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>&lt;ul class="nav navbar-nav navbar-right"&gt;
  {% if app.user and app.user.isGranted('IS_AUTHENTICATED_FULLY') %}
      {% include 'CustomUserBundle:Default:includes/navigation-authenticated.html.twig' %}
  {% else %}
      {% include 'CustomUserBundle:Default:includes/navigation-notauthenticated.html.twig' with {'csrf_token': csrf_token, 'last_username': last_username} %}
  {% endif %}
  &lt;/ul&gt;
  </code></pre>
  
  <p>Not authenticated template:</p>
  
  <pre><code>&lt;li&gt;&lt;a href="{{ path('fos_user_registration_register') }}"&gt;Nueva cuenta&lt;/a&gt;&lt;/li&gt;
  &lt;li class="dropdown"&gt;&lt;a href="#" class="dropdown-toggle"
      data-toggle="dropdown"&gt;Ingresar &lt;b class="caret"&gt;&lt;/b&gt;&lt;/a&gt;
      &lt;div class="dropdown-menu dd-login-form-container"&gt;
  
          &lt;!-- login form --&gt;
          &lt;form role="form" method="post"
              action="{{ path("fos_user_security_check") }}"&gt;
              &lt;input type="hidden" name="_csrf_token" value="{{ csrf_token }}" /&gt;
  ......
              &lt;button type="submit" class="btn btn-primary"&gt;Ingresa!&lt;/button&gt;
          &lt;/form&gt;
          &lt;!-- end login form --&gt;
          &lt;ul&gt;
              &lt;li&gt;&lt;a href="{{ path('fos_user_resetting_request') }}"&gt;¿Has olvidado
                      tu contraseña?&lt;/a&gt;&lt;/li&gt;
              &lt;li&gt;&lt;a href="{{ path('fos_user_registration_register') }}"&gt;¿Todavía
                      no tienes una cuenta?&lt;/a&gt;&lt;/li&gt;
          &lt;/ul&gt;
      &lt;/div&gt;
  &lt;/li&gt;
  </code></pre>
  
  <p>What am i missing? Also: This dropdown menu gets rendered inside /login too, would i have any trouble with generating the token twice there?</p>