Skip to content

Commit

Permalink
Merge branch 'master' into feat/import-namespaces-class
Browse files Browse the repository at this point in the history
  • Loading branch information
shakaran authored Jan 6, 2025
2 parents 8aa2dc3 + a47a373 commit c97ba53
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 120 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ jobs:
fail-fast: false
matrix:
php: ['7.4', '8.0', '8.1', '8.2', '8.3']
symfony: ['4.4.*', '5.4.*', '6.0.*', '6.1.*', '6.2.*', '6.3.*', '6.4.*', '7.0.*']
symfony: ['5.4.*', '6.0.*', '6.1.*', '6.2.*', '6.3.*', '6.4.*', '7.0.*']
composer-flags: ['--prefer-stable']
can-fail: [false]
extensions: ['curl, iconv, mbstring, mongodb, pdo, pdo_sqlite, sqlite, zip']
include:
- php: '7.4'
symfony: '4.4.*'
symfony: '5.4.*'
composer-flags: '--prefer-stable --prefer-lowest'
can-fail: false
extensions: 'curl, iconv, mbstring, mongodb, pdo, pdo_sqlite, sqlite, zip'
Expand Down
24 changes: 7 additions & 17 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Gesdinet\JWTRefreshTokenBundle\DependencyInjection;

use Gesdinet\JWTRefreshTokenBundle\Entity\RefreshToken;
use Symfony\Component\Config\Definition\BaseNode;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

Expand All @@ -34,15 +33,15 @@ public function getConfigTreeBuilder(): TreeBuilder
->info('The default update TTL flag for all authenticators.')
->end()
->scalarNode('firewall')
->setDeprecated(...$this->getDeprecationParameters('The "%node%" node is deprecated without replacement.', '1.0'))
->setDeprecated('gesdinet/jwt-refresh-token-bundle', '1.0', 'The "%node%" node is deprecated without replacement.')
->defaultValue('api')
->end()
->scalarNode('user_provider')
->setDeprecated(...$this->getDeprecationParameters('The "%node%" node is deprecated without replacement.', '1.0'))
->setDeprecated('gesdinet/jwt-refresh-token-bundle', '1.0', 'The "%node%" node is deprecated without replacement.')
->defaultNull()
->end()
->scalarNode('user_identity_field')
->setDeprecated(...$this->getDeprecationParameters('The "%node%" node is deprecated without replacement.', '1.0'))
->setDeprecated('gesdinet/jwt-refresh-token-bundle', '1.0', 'The "%node%" node is deprecated without replacement.')
->defaultValue('username')
->end()
->scalarNode('manager_type')
Expand All @@ -68,16 +67,16 @@ public function getConfigTreeBuilder(): TreeBuilder
->info('Set the object manager to use (default: doctrine.orm.entity_manager)')
->end()
->scalarNode('user_checker')
->setDeprecated(...$this->getDeprecationParameters('The "%node%" node is deprecated without replacement.', '1.0'))
->setDeprecated('gesdinet/jwt-refresh-token-bundle', '1.0', 'The "%node%" node is deprecated without replacement.')
->defaultValue('security.user_checker')
->end()
->scalarNode('refresh_token_entity')
->setDeprecated(...$this->getDeprecationParameters('The "%node%" node is deprecated, use the "refresh_token_class" node instead.', '0.5'))
->setDeprecated('gesdinet/jwt-refresh-token-bundle', '0.5', 'The "%node%" node is deprecated, use the "refresh_token_class" node instead.')
->defaultNull()
->info(sprintf('Set the refresh token class to use (default: %s)', RefreshToken::class))
->end()
->scalarNode('entity_manager')
->setDeprecated(...$this->getDeprecationParameters('The "%node%" node is deprecated, use the "object_manager" node instead.', '0.5'))
->setDeprecated('gesdinet/jwt-refresh-token-bundle', '0.5', 'The "%node%" node is deprecated, use the "object_manager" node instead.')
->defaultNull()
->info('Set the entity manager to use')
->end()
Expand All @@ -90,7 +89,7 @@ public function getConfigTreeBuilder(): TreeBuilder
->info('The default request parameter name containing the refresh token for all authenticators.')
->end()
->booleanNode('doctrine_mappings')
->setDeprecated(...$this->getDeprecationParameters('The "%node%" node is deprecated without replacement.', '1.0'))
->setDeprecated('gesdinet/jwt-refresh-token-bundle', '1.0', 'The "%node%" node is deprecated without replacement.')
->info('When true, resolving of Doctrine mapping is done automatically to use either ORM or ODM object manager')
->defaultTrue()
->end()
Expand Down Expand Up @@ -125,13 +124,4 @@ public function getConfigTreeBuilder(): TreeBuilder

