Skip to content

Instantly share code, notes, and snippets.

@akovalyov
Created November 23, 2016 11:44
Show Gist options
  • Save akovalyov/e7598581de38b9fdbfa0407709fd6800 to your computer and use it in GitHub Desktop.
Save akovalyov/e7598581de38b9fdbfa0407709fd6800 to your computer and use it in GitHub Desktop.
<?php
namespace AppBundle\Security\Authentication;
use AGILEmentBundle\Entity\User;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
class AutoLogin
{
const FIREWALL_APP = 'main';
private $tokenStorage;
public function __construct(TokenStorageInterface $tokenStorage)
{
$this->tokenStorage = $tokenStorage;
}
public function login(User $user, $firewall = self::FIREWALL_APP)
{
$token = new UsernamePasswordToken($user, null, $firewall, $user->getRoles());
$this->tokenStorage->setToken($token);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment