Answer the question
In order to leave comments, you need to log in
PersistentTokenBasedRememberMeServices not setting cookies?
Why not set cookies?
The code is following
use Symfony\Component\Security\Http\RememberMe\PersistentTokenBasedRememberMeServices;
use Symfony\Component\Security\Core\Authentication\RememberMe\InMemoryTokenProvider;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Security\Core\Util\SecureRandom;
//...
public function registrationAction(Request $request)
{
$user = new User();
$form = $this->createForm(new RegistrationType(), $user);
$form->handleRequest($request);
if($form->isValid()){
/...
$providerKey = 'secured_area';
$token = new UsernamePasswordToken($user, null, $providerKey, array('ROLE_USER'));
$this->get('security.context')->setToken($token);
$key = $this->container->getParameter('secret');
$securityRandom = new SecureRandom();
$persistentService = new
PersistentTokenBasedRememberMeServices(array($user), $providerKey, $key, array('path' => '/', 'name' => 'sid', 'domain' => '.site.local', 'secure' => false, 'httponly' => false, 'lifetime' => 31536000, 'always_remember_me' => true, 'remember_me_parameter' => '_remember_me'), null, $securityRandom);
$persistentService->setTokenProvider(new InMemoryTokenProvider());
$response = new RedirectResponse('index');
$persistentService->loginSuccess($request, $response, $token);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question