MetadataBuilder   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 28
dl 0
loc 94
rs 10
c 0
b 0
f 0
wmc 16

14 Methods

Rating   Name   Duplication   Size   Complexity  
A setTokenEndpointAuthMethodManager() 0 3 1
A addRoute() 0 4 1
A setResponseModeManager() 0 3 1
A __construct() 0 4 1
A setClientAssertionJwt() 0 5 1
A getMetadata() 0 3 1
A setClaimsSupported() 0 3 1
A setGrantTypeManager() 0 3 1
A setScopeRepository() 0 3 1
A setCodeChallengeMethodsSupported() 0 3 1
A setResponseTypeManager() 0 3 1
A setUserinfo() 0 3 2
A addKeyValuePair() 0 3 1
A setAuthorizationRequestLoader() 0 10 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\Service;
15
16
use OAuth2Framework\Component\AuthorizationCodeGrant\PKCEMethod\PKCEMethodManager;
17
use OAuth2Framework\Component\AuthorizationEndpoint\AuthorizationRequest\AuthorizationRequestLoader;
18
use OAuth2Framework\Component\AuthorizationEndpoint\ResponseMode\ResponseModeManager;
19
use OAuth2Framework\Component\AuthorizationEndpoint\ResponseType\ResponseTypeManager;
20
use OAuth2Framework\Component\ClientAuthentication\AuthenticationMethodManager;
21
use OAuth2Framework\Component\ClientAuthentication\ClientAssertionJwt;
22
use OAuth2Framework\Component\MetadataEndpoint\Metadata;
23
use OAuth2Framework\Component\OpenIdConnect\UserInfo\Claim\ClaimManager;
24
use OAuth2Framework\Component\OpenIdConnect\UserInfo\UserInfo;
25
use OAuth2Framework\Component\Scope\ScopeRepository;
26
use OAuth2Framework\Component\TokenEndpoint\GrantTypeManager;
27
use Symfony\Component\Routing\RouterInterface;
28
29
class MetadataBuilder
30
{
31
    /**
32
     * @var RouterInterface
33
     */
34
    private $router;
35
36
    /**
37
     * @var Metadata
38
     */
39
    private $metadata;
40
41
    public function __construct(RouterInterface $router)
42
    {
43
        $this->router = $router;
44
        $this->metadata = new Metadata();
45
    }
46
47
    public function getMetadata(): Metadata
48
    {
49
        return $this->metadata;
50
    }
51
52
    public function addRoute(string $name, string $routeName, array $routeParameters = []): void
53
    {
54
        $path = $this->router->generate($routeName, $routeParameters, RouterInterface::ABSOLUTE_URL);
55
        $this->metadata->set($name, $path);
56
    }
57
58
    public function setCodeChallengeMethodsSupported(PKCEMethodManager $PKCEMethodManager): void
59
    {
60
        $this->metadata->set('code_challenge_methods_supported', $PKCEMethodManager->names());
61
    }
62
63
    public function setClientAssertionJwt(ClientAssertionJwt $clientAssertionJwt): void
64
    {
65
        $this->metadata->set('token_endpoint_auth_signing_alg_values_supported', $clientAssertionJwt->getSupportedSignatureAlgorithms());
66
        $this->metadata->set('token_endpoint_auth_encryption_alg_values_supported', $clientAssertionJwt->getSupportedKeyEncryptionAlgorithms());
67
        $this->metadata->set('token_endpoint_auth_encryption_enc_values_supported', $clientAssertionJwt->getSupportedContentEncryptionAlgorithms());
68
    }
69
70
    public function setGrantTypeManager(GrantTypeManager $grantTypeManager): void
71
    {
72
        $this->metadata->set('grant_types_supported', $grantTypeManager->list());
73
    }
74
75
    public function setResponseTypeManager(ResponseTypeManager $responseTypeManager): void
76
    {
77
        $this->metadata->set('response_types_supported', $responseTypeManager->list());
78
    }
79
80
    public function setResponseModeManager(ResponseModeManager $responseModeManager): void
81
    {
82
        $this->metadata->set('response_modes_supported', $responseModeManager->list());
83
    }
84
85
    public function setTokenEndpointAuthMethodManager(AuthenticationMethodManager $tokenEndpointAuthMethodManager): void
86
    {
87
        $this->metadata->set('token_endpoint_auth_methods_supported', $tokenEndpointAuthMethodManager->list());
88
    }
89
90
    public function setScopeRepository(ScopeRepository $scopeRepository): void
91
    {
92
        $this->metadata->set('scopes_supported', $scopeRepository->all());
93
    }
94
95
    public function setUserinfo(UserInfo $userInfo): void
96
    {
97
        $this->metadata->set('subject_types_supported', $userInfo->isPairwiseSubjectIdentifierSupported() ? ['public', 'pairwise'] : ['public']);
98
    }
99
100
    public function setClaimsSupported(ClaimManager $claimManager): void
101
    {
102
        $this->metadata->set('claims_supported', $claimManager->list());
103
    }
104
105
    /**
106
     * @param null|mixed $value
107
     */
108
    public function addKeyValuePair(string $name, $value): void
109
    {
110
        $this->metadata->set($name, $value);
111
    }
112
113
    public function setAuthorizationRequestLoader(AuthorizationRequestLoader $authorizationRequestLoader): void
114
    {
115
        $requestObjectSupported = $authorizationRequestLoader->isRequestObjectSupportEnabled();
116
        $this->metadata->set('request_parameter_supported', $requestObjectSupported);
117
        if ($requestObjectSupported) {
118
            $this->metadata->set('request_uri_parameter_supported', $authorizationRequestLoader->isRequestObjectReferenceSupportEnabled());
119
            $this->metadata->set('require_request_uri_registration', $authorizationRequestLoader->isRequestUriRegistrationRequired());
120
            $this->metadata->set('request_object_signing_alg_values_supported', $authorizationRequestLoader->getSupportedSignatureAlgorithms());
121
            $this->metadata->set('request_object_encryption_alg_values_supported', $authorizationRequestLoader->getSupportedKeyEncryptionAlgorithms());
122
            $this->metadata->set('request_object_encryption_enc_values_supported', $authorizationRequestLoader->getSupportedContentEncryptionAlgorithms());
123
        }
124
    }
125
}
126