K
K
kapai692014-11-24 20:34:56
symfony
kapai69, 2014-11-24 20:34:56

Symfony2 programmatic authorization and remember me?

With programmatic authorization in symphony

$token = new UsernamePasswordToken($user, null, 'secured_area', array('ROLE_USER'));
$this->get('security.context')->setToken($token);

How to post remember me cookies to a user?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alex, 2014-11-24
@shoomyst

It probably won't be easy. I would look somewhere in the direction of this:
\Symfony\Component\Security\Http\RememberMe\PersistentTokenBasedRememberMeServices

B
Boris Benkovsky, 2014-11-24
@benbor

If you want to set a cookie, most likely you will want to read it, for each request - symfony2 docs will help you, for example , here or here
, but all this is cumbersome, maybe it's easier to implement from the box?
If you explicitly want "as in symfony" then obviously you need to find "as in symfony" - https://github.com/symfony/Security/blob/master/Ht...

$series = base64_encode($this->secureRandom->nextBytes(64));
        $tokenValue = base64_encode($this->secureRandom->nextBytes(64));
        $this->tokenProvider->createNewToken(
            new PersistentToken(
                get_class($user = $token->getUser()),
                $user->getUsername(),
                $series,
                $tokenValue,
                new \DateTime()
            )
        );
        $response->headers->setCookie(
            new Cookie(
                $this->options['name'],
                $this->encodeCookie(array($series, $tokenValue)),
                time() + $this->options['lifetime'],
                $this->options['path'],
                $this->options['domain'],
                $this->options['secure'],
                $this->options['httponly']
            )
        );

or look elsewhere. Find exactly what you have already connected and call

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question