namespace MyBundle;
use Doctrine\ORM\Mapping as ORM;
use Gesdinet\JWTRefreshTokenBundle\Entity\AbstractRefreshToken;
/**
* This class override Gesdinet\JWTRefreshTokenBundle\Entity\RefreshToken to have another table name.
*
* @ORM\Table("jwt_refresh_token")
*/
class JwtRefreshToken extends AbstractRefreshToken
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* {@inheritdoc}
*/
public function getId()
{
return $this->id;
}
}
namespace MyBundle;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
use Gesdinet\JWTRefreshTokenBundle\Document\AbstractRefreshToken;
/**
* This class override Gesdinet\JWTRefreshTokenBundle\Document\RefreshToken to have another collection name.
*
* @MongoDB\Document(collection="UserRefreshToken")
*/
class JwtRefreshToken extends AbstractRefreshToken
{
/**
* @var string
*
* @MongoDB\Id(strategy="auto")
*/
protected $id;
/**
* {@inheritdoc}
*/
public function getId()
{
return $this->id;
}
}
namespace AppBundle\EventListener;
use Gesdinet\JWTRefreshTokenBundle\Event\RefreshEvent;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class LogListener implements EventSubscriberInterface
{
private $logger;
public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
}
public function log(RefreshEvent $event)
{
$refreshToken = $event->getRefreshToken()->getRefreshToken();
$user = $event->getPreAuthenticatedToken()->getUser()->getUsername();
$this->logger->debug(sprintf('User "%s" has refreshed it\'s JWT token with refresh token "%s".', $user, $refreshToken));
}
public static function getSubscribedEvents()
{
return array(
'gesdinet.refresh_token' => 'log',
);
}
}