Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.0 Proposal #347

Draft
wants to merge 26 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
4402c8d
Bump PHP and Symfony requirements
mbabker Apr 21, 2022
d081b66
Remove deprecated document/entity classes
mbabker Apr 21, 2022
5aeee49
Removed deprecated RefreshTokenManagerInterface::create()
mbabker Apr 21, 2022
50f971b
Removed classes supporting authentication for Symfony 5.3 and earlier
mbabker Apr 21, 2022
12b0b2b
Remove deprecated RefreshTokenManager class
mbabker Apr 21, 2022
e032f1f
Removed deprecated configuration nodes
mbabker Apr 21, 2022
83c6c02
Use the AsCommand attribute to configure console commands
mbabker Apr 21, 2022
e85bd21
Remove token auto-generation from AbstractRefreshToken::setRefreshTok…
mbabker Apr 21, 2022
10da341
Remove compatibility code for older PHP and Symfony versions
mbabker Apr 21, 2022
7d12962
Use the check_path configuration when determining if the authenticato…
mbabker Apr 21, 2022
9f31da0
Require the refresh_token_class config node to be set
mbabker Apr 21, 2022
58eaffe
Remove more compatibility code
mbabker Apr 21, 2022
3e0d557
Inline ObjectManagerCompilerPass into the container extension
mbabker Apr 21, 2022
bf2379c
Remove manager_type config node, use feature detection when object_ma…
mbabker Apr 21, 2022
f546dc0
Register logout event through the security factory
mbabker Apr 21, 2022
e446fac
Remove unused code
mbabker Apr 21, 2022
c7304fe
Standardize container ID prefixes
mbabker Apr 21, 2022
f91e4b0
Bump dependency ranges
mbabker Apr 21, 2022
185a24d
Use attributes for fixtures
mbabker Apr 21, 2022
4edbe7c
Add final keyword to classes which shouldn't be extended
mbabker May 8, 2022
1119e8b
Add typehints everywhere
mbabker May 8, 2022
fe36216
The ODM returns an iterable object, change the typehint accordingly
mbabker May 8, 2022
b319a16
Update alias
mbabker Nov 23, 2022
ae532c4
Style fixes
mbabker Dec 1, 2022
e281230
Drop Symfony 6.0-6.3
mbabker Jul 24, 2023
031a9c2
Drop configuration documentation for Symfony <5.4
GwendolenLynch Jul 25, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 4 additions & 30 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,18 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['7.4', '8.0', '8.1', '8.2']
symfony: ['4.4.*', '5.4.*', '6.0.*', '6.1.*', '6.2.*', '6.3.*', '6.4.*', '7.0.*']
php: ['8.1', '8.2']
symfony: ['5.4.*', '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.*'
- php: '8.1'
symfony: '5.4.*'
composer-flags: '--prefer-stable --prefer-lowest'
can-fail: false
extensions: 'curl, iconv, mbstring, mongodb, pdo, pdo_sqlite, sqlite, zip'
exclude:
- php: '7.4'
symfony: '6.0.*'
- php: '7.4'
symfony: '6.1.*'
- php: '7.4'
symfony: '6.2.*'
- php: '7.4'
symfony: '6.3.*'
- php: '7.4'
symfony: '6.4.*'
- php: '7.4'
symfony: '7.0.*'
- php: '8.0'
symfony: '6.1.*'
- php: '8.0'
symfony: '6.2.*'
- php: '8.0'
symfony: '6.3.*'
- php: '8.0'
symfony: '6.4.*'
- php: '8.0'
symfony: '7.0.*'
- php: '8.1'
symfony: '7.0.*'

Expand Down Expand Up @@ -73,10 +51,6 @@ jobs:
version: '5.0'
topology: server

- name: Remove Guard (Symfony >=6.0)
if: contains(fromJSON('["6.0.*", "6.1.*", "6.2.*", "6.3.*", "6.4.*", "7.0.*"]'), matrix.symfony)
run: composer remove --dev --no-update symfony/security-guard

- name: Install dependencies
run: composer update ${{ matrix.composer-flags }} --prefer-dist --no-suggest
env:
Expand Down
20 changes: 3 additions & 17 deletions Command/ClearInvalidRefreshTokensCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,8 @@
use Symfony\Component\Console\Style\SymfonyStyle;

#[AsCommand(name: 'gesdinet:jwt:clear', description: 'Clear invalid refresh tokens.')]
class ClearInvalidRefreshTokensCommand extends Command
final class ClearInvalidRefreshTokensCommand extends Command
{
/**
* @deprecated
*/
protected static $defaultName = 'gesdinet:jwt:clear';

private RefreshTokenManagerInterface $refreshTokenManager;

public function __construct(RefreshTokenManagerInterface $refreshTokenManager)
Expand All @@ -39,23 +34,14 @@ public function __construct(RefreshTokenManagerInterface $refreshTokenManager)

protected function configure(): void
{
$this
->setDescription('Clear invalid refresh tokens.')
->addArgument('datetime', InputArgument::OPTIONAL, 'An optional date, all tokens before this date will be removed; the value should be able to be parsed by DateTime.');
$this->addArgument('datetime', InputArgument::OPTIONAL, 'An optional date, all tokens before this date will be removed; the value should be able to be parsed by DateTime.', 'now');
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);

/** @var string|null $datetime */
$datetime = $input->getArgument('datetime');

if (null === $datetime) {
$datetime = new \DateTime();
} else {
$datetime = new \DateTime($datetime);
}
$datetime = new \DateTime($input->getArgument('datetime'));

$revokedTokens = $this->refreshTokenManager->revokeAllInvalid($datetime);

Expand Down
13 changes: 3 additions & 10 deletions Command/RevokeRefreshTokenCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,9 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

#[AsCommand(name: 'gesdinet:jwt:revoke', description: 'Revoke a refresh token')]
class RevokeRefreshTokenCommand extends Command
#[AsCommand(name: 'gesdinet:jwt:revoke', description: 'Revoke a refresh token.')]
final class RevokeRefreshTokenCommand extends Command
{
/**
* @deprecated
*/
protected static $defaultName = 'gesdinet:jwt:revoke';

private RefreshTokenManagerInterface $refreshTokenManager;

public function __construct(RefreshTokenManagerInterface $refreshTokenManager)
Expand All @@ -38,9 +33,7 @@ public function __construct(RefreshTokenManagerInterface $refreshTokenManager)

protected function configure(): void
{
$this
->setDescription('Revoke a refresh token')
->addArgument('refresh_token', InputArgument::REQUIRED, 'The refresh token to revoke');
$this->addArgument('refresh_token', InputArgument::REQUIRED, 'The refresh token to revoke');
}

protected function execute(InputInterface $input, OutputInterface $output): int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ final class AddExtractorsToChainCompilerPass implements CompilerPassInterface

public function process(ContainerBuilder $container): void
{
if (!$container->hasDefinition('gesdinet.jwtrefreshtoken.request.extractor.chain')) {
if (!$container->hasDefinition('gesdinet_jwt_refresh_token.request.extractor.chain')) {
return;
}

$definition = $container->getDefinition('gesdinet.jwtrefreshtoken.request.extractor.chain');
$definition = $container->getDefinition('gesdinet_jwt_refresh_token.request.extractor.chain');

foreach ($this->findAndSortTaggedServices('gesdinet_jwt_refresh_token.request_extractor', $container) as $extractorService) {
$definition->addMethodCall('addExtractor', [$extractorService]);
Expand Down
47 changes: 0 additions & 47 deletions DependencyInjection/Compiler/CustomUserProviderCompilerPass.php

This file was deleted.

20 changes: 0 additions & 20 deletions DependencyInjection/Compiler/ObjectManagerCompilerPass.php

This file was deleted.

37 changes: 0 additions & 37 deletions DependencyInjection/Compiler/UserCheckerCompilerPass.php

This file was deleted.

64 changes: 7 additions & 57 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@

namespace Gesdinet\JWTRefreshTokenBundle\DependencyInjection;

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

class Configuration implements ConfigurationInterface
final class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder(): TreeBuilder
{
Expand All @@ -33,54 +32,23 @@ public function getConfigTreeBuilder(): TreeBuilder
->defaultFalse()
->info('The default update TTL flag for all authenticators.')
->end()
->scalarNode('firewall')
->setDeprecated(...$this->getDeprecationParameters('The "%node%" node is deprecated without replacement.', '1.0'))
->defaultValue('api')
->end()
->scalarNode('user_provider')
->setDeprecated(...$this->getDeprecationParameters('The "%node%" node is deprecated without replacement.', '1.0'))
->defaultNull()
->end()
->scalarNode('user_identity_field')
->setDeprecated(...$this->getDeprecationParameters('The "%node%" node is deprecated without replacement.', '1.0'))
->defaultValue('username')
->end()
->scalarNode('manager_type')
->defaultValue('orm')
->info('Set the type of object manager to use (default: orm)')
->end()
->scalarNode('refresh_token_class')
->defaultNull()
->info(sprintf('Set the refresh token class to use (default: %s)', RefreshToken::class))
->isRequired()
->cannotBeEmpty()
->info('Set the refresh token class to use')
->validate()
->ifTrue(static fn ($v): bool => null === $v)
->then(static function () {
trigger_deprecation(
'gesdinet/jwt-refresh-token-bundle',
'1.1',
'Not setting the "refresh_token_class" option is deprecated, as of 2.0 a class must be set.'
);
})
->ifTrue(static fn ($v): bool => null === $v || !\in_array(RefreshTokenInterface::class, class_implements($v), true))
->thenInvalid(sprintf('The "refresh_token_class" class must implement "%s".', RefreshTokenInterface::class))
->end()
->end()
->scalarNode('object_manager')
->defaultNull()
->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'))
->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'))
->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'))
->defaultNull()
->info('Set the entity manager to use')
->end()
->scalarNode('single_use')
->defaultFalse()
->info('When true, generate a new refresh token on consumption (deleting the old one)')
Expand All @@ -89,11 +57,6 @@ public function getConfigTreeBuilder(): TreeBuilder
->defaultValue('refresh_token')
->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'))
->info('When true, resolving of Doctrine mapping is done automatically to use either ORM or ODM object manager')
->defaultTrue()
->end()
->arrayNode('cookie')
->canBeEnabled()
->children()
Expand All @@ -109,10 +72,6 @@ public function getConfigTreeBuilder(): TreeBuilder
->scalarNode('remove_token_from_body')->defaultTrue()->end()
->end()
->end()
->scalarNode('logout_firewall')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should depreciate it before we delete it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, thanks for the reminder here. There are definitely a few things that could use a proper deprecation in a 1.x release that I'm now forgetting about since I've been sitting on this branch for so long 😬

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#350 for compat layer

->defaultValue('api')
->info('Name of the firewall that triggers the logout event to hook into (default: api)')
->end()
->scalarNode('return_expiration')
->defaultFalse()
->info('When true, the response will include the token expiration timestamp')
Expand All @@ -125,13 +84,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];
}
}
Loading