1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the GesdinetJWTRefreshTokenBundle package. |
5
|
|
|
* |
6
|
|
|
* (c) Gesdinet <http://www.gesdinet.com/> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Gesdinet\JWTRefreshTokenBundle\Command; |
13
|
|
|
|
14
|
|
|
use Gesdinet\JWTRefreshTokenBundle\Doctrine\RefreshTokenManager; |
15
|
|
|
use Gesdinet\JWTRefreshTokenBundle\Model\RefreshTokenManagerInterface; |
16
|
|
|
use Symfony\Component\Console\Command\Command; |
17
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
18
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
19
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Class ClearInvalidRefreshTokensCommand. |
23
|
|
|
*/ |
24
|
|
|
class ClearInvalidRefreshTokensCommand extends Command |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
4 |
|
* @var RefreshTokenManager |
28
|
|
|
*/ |
29
|
4 |
|
private $refreshTokenManager; |
30
|
4 |
|
|
31
|
4 |
|
public function __construct(RefreshTokenManagerInterface $refreshTokenManager) |
32
|
4 |
|
{ |
33
|
4 |
|
parent::__construct(); |
34
|
4 |
|
$this->refreshTokenManager = $refreshTokenManager; |
|
|
|
|
35
|
4 |
|
} |
36
|
|
|
|
37
|
|
|
protected function configure(): void |
38
|
|
|
{ |
39
|
|
|
$this |
40
|
1 |
|
->setName('gesdinet:jwt:clear') |
41
|
|
|
->setDescription('Clear invalid refresh tokens.') |
42
|
1 |
|
->setDefinition( |
43
|
|
|
[ |
44
|
1 |
|
new InputArgument('datetime', InputArgument::OPTIONAL), |
45
|
1 |
|
] |
46
|
1 |
|
); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
50
|
1 |
|
{ |
51
|
1 |
|
$datetime = $input->getArgument('datetime'); |
52
|
|
|
|
53
|
1 |
|
if (null === $datetime) { |
54
|
1 |
|
$datetime = new \DateTime(); |
55
|
1 |
|
} else { |
56
|
1 |
|
$datetime = new \DateTime($datetime); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$revokedTokens = $this->refreshTokenManager->revokeAllInvalid($datetime); |
60
|
|
|
|
61
|
|
|
foreach ($revokedTokens as $revokedToken) { |
62
|
|
|
$output->writeln(sprintf('Revoke <comment>%s</comment>', $revokedToken->getRefreshToken())); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.