|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Majora\Bundle\OAuthServerBundle\DependencyInjection; |
|
4
|
|
|
|
|
5
|
|
|
use Majora\Component\OAuth\Entity\AccessToken; |
|
6
|
|
|
use Majora\Component\OAuth\Entity\RefreshToken; |
|
7
|
|
|
use Majora\Component\OAuth\Model\AccessTokenInterface; |
|
8
|
|
|
use Majora\Component\OAuth\Model\RefreshTokenInterface; |
|
9
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
|
10
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Majora OAuth server bundle semantical configuration class. |
|
14
|
|
|
*/ |
|
15
|
|
|
class Configuration implements ConfigurationInterface |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* {@inheritdoc} |
|
19
|
|
|
* |
|
20
|
|
|
* @see http://symfony.com/doc/current/components/config/definition.html |
|
21
|
|
|
*/ |
|
22
|
|
|
public function getConfigTreeBuilder() |
|
23
|
|
|
{ |
|
24
|
|
|
$treeBuilder = new TreeBuilder(); |
|
25
|
|
|
$treeBuilder->root('majora_oauth_server') |
|
26
|
|
|
->children() |
|
27
|
|
|
->scalarNode('secret') |
|
28
|
|
|
->isRequired() |
|
29
|
|
|
->cannotBeEmpty() |
|
30
|
|
|
->end() |
|
31
|
|
|
->arrayNode('access_token') |
|
32
|
|
|
->addDefaultsIfNotSet() |
|
33
|
|
|
->children() |
|
34
|
|
|
->integerNode('ttl') |
|
35
|
|
|
->defaultValue(AccessTokenInterface::DEFAULT_TTL) |
|
36
|
|
|
->end() |
|
37
|
|
|
->scalarNode('class') |
|
38
|
|
|
->cannotBeEmpty() |
|
39
|
|
|
->defaultValue(AccessToken::class) |
|
40
|
|
|
->validate() |
|
41
|
|
|
->ifTrue(function ($accessTokenClass) { |
|
42
|
|
|
return !( |
|
43
|
|
|
class_exists($accessTokenClass, true) |
|
44
|
|
|
&& (new \ReflectionClass($accessTokenClass)) |
|
45
|
|
|
->implementsInterface(AccessTokenInterface::class) |
|
46
|
|
|
); |
|
47
|
|
|
}) |
|
48
|
|
|
->thenInvalid('Provided access_token configuration has to be a valid class which implements Majora\Component\OAuth\Model\AccessTokenInterface.') |
|
49
|
|
|
->end() |
|
50
|
|
|
->end() |
|
51
|
|
|
->end() |
|
52
|
|
|
->end() |
|
53
|
|
|
|
|
54
|
|
|
->arrayNode('refresh_token') |
|
55
|
|
|
->addDefaultsIfNotSet() |
|
56
|
|
|
->children() |
|
57
|
|
|
->integerNode('ttl') |
|
58
|
|
|
->defaultValue(RefreshTokenInterface::DEFAULT_TTL) |
|
59
|
|
|
->end() |
|
60
|
|
|
->scalarNode('class') |
|
61
|
|
|
->cannotBeEmpty() |
|
62
|
|
|
->defaultValue(RefreshToken::class) |
|
63
|
|
|
->validate() |
|
64
|
|
|
->ifTrue(function ($refreshTokenClass) { |
|
65
|
|
|
return !( |
|
66
|
|
|
class_exists($refreshTokenClass, true) |
|
67
|
|
|
&& (new \ReflectionClass($refreshTokenClass)) |
|
68
|
|
|
->implementsInterface(RefreshTokenInterface::class) |
|
69
|
|
|
); |
|
70
|
|
|
}) |
|
71
|
|
|
->thenInvalid('Provided refresh_token configuration has to be a valid class which implements Majora\Component\OAuth\Model\RefreshTokenInterface.') |
|
72
|
|
|
->end() |
|
73
|
|
|
->end() |
|
74
|
|
|
->scalarNode('loader') |
|
75
|
|
|
->isRequired() |
|
76
|
|
|
->cannotBeEmpty() |
|
77
|
|
|
->end() |
|
78
|
|
|
->end() |
|
79
|
|
|
->end() |
|
80
|
|
|
|
|
81
|
|
|
->arrayNode('application') |
|
82
|
|
|
->children() |
|
83
|
|
|
->scalarNode('loader') |
|
84
|
|
|
->isRequired() |
|
85
|
|
|
->cannotBeEmpty() |
|
86
|
|
|
->end() |
|
87
|
|
|
->end() |
|
88
|
|
|
->end() |
|
89
|
|
|
->arrayNode('account') |
|
90
|
|
|
->children() |
|
91
|
|
|
->scalarNode('loader') |
|
92
|
|
|
->isRequired() |
|
93
|
|
|
->cannotBeEmpty() |
|
94
|
|
|
->end() |
|
95
|
|
|
->end() |
|
96
|
|
|
->end() |
|
97
|
|
|
->end() |
|
98
|
|
|
; |
|
99
|
|
|
|
|
100
|
|
|
return $treeBuilder; |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|