PHP code example of mrellerm / jwt-refresh-token-bundle
1. Go to this page and download the library: Download mrellerm/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' );
mrellerm / jwt-refresh-token-bundle example snippets
class AppKernel extends Kernel
{
public function registerBundles ()
{
$bundles = array (
new Gesdinet\JWTRefreshTokenBundle\GesdinetJWTRefreshTokenBundle(),
);
}
}
return [
Gesdinet\JWTRefreshTokenBundle\GesdinetJWTRefreshTokenBundle::class => ['all' => true ],
];
namespace MyBundle ;
use Doctrine \ORM \Mapping as ORM ;
use Gesdinet \JWTRefreshTokenBundle \Entity \AbstractRefreshToken ;
class JwtRefreshToken extends AbstractRefreshToken
{
protected $id;
public function getId ()
{
return $this ->id;
}
}
namespace MyBundle ;
use Doctrine \ODM \MongoDB \Mapping \Annotations as MongoDB ;
use Gesdinet \JWTRefreshTokenBundle \Document \AbstractRefreshToken ;
class JwtRefreshToken extends AbstractRefreshToken
{
protected $id;
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' ,
);
}
}
bash
php bin/console gesdinet:jwt:clear
bash
php bin/console gesdinet:jwt:clear
bash
php bin/console gesdinet:jwt:clear 2015 -08 -08
bash
php bin/console gesdinet:jwt:clear 2015 -08 -08