PHP code example of meuhmeuhconcept / security-bundle
1. Go to this page and download the library: Download meuhmeuhconcept/security-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/ */
meuhmeuhconcept / security-bundle example snippets
...
use Mmc\Security\DependencyInjection\Security\Factory\MmcLoginFactory;
...
public function build(ContainerBuilder $container)
{
$extension = $container->getExtension('security');
$extension->addSecurityListenerFactory(new MmcLoginFactory());
}
...
namespace App\Security;
use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTCreatedEvent;
use Mmc\Security\Authentication\Token\MmcToken;
use Mmc\Security\Service\SessionTTLProvider;
use Mmc\Security\User\UserInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
class JWTCreatedListener
{
protected $tokenStorage;
protected $sessionTTLProvider;
public function __construct(
TokenStorageInterface $tokenStorage,
SessionTTLProvider $sessionTTLProvider
) {
$this->tokenStorage = $tokenStorage;
$this->sessionTTLProvider = $sessionTTLProvider;
}
public function onJWTCreated(JWTCreatedEvent $event)
{
$token = $this->tokenStorage->getToken();
if (!$token || !$token instanceof MmcToken) {
return;
}
$user = $token->getUser();
if (!$user || !$user instanceof UserInterface) {
return;
}
$ttl = $this->sessionTTLProvider->getSessionTTL($token->getType());
if ($token->hasExtra('rememberMe') && $token->getExtra('rememberMe')) {
$ttl = 2678400; // 60 * 60 * 24 * 31
}
$payload = $event->getData();
$payload['exp'] = time() + $ttl;
$payload['authType'] = $user->getType();
//$payload['name'] = $user->getName();
//$payload['firstname'] = $user->getFirstname();
$event->setData($payload);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.