/**
  * @param UserProviderInterface $userProvider
  * @param Token                 $token
  *
  * @throws AuthenticationException
  * @throws AuthenticationServiceException
  *
  * @return UserInterface
  */
 protected function retrieveUser(UserProviderInterface $userProvider, Token $token)
 {
     $parts = $this->tokenManager->getEncoder()->decodeHash($token->getHash());
     if (count($parts) !== 4) {
         throw new AuthenticationException('The hash is invalid.');
     }
     list($class, $username, $expires, $hash) = $parts;
     if (false === ($username = base64_decode($username, true))) {
         throw new AuthenticationException('$username contains a character from outside the base64 alphabet.');
     }
     try {
         $user = $userProvider->loadUserByUsername($username);
     } catch (\Exception $e) {
         throw new AuthenticationServiceException($e->getMessage(), 0, $e);
     }
     if (!$user instanceof UserInterface) {
         throw new AuthenticationServiceException('The user provider must return a UserInterface object.');
     }
     return $user;
 }
 /**
  * @test
  */
 public function it_can_check_for_expired_tokens()
 {
     $this->assertFalse($this->manager->isExpired((new Token())->setExpiresAt(new \DateTime('10 seconds'))));
     $this->assertTrue($this->manager->isExpired((new Token())->setExpiresAt(new \DateTime('-10 seconds'))));
 }