PHP code example of dimkinthepro / jwt-auth-bundle
1. Go to this page and download the library: Download dimkinthepro/jwt-auth-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/ */
use Dimkinthepro\JwtAuth\Application\Component\Event\JwtTokenCreatedEvent;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
#[AsEventListener]
class UserRolesClaimsListener
{
public function __invoke(JwtTokenCreatedEvent $event): void
{
$event->setClaims($event->getClaims() + ['role' => 'admin']);
}
}
use Dimkinthepro\JwtAuth\Infrastructure\Event\JwtAuthenticationSuccessEvent;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
#[AsEventListener]
class EnrichLoginResponseListener
{
public function __invoke(JwtAuthenticationSuccessEvent $event): void
{
$event->setData($event->getData() + ['userEmail' => $event->getUser()->getUserIdentifier()]);
}
}