Failed Conditions
Push — ng ( 962349...975869 )
by Florent
03:54
created

JwksUriEndpointSource   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 57
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A name() 0 4 1
A load() 0 4 1
A getNodeDefinition() 0 20 1
A prepend() 0 11 2
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\Bundle\DependencyInjection\Component\Endpoint\JwksUri;
15
16
use Jose\Bundle\JoseFramework\Helper\ConfigurationHelper;
17
use OAuth2Framework\Bundle\DependencyInjection\Component\Component;
18
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
19
use Symfony\Component\DependencyInjection\ContainerBuilder;
20
use Symfony\Component\PropertyAccess\PropertyAccess;
21
22
class JwksUriEndpointSource implements Component
23
{
24
    /**
25
     * @return string
26
     */
27
    public function name(): string
28
    {
29
        return 'jwks_uri';
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function load(array $configs, ContainerBuilder $container)
36
    {
37
        //Nothing to do
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function getNodeDefinition(NodeDefinition $node)
44
    {
45
        $node->children()
46
            ->arrayNode($this->name())
47
                ->addDefaultsIfNotSet()
48
                ->canBeEnabled()
49
                ->children()
50
                    ->scalarNode('path')
51
                    ->info('The path of the key set (e.g. "/openid_connect/certs").')
52
                ->end()
53
                ->scalarNode('key_set')
54
                    ->info('The public key set to share with third party applications.')
55
                ->end()
56
                ->integerNode('max_age')
57
                    ->info('When share, this value indicates how many seconds the HTTP client should keep the key in cache. Default is 21600 = 6 hours.')
58
                    ->defaultValue(21600)
59
                ->end()
60
            ->end()
61
        ->end();
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67
    public function prepend(ContainerBuilder $container, array $config): array
68
    {
69
        $currentPath = '[endpoint][jwks_uri]';
70
        $accessor = PropertyAccess::createPropertyAccessor();
71
        $sourceConfig = $accessor->getValue($config, $currentPath);
72
        if (true === $sourceConfig['enabled']) {
73
            ConfigurationHelper::addKeyset($container, 'oauth2_server.endpoint.jwks_uri', 'jwkset', ['value' => $sourceConfig['key_set']]);
74
            ConfigurationHelper::addKeyUri($container, 'oauth2_server.endpoint.jwks_uri', ['id' => 'jose.key_set.oauth2_server.endpoint.jwks_uri', 'path' => $sourceConfig['path'], 'max_age' => $sourceConfig['max_age']]);
75
        }
76
        return [];
77
    }
78
}
79