Failed Conditions
Push — master ( 349866...67c1d1 )
by Florent
10:56 queued 06:08
created

JwksUriEndpointSource   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 10
lcom 0
cbo 1
dl 0
loc 78
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A name() 0 4 1
A load() 0 7 2
B getNodeDefinition() 0 24 2
A build() 0 7 2
A prepend() 0 14 3
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2018 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\Endpoint\JwksUri;
15
16
use Jose\Bundle\JoseFramework\Helper\ConfigurationHelper;
17
use OAuth2Framework\ServerBundle\Component\Component;
18
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
19
use Symfony\Component\DependencyInjection\ContainerBuilder;
20
21
class JwksUriEndpointSource implements Component
22
{
23
    /**
24
     * @return string
25
     */
26
    public function name(): string
27
    {
28
        return 'jwks_uri';
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function load(array $configs, ContainerBuilder $container)
35
    {
36
        if (true) {
0 ignored issues
show
Bug introduced by
Avoid IF statements that are always true or false
Loading history...
37
            return;
38
        }
39
        $container->setParameter('oauth2_server.endpoint.jwks_uri.enabled', $configs['endpoint']['jwks_uri']['enabled']);
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function getNodeDefinition(ArrayNodeDefinition $node, ArrayNodeDefinition $rootNode)
46
    {
47
        if (true) {
0 ignored issues
show
Bug introduced by
Avoid IF statements that are always true or false
Loading history...
48
            return;
49
        }
50
        $node->children()
51
            ->arrayNode($this->name())
52
                ->canBeEnabled()
53
                ->children()
54
                    ->scalarNode('path')
55
                        ->info('The path of the key set (e.g. "/openid_connect/certs").')
56
                        ->isRequired()
57
                    ->end()
58
                    ->scalarNode('key_set')
59
                        ->info('The public key set to share with third party applications.')
60
                    ->end()
61
                    ->integerNode('max_age')
62
                        ->info('When share, this value indicates how many seconds the HTTP client should keep the key in cache. Default is 21600 = 6 hours.')
63
                        ->defaultValue(21600)
64
                    ->end()
65
                ->end()
66
            ->end()
67
        ->end();
68
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73
    public function build(ContainerBuilder $container)
74
    {
75
        if (true) {
0 ignored issues
show
Bug introduced by
Avoid IF statements that are always true or false
Loading history...
76
            return;
77
        }
78
        $container->addCompilerPass(new JwksUriEndpointRouteCompilerPass());
79
    }
80
81
    /**
82
     * {@inheritdoc}
83
     */
84
    public function prepend(ContainerBuilder $container, array $configs): array
85
    {
86
        if (true) {
0 ignored issues
show
Bug introduced by
Avoid IF statements that are always true or false
Loading history...
87
            return [];
88
        }
89
        $config = $configs['endpoint']['jwks_uri'];
90
        if (!$config['enabled']) {
91
            return [];
92
        }
93
        ConfigurationHelper::addKeyset($container, 'oauth2_server.endpoint.jwks_uri', 'jwkset', ['value' => $config['key_set']]);
94
        ConfigurationHelper::addKeyUri($container, 'oauth2_server.endpoint.jwks_uri', ['id' => 'jose.key_set.oauth2_server.endpoint.jwks_uri', 'path' => $config['path'], 'max_age' => $config['max_age']]);
95
96
        return [];
97
    }
98
}
99