We’ve successfully configured the FOSUserBundle; login, register, reset password, etc, are all working just fine.
Now we want to incorporate the login form into our general site layout, notably placing the form into the top-right section of the layout header. Doing this would be easy enough if we were just dealing with the username and password fields. However we can’t seem to figure out how to obtain the CSRF token which is generated by the FOSUserBundle service:
$this->container->get('form.csrf_provider')->generateCsrfToken('authenticate');
I tried calling the above within a Twig extension which otherwise works fine however apparently the extension can’t properly reference the container.
Surely there is some easy way to obtain the FOSUserBundle CSRF token globally?
Thanks!
Jason
You can define a function like this in one of your controllers
and then just embed it into your form via
You also need to include the following at the top of your controller: