ApiGwAuthenticationExtension::prepend()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 22
ccs 0
cts 5
cp 0
rs 9.9332
c 1
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
/**
4
 * For the full copyright and license information, please view
5
 * the LICENSE file that was distributed with this source code.
6
 *
7
 * @see https://github.com/ecphp
8
 */
9
10
declare(strict_types=1);
11
12
namespace EcPhp\ApiGwAuthenticationBundle\DependencyInjection;
13
14
use Symfony\Component\Config\FileLocator;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
17
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
18
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
19
20
class ApiGwAuthenticationExtension extends Extension implements PrependExtensionInterface
21
{
22
    public function load(array $configs, ContainerBuilder $container): void
23
    {
24
        $configuration = new Configuration();
25
        $config = $this->processConfiguration($configuration, $configs);
26
27
        // Load API GW Authentication configuration.
28
        $container->setParameter('api_gw_authentication', $config);
29
30
        $loader = new PhpFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
31
        $loader->load('services.php');
32
    }
33
34
    public function prepend(ContainerBuilder $container)
35
    {
36
        // Configure the symfony/security bundle
37
        // Add the API Gateway user provider.
38
        $container
39
            ->loadFromExtension(
40
                'security',
41
                [
42
                    'providers' => [
43
                        'api_gw_authentication' => [
44
                            'id' => 'api_gw_authentication.user_provider',
45
                        ],
46
                    ],
47
                ]
48
            );
49
50
        // Configure the lexik/jwt-authenication bundle
51
        $container
52
            ->loadFromExtension(
53
                'lexik_jwt_authentication',
54
                [
55
                    'user_identity_field' => 'sub',
56
                ]
57
            );
58
    }
59
}
60