Generate new CSRF token without reloading the entire form

后端 未结 4 2138
误落风尘
误落风尘 2020-12-01 06:55

If a user gets logged out (due to session expiration or for other reasons) in the background while using my Symfony2 application, I have implemented a JS layer appearing on

4条回答
  •  醉酒成梦
    2020-12-01 07:33

    Use this to regenerate CSRF token (Since Symfony2.4):

    $csrf = $this->get('security.csrf.token_manager'); //Symfony\Component\Security\Csrf\CsrfTokenManagerInterface
    $token = $csrf->refreshToken($intention); // Intention is specified in form type
    
    return new Response($token);
    

提交回复
热议问题