welcome back to dyb-tech
This commit is contained in:
+53
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Lexik\Bundle\JWTAuthenticationBundle\DependencyInjection\Security\Factory;
|
||||
|
||||
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\AuthenticatorFactoryInterface;
|
||||
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SecurityFactoryInterface;
|
||||
use Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension;
|
||||
|
||||
if (interface_exists(SecurityFactoryInterface::class) && !interface_exists(AuthenticatorFactoryInterface::class)) {
|
||||
eval('
|
||||
namespace Lexik\Bundle\JWTAuthenticationBundle\DependencyInjection\Security\Factory;
|
||||
|
||||
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\AuthenticatorFactoryInterface;
|
||||
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SecurityFactoryInterface;
|
||||
|
||||
/**
|
||||
* Wires the "jwt" authenticator from user configuration.
|
||||
*
|
||||
* @author Robin Chalas <robin.chalas@gmail.com>
|
||||
*/
|
||||
class JWTAuthenticatorFactory implements SecurityFactoryInterface
|
||||
{
|
||||
use JWTAuthenticatorFactoryTrait;
|
||||
}
|
||||
');
|
||||
} elseif (!method_exists(SecurityExtension::class, 'addAuthenticatorFactory')) {
|
||||
eval('
|
||||
namespace Lexik\Bundle\JWTAuthenticationBundle\DependencyInjection\Security\Factory;
|
||||
|
||||
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\AuthenticatorFactoryInterface;
|
||||
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SecurityFactoryInterface;
|
||||
|
||||
/**
|
||||
* Wires the "jwt" authenticator from user configuration.
|
||||
*
|
||||
* @author Robin Chalas <robin.chalas@gmail.com>
|
||||
*/
|
||||
class JWTAuthenticatorFactory implements AuthenticatorFactoryInterface, SecurityFactoryInterface
|
||||
{
|
||||
use JWTAuthenticatorFactoryTrait;
|
||||
}
|
||||
');
|
||||
} else {
|
||||
/**
|
||||
* Wires the "jwt" authenticator from user configuration.
|
||||
*
|
||||
* @author Robin Chalas <robin.chalas@gmail.com>
|
||||
*/
|
||||
class JWTAuthenticatorFactory implements AuthenticatorFactoryInterface
|
||||
{
|
||||
use JWTAuthenticatorFactoryTrait;
|
||||
}
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace Lexik\Bundle\JWTAuthenticationBundle\DependencyInjection\Security\Factory;
|
||||
|
||||
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
|
||||
use Symfony\Component\DependencyInjection\ChildDefinition;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
* Wires the "jwt" authenticator from user configuration.
|
||||
*
|
||||
* @author Robin Chalas <robin.chalas@gmail.com>
|
||||
*/
|
||||
trait JWTAuthenticatorFactoryTrait
|
||||
{
|
||||
/**
|
||||
* @throws \LogicException
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function create(ContainerBuilder $container, $id, $config, $userProvider, $defaultEntryPoint)
|
||||
{
|
||||
throw new \LogicException('This method is implemented for BC purpose and should never be called.');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPriority(): int
|
||||
{
|
||||
return -10;
|
||||
}
|
||||
|
||||
public function getPosition(): string
|
||||
{
|
||||
return 'pre_auth';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getKey(): string
|
||||
{
|
||||
return 'jwt';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addConfiguration(NodeDefinition $node): void
|
||||
{
|
||||
$node
|
||||
->children()
|
||||
->scalarNode('provider')
|
||||
->defaultNull()
|
||||
->end()
|
||||
->scalarNode('authenticator')
|
||||
->defaultValue('lexik_jwt_authentication.security.jwt_authenticator')
|
||||
->end()
|
||||
->end()
|
||||
;
|
||||
}
|
||||
|
||||
public function createAuthenticator(ContainerBuilder $container, string $firewallName, array $config, string $userProviderId): string
|
||||
{
|
||||
$authenticatorId = 'security.authenticator.jwt.' . $firewallName;
|
||||
|
||||
$userProviderId = empty($config['provider']) ? $userProviderId : 'security.user.provider.concrete.' . $config['provider'];
|
||||
|
||||
$container
|
||||
->setDefinition($authenticatorId, new ChildDefinition($config['authenticator']))
|
||||
->replaceArgument(3, new Reference($userProviderId))
|
||||
;
|
||||
|
||||
// Compile-time parameter removed by RemoveLegacyAuthenticatorPass
|
||||
// Stop setting it when guard support gets removed (aka when removing Symfony<5.3 support)
|
||||
$container->setParameter('lexik_jwt_authentication.authenticator_manager_enabled', true);
|
||||
|
||||
return $authenticatorId;
|
||||
}
|
||||
}
|
||||
+182
@@ -0,0 +1,182 @@
|
||||
<?php
|
||||
|
||||
namespace Lexik\Bundle\JWTAuthenticationBundle\DependencyInjection\Security\Factory;
|
||||
|
||||
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SecurityFactoryInterface;
|
||||
use Symfony\Component\Config\Definition\BaseNode;
|
||||
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
|
||||
use Symfony\Component\DependencyInjection\ChildDefinition;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
* JWTFactory.
|
||||
*
|
||||
* @deprecated since 2.0, use the "lexik_jwt_authentication.jwt_token_authenticator" Guard
|
||||
* authenticator instead
|
||||
*
|
||||
* @author Nicolas Cabot <n.cabot@lexik.fr>
|
||||
*/
|
||||
class JWTFactory implements SecurityFactoryInterface
|
||||
{
|
||||
public function __construct($triggerDeprecation = true)
|
||||
{
|
||||
if ($triggerDeprecation) {
|
||||
trigger_deprecation('lexik/jwt-authentication-bundle', '2.0', 'Class "%s" is deprecated, use "%s" instead.', self::class, JWTAuthenticatorFactory::class);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function create(ContainerBuilder $container, $id, $config, $userProvider, $defaultEntryPoint)
|
||||
{
|
||||
$providerId = 'security.authentication.provider.jwt.' . $id;
|
||||
$container
|
||||
->setDefinition($providerId, new ChildDefinition($config['authentication_provider']))
|
||||
->replaceArgument(0, new Reference($userProvider));
|
||||
|
||||
$listenerId = 'security.authentication.listener.jwt.' . $id;
|
||||
$container
|
||||
->setDefinition($listenerId, new ChildDefinition($config['authentication_listener']))
|
||||
->replaceArgument(2, $config);
|
||||
|
||||
$entryPointId = $defaultEntryPoint;
|
||||
|
||||
if ($config['create_entry_point']) {
|
||||
$entryPointId = $this->createEntryPoint($container, $id, $defaultEntryPoint);
|
||||
}
|
||||
|
||||
if ($config['authorization_header']['enabled']) {
|
||||
$authorizationHeaderExtractorId = 'lexik_jwt_authentication.extractor.authorization_header_extractor.' . $id;
|
||||
$container
|
||||
->setDefinition($authorizationHeaderExtractorId, new ChildDefinition('lexik_jwt_authentication.extractor.authorization_header_extractor'))
|
||||
->replaceArgument(0, $config['authorization_header']['prefix'])
|
||||
->replaceArgument(1, $config['authorization_header']['name']);
|
||||
|
||||
$container
|
||||
->getDefinition($listenerId)
|
||||
->addMethodCall('addTokenExtractor', [new Reference($authorizationHeaderExtractorId)]);
|
||||
}
|
||||
|
||||
if ($config['query_parameter']['enabled']) {
|
||||
$queryParameterExtractorId = 'lexik_jwt_authentication.extractor.query_parameter_extractor.' . $id;
|
||||
$container
|
||||
->setDefinition($queryParameterExtractorId, new ChildDefinition('lexik_jwt_authentication.extractor.query_parameter_extractor'))
|
||||
->replaceArgument(0, $config['query_parameter']['name']);
|
||||
|
||||
$container
|
||||
->getDefinition($listenerId)
|
||||
->addMethodCall('addTokenExtractor', [new Reference($queryParameterExtractorId)]);
|
||||
}
|
||||
|
||||
if ($config['cookie']['enabled']) {
|
||||
$cookieExtractorId = 'lexik_jwt_authentication.extractor.cookie_extractor.' . $id;
|
||||
$container
|
||||
->setDefinition($cookieExtractorId, new ChildDefinition('lexik_jwt_authentication.extractor.cookie_extractor'))
|
||||
->replaceArgument(0, $config['cookie']['name']);
|
||||
|
||||
$container
|
||||
->getDefinition($listenerId)
|
||||
->addMethodCall('addTokenExtractor', [new Reference($cookieExtractorId)]);
|
||||
}
|
||||
|
||||
return [$providerId, $listenerId, $entryPointId];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPosition()
|
||||
{
|
||||
return 'pre_auth';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getKey()
|
||||
{
|
||||
return 'lexik_jwt';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addConfiguration(NodeDefinition $node)
|
||||
{
|
||||
$deprecationArgs = ['The "%path%.%node%" configuration key is deprecated. Use the "lexik_jwt_authentication.jwt_token_authenticator" Guard authenticator instead.'];
|
||||
if (method_exists(BaseNode::class, 'getDeprecation')) {
|
||||
$deprecationArgs = ['lexik/jwt-authentication-bundle', '2.7', 'The "%path%.%node%" configuration key is deprecated. Use the "lexik_jwt_authentication.jwt_token_authenticator" Guard authenticator instead.'];
|
||||
}
|
||||
|
||||
$node
|
||||
->setDeprecated(...$deprecationArgs)
|
||||
->children()
|
||||
->arrayNode('authorization_header')
|
||||
->addDefaultsIfNotSet()
|
||||
->canBeDisabled()
|
||||
->children()
|
||||
->scalarNode('prefix')
|
||||
->defaultValue('Bearer')
|
||||
->end()
|
||||
->scalarNode('name')
|
||||
->defaultValue('Authorization')
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->arrayNode('cookie')
|
||||
->addDefaultsIfNotSet()
|
||||
->canBeEnabled()
|
||||
->children()
|
||||
->scalarNode('name')
|
||||
->defaultValue('BEARER')
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->arrayNode('query_parameter')
|
||||
->canBeEnabled()
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->scalarNode('name')
|
||||
->defaultValue('bearer')
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->booleanNode('throw_exceptions')
|
||||
->defaultFalse()
|
||||
->end()
|
||||
->booleanNode('create_entry_point')
|
||||
->defaultTrue()
|
||||
->end()
|
||||
->scalarNode('authentication_provider')
|
||||
->defaultValue('lexik_jwt_authentication.security.authentication.provider')
|
||||
->end()
|
||||
->scalarNode('authentication_listener')
|
||||
->defaultValue('lexik_jwt_authentication.security.authentication.listener')
|
||||
->end()
|
||||
->end();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an entry point, by default it sends a 401 header and ends the request.
|
||||
*
|
||||
* @param string $id
|
||||
* @param mixed $defaultEntryPoint
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function createEntryPoint(ContainerBuilder $container, $id, $defaultEntryPoint)
|
||||
{
|
||||
$entryPointId = 'lexik_jwt_authentication.security.authentication.entry_point.' . $id;
|
||||
$container->setDefinition($entryPointId, new ChildDefinition('lexik_jwt_authentication.security.authentication.entry_point'));
|
||||
|
||||
return $entryPointId;
|
||||
}
|
||||
}
|
||||
Vendored
+49
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Lexik\Bundle\JWTAuthenticationBundle\DependencyInjection\Security\Factory;
|
||||
|
||||
use Lexik\Bundle\JWTAuthenticationBundle\Security\User\JWTUser;
|
||||
use Lexik\Bundle\JWTAuthenticationBundle\Security\User\JWTUserInterface;
|
||||
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\UserProvider\UserProviderFactoryInterface;
|
||||
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
|
||||
use Symfony\Component\DependencyInjection\ChildDefinition;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
|
||||
/**
|
||||
* Creates the `lexik_jwt` user provider.
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @author Robin Chalas <robin.chalas@gmail.com>
|
||||
*/
|
||||
final class JWTUserFactory implements UserProviderFactoryInterface
|
||||
{
|
||||
public function create(ContainerBuilder $container, $id, $config): void
|
||||
{
|
||||
$container->setDefinition($id, new ChildDefinition('lexik_jwt_authentication.security.jwt_user_provider'))
|
||||
->replaceArgument(0, $config['class']);
|
||||
}
|
||||
|
||||
public function getKey(): string
|
||||
{
|
||||
return 'lexik_jwt';
|
||||
}
|
||||
|
||||
public function addConfiguration(NodeDefinition $node): void
|
||||
{
|
||||
$node
|
||||
->children()
|
||||
->scalarNode('class')
|
||||
->cannotBeEmpty()
|
||||
->defaultValue(JWTUser::class)
|
||||
->validate()
|
||||
->ifTrue(function ($class) {
|
||||
return !(new \ReflectionClass($class))->implementsInterface(JWTUserInterface::class);
|
||||
})
|
||||
->thenInvalid('The %s class must implement ' . JWTUserInterface::class . ' for using the "lexik_jwt" user provider.')
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user