vendor/symfony/symfony/src/Symfony/Component/Security/Core/Authentication/Token/RememberMeToken.php line 21

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\Security\Core\Authentication\Token;
  11. use Symfony\Component\Security\Core\User\UserInterface;
  12. /**
  13.  * Authentication Token for "Remember-Me".
  14.  *
  15.  * @author Johannes M. Schmitt <schmittjoh@gmail.com>
  16.  */
  17. class RememberMeToken extends AbstractToken
  18. {
  19.     private $secret;
  20.     private $providerKey;
  21.     /**
  22.      * @param string $secret A secret used to make sure the token is created by the app and not by a malicious client
  23.      *
  24.      * @throws \InvalidArgumentException
  25.      */
  26.     public function __construct(UserInterface $userstring $providerKeystring $secret)
  27.     {
  28.         parent::__construct($user->getRoles());
  29.         if (empty($secret)) {
  30.             throw new \InvalidArgumentException('$secret must not be empty.');
  31.         }
  32.         if (empty($providerKey)) {
  33.             throw new \InvalidArgumentException('$providerKey must not be empty.');
  34.         }
  35.         $this->providerKey $providerKey;
  36.         $this->secret $secret;
  37.         $this->setUser($user);
  38.         parent::setAuthenticated(true);
  39.     }
  40.     /**
  41.      * {@inheritdoc}
  42.      */
  43.     public function setAuthenticated($authenticated)
  44.     {
  45.         if ($authenticated) {
  46.             throw new \LogicException('You cannot set this token to authenticated after creation.');
  47.         }
  48.         parent::setAuthenticated(false);
  49.     }
  50.     /**
  51.      * Returns the provider secret.
  52.      *
  53.      * @return string The provider secret
  54.      */
  55.     public function getProviderKey()
  56.     {
  57.         return $this->providerKey;
  58.     }
  59.     /**
  60.      * Returns the secret.
  61.      *
  62.      * @return string
  63.      */
  64.     public function getSecret()
  65.     {
  66.         return $this->secret;
  67.     }
  68.     /**
  69.      * {@inheritdoc}
  70.      */
  71.     public function getCredentials()
  72.     {
  73.         return '';
  74.     }
  75.     /**
  76.      * {@inheritdoc}
  77.      */
  78.     public function __serialize(): array
  79.     {
  80.         return [$this->secret$this->providerKeyparent::__serialize()];
  81.     }
  82.     /**
  83.      * {@inheritdoc}
  84.      */
  85.     public function __unserialize(array $data): void
  86.     {
  87.         [$this->secret$this->providerKey$parentData] = $data;
  88.         $parentData = \is_array($parentData) ? $parentData unserialize($parentData);
  89.         parent::__unserialize($parentData);
  90.     }
  91. }