AuthorizationCodeSource   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 36
c 0
b 0
f 0
dl 0
loc 60
rs 10
wmc 9

5 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 11 3
A getNodeDefinition() 0 25 2
A name() 0 3 1
A prepend() 0 3 1
A build() 0 7 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2019 Spomky-Labs
9
 *
10
 * This software may be modified and distributed under the terms
11
 * of the MIT license.  See the LICENSE file for details.
12
 */
13
14
namespace OAuth2Framework\ServerBundle\Component\Grant\AuthorizationCode;
15
16
use OAuth2Framework\Component\AuthorizationCodeGrant\AuthorizationCode;
17
use OAuth2Framework\Component\AuthorizationCodeGrant\AuthorizationCodeRepository;
18
use OAuth2Framework\ServerBundle\Component\Component;
19
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
20
use Symfony\Component\Config\FileLocator;
21
use Symfony\Component\DependencyInjection\ContainerBuilder;
22
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
23
24
class AuthorizationCodeSource implements Component
25
{
26
    public function name(): string
27
    {
28
        return 'authorization_code';
29
    }
30
31
    public function load(array $configs, ContainerBuilder $container): void
32
    {
33
        if (!interface_exists(AuthorizationCode::class) || true !== $configs['grant']['authorization_code']['enabled']) {
34
            return;
35
        }
36
        $container->setParameter('oauth2_server.grant.authorization_code.lifetime', $configs['grant']['authorization_code']['lifetime']);
37
        $container->setParameter('oauth2_server.grant.authorization_code.enforce_pkce', $configs['grant']['authorization_code']['enforce_pkce']);
38
        $container->setAlias(AuthorizationCodeRepository::class, $configs['grant']['authorization_code']['repository']);
39
40
        $loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config/grant'));
41
        $loader->load('authorization_code.php');
42
    }
43
44
    public function getNodeDefinition(ArrayNodeDefinition $node, ArrayNodeDefinition $rootNode): void
45
    {
46
        if (!interface_exists(AuthorizationCode::class)) {
47
            return;
48
        }
49
        $node->children()
50
            ->arrayNode('authorization_code')
51
            ->canBeEnabled()
52
            ->children()
53
            ->integerNode('lifetime')
54
            ->defaultValue(30)
55
            ->min(1)
56
            ->info('Authorization code lifetime (in seconds)')
57
            ->end()
58
            ->scalarNode('repository')
0 ignored issues
show
Bug introduced by
The method scalarNode() does not exist on Symfony\Component\Config...der\NodeParentInterface. It seems like you code against a sub-type of Symfony\Component\Config...der\NodeParentInterface such as Symfony\Component\Config...ion\Builder\NodeBuilder. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

58
            ->/** @scrutinizer ignore-call */ scalarNode('repository')
Loading history...
59
            ->isRequired()
60
            ->info('The authorization code repository')
61
            ->end()
62
            ->booleanNode('enforce_pkce')
63
            ->defaultFalse()
64
            ->info('If true, the PKCE is required for all requests including the ones from confidential clients')
65
            ->end()
66
            ->end()
67
            ->end()
68
            ->end()
69
        ;
70
    }
71
72
    public function build(ContainerBuilder $container): void
73
    {
74
        if (!class_exists(AuthorizationCode::class)) {
75
            return;
76
        }
77
        $container->addCompilerPass(new PKCEMethodCompilerPass());
78
        $container->addCompilerPass(new AuthorizationCodeSupportForIdTokenBuilderCompilerPass());
79
    }
80
81
    public function prepend(ContainerBuilder $container, array $config): array
82
    {
83
        return [];
84
    }
85
}
86