|
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\DependencyInjection; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
|
15
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* This is the class that validates and merges configuration from your app/config files. |
|
19
|
|
|
* |
|
20
|
|
|
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class} |
|
21
|
|
|
*/ |
|
22
|
|
|
class Configuration implements ConfigurationInterface |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* {@inheritdoc} |
|
26
|
|
|
*/ |
|
27
|
2 |
|
public function getConfigTreeBuilder() |
|
28
|
|
|
{ |
|
29
|
2 |
|
$treeBuilder = new TreeBuilder('gesdinet_jwt_refresh_token'); |
|
30
|
2 |
|
$rootNode = method_exists(TreeBuilder::class, 'getRootNode') ? $treeBuilder->getRootNode() : $treeBuilder->root('gesdinet_jwt_refresh_token'); |
|
31
|
|
|
|
|
32
|
|
|
$rootNode |
|
|
|
|
|
|
33
|
2 |
|
->children() |
|
34
|
2 |
|
->integerNode('ttl')->defaultValue(2592000)->end() |
|
35
|
2 |
|
->booleanNode('ttl_update')->defaultFalse()->end() |
|
36
|
2 |
|
->scalarNode('firewall')->defaultValue('api')->end() |
|
37
|
2 |
|
->scalarNode('user_provider')->defaultNull()->end() |
|
38
|
2 |
|
->scalarNode('user_identity_field')->defaultValue('username')->end() |
|
39
|
2 |
|
->scalarNode('manager_type') |
|
40
|
2 |
|
->defaultValue('orm') |
|
41
|
2 |
|
->info('Set manager mode instead of default one (orm)') |
|
42
|
2 |
|
->end() |
|
43
|
2 |
|
->scalarNode('refresh_token_class') |
|
44
|
2 |
|
->defaultNull() |
|
45
|
2 |
|
->info('Set another refresh token class to use instead of default one (Gesdinet\JWTRefreshTokenBundle\Entity\RefreshToken)') |
|
46
|
2 |
|
->end() |
|
47
|
|
|
->scalarNode('object_manager') |
|
48
|
2 |
|
->defaultNull() |
|
49
|
|
|
->info('Set object manager to use (default: doctrine.orm.entity_manager)') |
|
50
|
|
|
->end() |
|
51
|
|
|
->scalarNode('user_checker')->defaultValue('security.user_checker')->end() |
|
52
|
|
|
->scalarNode('refresh_token_entity') |
|
53
|
|
|
->defaultNull() |
|
54
|
|
|
->info('Deprecated, use refresh_token_class instead') |
|
55
|
|
|
->end() |
|
56
|
|
|
->scalarNode('entity_manager') |
|
57
|
|
|
->defaultNull() |
|
58
|
|
|
->info('Deprecated, use object_manager instead') |
|
59
|
|
|
->end() |
|
60
|
|
|
->scalarNode('single_use') |
|
61
|
|
|
->defaultFalse() |
|
62
|
|
|
->info('When true, generate a new refresh token on consumption (deleting the old one)') |
|
63
|
|
|
->end() |
|
64
|
|
|
->scalarNode('token_parameter_name')->defaultValue('refresh_token')->end() |
|
65
|
|
|
->end(); |
|
66
|
|
|
|
|
67
|
|
|
return $treeBuilder; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: