vendor/lexik/jwt-authentication-bundle/Security/User/JWTUserProvider.php line 51

Open in your IDE?
  1. <?php
  2. namespace Lexik\Bundle\JWTAuthenticationBundle\Security\User;
  3. use Symfony\Component\Security\Core\User\UserInterface;
  4. /**
  5.  * JWT User provider.
  6.  *
  7.  * @author Robin Chalas <robin.chalas@gmail.com>
  8.  */
  9. final class JWTUserProvider implements PayloadAwareUserProviderInterface
  10. {
  11.     private $class;
  12.     private $cache = [];
  13.     /**
  14.      * @param string $class The {@link JWTUserInterface} implementation FQCN for which to provide instances
  15.      */
  16.     public function __construct($class)
  17.     {
  18.         $this->class $class;
  19.     }
  20.     /**
  21.      * {@inheritdoc}
  22.      *
  23.      * @param array $payload The JWT payload from which to create an instance
  24.      *
  25.      * @return UserInterface
  26.      */
  27.     public function loadUserByUsername($username, array $payload = [])
  28.     {
  29.         return $this->loadUserByUsernameAndPayload($username$payload);
  30.     }
  31.     /**
  32.      * {@inheritdoc}
  33.      *
  34.      * @param array $payload The JWT payload from which to create an instance
  35.      */
  36.     public function loadUserByIdentifier(string $identifier, array $payload = []): UserInterface
  37.     {
  38.         return $this->loadUserByIdentifierAndPayload($identifier$payload);
  39.     }
  40.     /**
  41.      * {@inheritdoc}
  42.      */
  43.     public function loadUserByUsernameAndPayload(string $username, array $payload): UserInterface
  44.     {
  45.         if (isset($this->cache[$username])) {
  46.             return $this->cache[$username];
  47.         }
  48.         $class $this->class;
  49.         return $this->cache[$username] = $class::createFromPayload($username$payload);
  50.     }
  51.     public function loadUserByIdentifierAndPayload(string $userIdentifier, array $payload): UserInterface
  52.     {
  53.         if (isset($this->cache[$userIdentifier])) {
  54.             return $this->cache[$userIdentifier];
  55.         }
  56.         $class $this->class;
  57.         return $this->cache[$userIdentifier] = $class::createFromPayload($userIdentifier$payload);
  58.     }
  59.     /**
  60.      * {@inheritdoc}
  61.      */
  62.     public function supportsClass($class): bool
  63.     {
  64.         return $class === $this->class || (new \ReflectionClass($class))->implementsInterface(JWTUserInterface::class);
  65.     }
  66.     public function refreshUser(UserInterface $user): UserInterface
  67.     {
  68.         return $user// noop
  69.     }
  70. }