|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of the KleijnWeb\JwtBundle package. |
|
4
|
|
|
* |
|
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
6
|
|
|
* file that was distributed with this source code. |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace KleijnWeb\JwtBundle\DependencyInjection; |
|
10
|
|
|
|
|
11
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
12
|
|
|
use Symfony\Component\Config\FileLocator; |
|
13
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
14
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
|
15
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
|
16
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @author John Kleijn <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
class KleijnWebJwtExtension extends Extension |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* {@inheritdoc} |
|
25
|
|
|
*/ |
|
26
|
|
|
public function load(array $configs, ContainerBuilder $container) |
|
27
|
|
|
{ |
|
28
|
|
|
$config = $this->processConfiguration(new Configuration(), $configs); |
|
29
|
|
|
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); |
|
30
|
|
|
$loader->load('services.yml'); |
|
31
|
|
|
|
|
32
|
|
|
$keys = []; |
|
33
|
|
|
|
|
34
|
|
|
foreach ($config['keys'] as $keyId => $keyConfig) { |
|
35
|
|
|
|
|
36
|
|
|
$keyConfig['kid'] = $keyId; |
|
37
|
|
|
$keyDefinition = new Definition('jwt.keys.' . $keyId); |
|
38
|
|
|
$keyDefinition->setClass('KleijnWeb\JwtBundle\Authenticator\JwtKey'); |
|
39
|
|
|
|
|
40
|
|
|
if (isset($keyConfig['loader'])) { |
|
41
|
|
|
$keyConfig['loader'] = new Reference($keyConfig['loader']); |
|
42
|
|
|
} |
|
43
|
|
|
$keyDefinition->addArgument($keyConfig); |
|
44
|
|
|
$keys[] = $keyDefinition; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
$container->getDefinition('jwt.authenticator')->addArgument($keys); |
|
48
|
|
|
|
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @return string |
|
53
|
|
|
*/ |
|
54
|
|
|
public function getAlias() |
|
55
|
|
|
{ |
|
56
|
|
|
return "jwt"; |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|