K
K
kapai692014-11-30 21:53:47
symfony
kapai69, 2014-11-30 21:53:47

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);
}
}

The error code does not give out, but the cookie is not set either! Where is the mistake?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex, 2014-11-30
@shoomyst

Something is very scary. The parameters seem to be mixed up.
Plug in xdebug and walk through the code

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question