return $treeBuilder;
}

private function getDeprecationParameters(string $message, string $version): array
{
if (method_exists(BaseNode::class, 'getDeprecation')) {
return ['gesdinet/jwt-refresh-token-bundle', $version, $message];
}

return [$message];
}
}
3 changes: 2 additions & 1 deletion DependencyInjection/GesdinetJWTRefreshTokenExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
use Gesdinet\JWTRefreshTokenBundle\Request\Extractor\ExtractorInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader;

class GesdinetJWTRefreshTokenExtension extends Extension
{
Expand Down
10 changes: 3 additions & 7 deletions GesdinetJWTRefreshTokenBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\Security\Http\RememberMe\RememberMeHandlerInterface;

class GesdinetJWTRefreshTokenBundle extends Bundle
{
Expand All @@ -23,11 +22,8 @@ public function build(ContainerBuilder $container): void
$container->addCompilerPass(new ObjectManagerCompilerPass());
$container->addCompilerPass(new UserCheckerCompilerPass(true));

// Only register the security authenticator for Symfony 5.4+
if (interface_exists(RememberMeHandlerInterface::class)) {
/** @var SecurityExtension $extension */
$extension = $container->getExtension('security');
$extension->addAuthenticatorFactory(new RefreshTokenAuthenticatorFactory());
}
/** @var SecurityExtension $extension */
$extension = $container->getExtension('security');
$extension->addAuthenticatorFactory(new RefreshTokenAuthenticatorFactory());
}
}
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The purpose of this bundle is manage refresh tokens with JWT (Json Web Tokens) i

## Prerequisites

This bundle requires PHP 7.4 or later and Symfony 4.4, 5.4, or 6.0+.
This bundle requires PHP 7.4 or later and Symfony 5.4 or later.

For support with older Symfony versions, please use the 0.12 release.

Expand All @@ -25,7 +25,7 @@ For support with older Symfony versions, please use the 0.12 release.

**You must also install either the Doctrine ORM or MongoDB ODM, these packages are not installed automatically with this bundle. Failing to do so may trigger errors on installation.**

If using Symfony 4.4, you will also need to install the `symfony/security-guard` package, it is only required for the legacy authentication API and is not compatible with Symfony 6.0.
If using Symfony 5.4 with the deprecated Guard authenticators, you will also need to install the `symfony/security-guard` package. Note that it is only required for the legacy authentication API and is not compatible with Symfony 6.0.

With Doctrine's ORM

Expand Down Expand Up @@ -177,7 +177,7 @@ security:
# ...
```

### Step 4 (Symfony 4.4)
### Step 4 (Symfony 5.4 with Guard Authentication)

#### Define the refresh token route

Expand Down Expand Up @@ -319,7 +319,7 @@ security:

By default, when a user provider is not specified, then the user provider for the firewall is used instead.

#### Symfony 4.4
#### Symfony 5.4 with Guard Authentication

*NOTE* This setting is deprecated and is not used with the `refresh_jwt` authenticator

Expand Down Expand Up @@ -365,7 +365,7 @@ security:
refresh_jwt: ~
```

#### Symfony 4.4
#### Symfony 5.4 with Guard Authentication

*NOTE* This setting is deprecated and is not used with the `refresh_jwt` authenticator

Expand Down
117 changes: 49 additions & 68 deletions Resources/config/services.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use function Symfony\Component\DependencyInjection\Loader\Configurator\abstract_arg;
namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Gesdinet\JWTRefreshTokenBundle\Command\ClearInvalidRefreshTokensCommand;
use Gesdinet\JWTRefreshTokenBundle\Command\RevokeRefreshTokenCommand;
use Gesdinet\JWTRefreshTokenBundle\Doctrine\RefreshTokenManager;
Expand All @@ -20,43 +21,23 @@
use Gesdinet\JWTRefreshTokenBundle\Security\Http\Authenticator\RefreshTokenAuthenticator;
use Gesdinet\JWTRefreshTokenBundle\Security\Provider\RefreshTokenProvider;
use Gesdinet\JWTRefreshTokenBundle\Service\RefreshToken;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\DependencyInjection\Parameter;
use Symfony\Component\DependencyInjection\Reference;

