Failed Conditions
Push — ng ( e90992...13fb6e )
by Florent
17:32
created

IdTokenSource::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
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\OpenIdConnect;
15
16
use Fluent\PhpConfigFileLoader;
17
use Jose\Bundle\JoseFramework\Helper\ConfigurationHelper;
18
use OAuth2Framework\Bundle\DependencyInjection\Component\Component;
19
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
20
use Symfony\Component\Config\FileLocator;
21
use Symfony\Component\DependencyInjection\ContainerBuilder;
22
use Symfony\Component\PropertyAccess\PropertyAccess;
23
24
final class IdTokenSource implements Component
0 ignored issues
show
Bug introduced by
There is one abstract method load in this class; you could implement it, or declare this class as abstract.
Loading history...
25
{
26
    /**
27
     * UserinfoSource constructor.
28
     */
29
    public function __construct()
30
    {
31
        $this->addSubSource(new IdTokenResponseTypeSource());
0 ignored issues
show
Bug introduced by
The method addSubSource() does not seem to exist on object<OAuth2Framework\B...dConnect\IdTokenSource>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
32
        $this->addSubSource(new IdTokenEncryptionSource());
0 ignored issues
show
Bug introduced by
The method addSubSource() does not seem to exist on object<OAuth2Framework\B...dConnect\IdTokenSource>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function prepend(array $bundleConfig, string $path, ContainerBuilder $container)
39
    {
40
        parent::prepend($bundleConfig, $path, $container);
41
        $currentPath = $path.'['.$this->name().']';
42
        $accessor = PropertyAccess::createPropertyAccessor();
43
        $sourceConfig = $accessor->getValue($bundleConfig, $currentPath);
44
        ConfigurationHelper::addJWSBuilder($container, $this->name(), $sourceConfig['signature_algorithms'], false);
45
        ConfigurationHelper::addJWSLoader($container, $this->name(), $sourceConfig['signature_algorithms'], [], ['jws_compact'], false);
0 ignored issues
show
Bug introduced by
The method addJWSLoader() does not seem to exist on object<Jose\Bundle\JoseF...er\ConfigurationHelper>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
46
47
        Assertion::keyExists($bundleConfig['key_set'], 'signature', 'The signature key set must be enabled.');
48
        //ConfigurationHelper::addKeyset($container, 'id_token.key_set.signature', 'jwkset', ['value' => $bundleConfig['key_set']['signature']]);
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    protected function continueLoading(string $path, ContainerBuilder $container, array $config)
55
    {
56
        foreach (['lifetime', 'default_signature_algorithm', 'signature_algorithms', 'claim_checkers', 'header_checkers'] as $k) {
57
            $container->setParameter($path.'.'.$k, $config[$k]);
58
        }
59
        //$container->setAlias($path.'.key_set', 'jose.key_set.id_token.key_set.signature');
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
60
61
        $loader = new PhpConfigFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config/openid_connect'));
62
        $loader->load('userinfo_scope_support.php');
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68
    public function name(): string
69
    {
70
        return 'id_token';
71
    }
72
73
    public function getNodeDefinition(NodeDefinition $node)
74
    {
75
76
        $node
77
            ->validate()
78
                ->ifTrue(function ($config) {
79
                    return empty($config['default_signature_algorithm']);
80
                })
81
                ->thenInvalid('The option "default_signature_algorithm" must be set.')
82
            ->end()
83
            ->validate()
84
                ->ifTrue(function ($config) {
85
                    return empty($config['signature_algorithms']);
86
                })
87
                ->thenInvalid('The option "signature_algorithm" must contain at least one signature algorithm.')
88
            ->end()
89
            ->validate()
90
                ->ifTrue(function ($config) {
91
                    return !in_array($config['default_signature_algorithm'], $config['signature_algorithms']);
92
                })
93
                ->thenInvalid('The default signature algorithm must be in the supported signature algorithms.')
94
            ->end()
95
            ->children()
96
                ->scalarNode('default_signature_algorithm')
97
                    ->info('Signature algorithm used if the client has not defined a preferred one. Recommended value is "RS256".')
98
                ->end()
99
                ->arrayNode('signature_algorithms')
100
                    ->info('Signature algorithm used to sign the ID Tokens.')
101
                    ->useAttributeAsKey('name')
102
                    ->prototype('scalar')->end()
103
                    ->treatNullLike([])
104
                ->end()
105
                ->arrayNode('claim_checkers')
106
                    ->info('Checkers will verify the JWT claims.')
107
                    ->useAttributeAsKey('name')
108
                    ->prototype('scalar')->end()
109
                    ->treatNullLike(['exp', 'iat', 'nbf'])
110
                ->end()
111
                ->arrayNode('header_checkers')
112
                    ->info('Checkers will verify the JWT headers.')
113
                    ->useAttributeAsKey('name')
114
                    ->prototype('scalar')->end()
115
                    ->treatNullLike(['crit'])
116
                ->end()
117
                ->integerNode('lifetime')
118
                    ->info('Lifetime of the ID Tokens (in seconds). If an access token is issued with the ID Token, the lifetime of the access token is used instead of this value.')
119
                    ->defaultValue(3600)
120
                    ->min(1)
121
                ->end()
122
            ->end();
123
    }
124
}
125