PHP code example of terehinis / jwt-refresh-token-bundle
1. Go to this page and download the library: Download terehinis/jwt-refresh-token-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
terehinis / jwt-refresh-token-bundle example snippets
// app/AppKernel.php
// ...
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
// ...
new terehinis\JWTRefreshTokenBundle\terehinisJWTRefreshTokenBundle(),
);
}
// ...
}
namespace MyBundle;
use terehinis\JWTRefreshTokenBundle\Entity\AbstractRefreshToken;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Doctrine\ORM\Mapping as ORM;
/**
* This class override terehinis\JWTRefreshTokenBundle\Entity\RefreshToken to have another table name.
*
* @ORM\Table("jwt_refresh_token")
* @ORM\Entity(repositoryClass="terehinis\JWTRefreshTokenBundle\Entity\RefreshTokenRepository")
* @UniqueEntity("refreshToken")
*/
class JwtRefreshToken extends AbstractRefreshToken
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* {@inheritdoc}
*/
public function getId()
{
$this->id;
}
}
namespace AppBundle\EventListener;
use terehinis\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(
'terehinis.refresh_token' => 'log',
);
}
}