return static function (ContainerConfigurator $container) {
$deprecateArgs = static function (string $version, string $message = 'The "%service_id%" service is deprecated.'): array {
if (method_exists(Definition::class, 'getDeprecation')) {
return ['gesdinet/jwt-refresh-token-bundle', $version, $message];
}

return [$message];
};

$abstractArg = static function (string $description) {
if (function_exists('Symfony\Component\DependencyInjection\Loader\Configurator\abstract_arg')) {
return abstract_arg($description);
}

return null;
};

$services = $container->services();

$services->set('gesdinet.jwtrefreshtoken.send_token')
->class(AttachRefreshTokenOnSuccessListener::class)
->args([
new Reference('gesdinet.jwtrefreshtoken.refresh_token_manager'),
new Parameter('gesdinet_jwt_refresh_token.ttl'),
new Reference('request_stack'),
new Parameter('gesdinet_jwt_refresh_token.token_parameter_name'),
new Parameter('gesdinet_jwt_refresh_token.single_use'),
new Reference('gesdinet.jwtrefreshtoken.refresh_token_generator'),
new Reference('gesdinet.jwtrefreshtoken.request.extractor.chain'),
new Parameter('gesdinet_jwt_refresh_token.cookie'),
new Parameter('gesdinet_jwt_refresh_token.return_expiration'),
new Parameter('gesdinet_jwt_refresh_token.return_expiration_parameter_name'),
service('gesdinet.jwtrefreshtoken.refresh_token_manager'),
param('gesdinet_jwt_refresh_token.ttl'),
service('request_stack'),
param('gesdinet_jwt_refresh_token.token_parameter_name'),
param('gesdinet_jwt_refresh_token.single_use'),
service('gesdinet.jwtrefreshtoken.refresh_token_generator'),
service('gesdinet.jwtrefreshtoken.request.extractor.chain'),
param('gesdinet_jwt_refresh_token.cookie'),
param('gesdinet_jwt_refresh_token.return_expiration'),
param('gesdinet_jwt_refresh_token.return_expiration_parameter_name'),
])
->tag('kernel.event_listener', [
'event' => 'lexik_jwt_authentication.on_authentication_success',
Expand All @@ -67,7 +48,7 @@
->class(RefreshTokenGenerator::class)
->public()
->args([
new Reference('gesdinet.jwtrefreshtoken.refresh_token_manager'),
service('gesdinet.jwtrefreshtoken.refresh_token_manager'),
]);

$services->alias(RefreshTokenGeneratorInterface::class, 'gesdinet.jwtrefreshtoken.refresh_token_generator');
Expand All @@ -76,8 +57,8 @@
->class(RefreshTokenManager::class)
->public()
->args([
new Reference('gesdinet.jwtrefreshtoken.object_manager'),
new Parameter('gesdinet.jwtrefreshtoken.refresh_token.class'),
service('gesdinet.jwtrefreshtoken.object_manager'),
param('gesdinet.jwtrefreshtoken.refresh_token.class'),
]);

$services->alias(RefreshTokenManagerInterface::class, 'gesdinet.jwtrefreshtoken.refresh_token_manager');
Expand All @@ -101,83 +82,83 @@
->tag('gesdinet_jwt_refresh_token.request_extractor');

$services->set('gesdinet.jwtrefreshtoken')
->deprecate(...$deprecateArgs('1.0'))
->deprecate('gesdinet/jwt-refresh-token-bundle', '1.0', 'The "%service_id%" service is deprecated.')
->class(RefreshToken::class)
->public()
->args([
new Reference('gesdinet.jwtrefreshtoken.authenticator'),
new Reference('gesdinet.jwtrefreshtoken.user_provider'),
new Reference('lexik_jwt_authentication.handler.authentication_success'),
new Reference('lexik_jwt_authentication.handler.authentication_failure'),
new Reference('gesdinet.jwtrefreshtoken.refresh_token_manager'),
new Parameter('gesdinet_jwt_refresh_token.ttl'),
new Parameter('gesdinet_jwt_refresh_token.security.firewall'),
new Parameter('gesdinet_jwt_refresh_token.ttl_update'),
new Reference('event_dispatcher'),
service('gesdinet.jwtrefreshtoken.authenticator'),
service('gesdinet.jwtrefreshtoken.user_provider'),
service('lexik_jwt_authentication.handler.authentication_success'),
service('lexik_jwt_authentication.handler.authentication_failure'),
service('gesdinet.jwtrefreshtoken.refresh_token_manager'),
param('gesdinet_jwt_refresh_token.ttl'),
param('gesdinet_jwt_refresh_token.security.firewall'),
param('gesdinet_jwt_refresh_token.ttl_update'),
service('event_dispatcher'),
]);

$services->set('gesdinet.jwtrefreshtoken.user_provider')
->deprecate(...$deprecateArgs('1.0'))
->deprecate('gesdinet/jwt-refresh-token-bundle', '1.0', 'The "%service_id%" service is deprecated.')
->class(RefreshTokenProvider::class)
->args([
new Reference('gesdinet.jwtrefreshtoken.refresh_token_manager'),
service('gesdinet.jwtrefreshtoken.refresh_token_manager'),
]);

$services->set('gesdinet.jwtrefreshtoken.authenticator')
->deprecate(...$deprecateArgs('1.0'))
->deprecate('gesdinet/jwt-refresh-token-bundle', '1.0', 'The "%service_id%" service is deprecated.')
->class(LegacyRefreshTokenAuthenticator::class)
->args([
new Reference('gesdinet.jwtrefreshtoken.user_checker'),
new Parameter('gesdinet_jwt_refresh_token.token_parameter_name'),
new Reference('gesdinet.jwtrefreshtoken.request.extractor.chain'),
service('gesdinet.jwtrefreshtoken.user_checker'),
param('gesdinet_jwt_refresh_token.token_parameter_name'),
service('gesdinet.jwtrefreshtoken.request.extractor.chain'),
]);

$services->set('gesdinet.jwtrefreshtoken.security.authentication.failure_handler')
->class(AuthenticationFailureHandler::class)
->args([
new Reference('event_dispatcher'),
service('event_dispatcher'),
]);

$services->set('gesdinet.jwtrefreshtoken.security.authentication.success_handler')
->class(AuthenticationSuccessHandler::class)
->args([
new Reference('lexik_jwt_authentication.handler.authentication_success'),
new Reference('event_dispatcher'),
service('lexik_jwt_authentication.handler.authentication_success'),
service('event_dispatcher'),
]);

$services->set('gesdinet.jwtrefreshtoken.security.refresh_token_authenticator')
->abstract()
->class(RefreshTokenAuthenticator::class)
->args([
new Reference('gesdinet.jwtrefreshtoken.refresh_token_manager'),
new Reference('event_dispatcher'),
new Reference('gesdinet.jwtrefreshtoken.request.extractor.chain'),
$abstractArg('user provider'),
$abstractArg('authentication success handler'),
$abstractArg('authentication failure handler'),
$abstractArg('options'),
new Reference('security.http_utils'),
service('gesdinet.jwtrefreshtoken.refresh_token_manager'),
service('event_dispatcher'),
service('gesdinet.jwtrefreshtoken.request.extractor.chain'),
abstract_arg('user provider'),
abstract_arg('authentication success handler'),
abstract_arg('authentication failure handler'),
abstract_arg('options'),
service('security.http_utils'),
]);

$services->set(ClearInvalidRefreshTokensCommand::class)
->args([
new Reference('gesdinet.jwtrefreshtoken.refresh_token_manager'),
service('gesdinet.jwtrefreshtoken.refresh_token_manager'),
])
->tag('console.command');

$services->set(RevokeRefreshTokenCommand::class)
->args([
new Reference('gesdinet.jwtrefreshtoken.refresh_token_manager'),
service('gesdinet.jwtrefreshtoken.refresh_token_manager'),
])
->tag('console.command');

$services->set(LogoutEventListener::class)
->args([
new Reference('gesdinet.jwtrefreshtoken.refresh_token_manager'),
new Reference('gesdinet.jwtrefreshtoken.request.extractor.chain'),
new Parameter('gesdinet_jwt_refresh_token.token_parameter_name'),
new Parameter('gesdinet_jwt_refresh_token.cookie'),
new Parameter('gesdinet_jwt_refresh_token.logout_firewall_context'),
service('gesdinet.jwtrefreshtoken.refresh_token_manager'),
service('gesdinet.jwtrefreshtoken.request.extractor.chain'),
param('gesdinet_jwt_refresh_token.token_parameter_name'),
param('gesdinet_jwt_refresh_token.cookie'),
param('gesdinet_jwt_refresh_token.logout_firewall_context'),
])
->tag('kernel.event_listener', [
'event' => 'Symfony\Component\Security\Http\Event\LogoutEvent',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\Security\Http\RememberMe\RememberMeHandlerInterface;

final class RefreshTokenAuthenticatorFactoryTest extends TestCase
{
Expand All @@ -21,13 +20,6 @@ final class RefreshTokenAuthenticatorFactoryTest extends TestCase
*/
private $container;

public static function setUpBeforeClass(): void
{
if (!interface_exists(RememberMeHandlerInterface::class)) {
self::markTestSkipped('Only applies to Symfony 5.3+');
}
}

protected function setUp(): void
{
$this->factory = new RefreshTokenAuthenticatorFactory();
Expand Down
Loading

0 comments on commit c97ba53

Please sign in to comment.