|
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\Service; |
|
15
|
|
|
|
|
16
|
|
|
use OAuth2Framework\Component\AuthorizationCodeGrant\PKCEMethod\PKCEMethodManager; |
|
17
|
|
|
use OAuth2Framework\Component\AuthorizationEndpoint\AuthorizationRequestLoader; |
|
18
|
|
|
use OAuth2Framework\Component\AuthorizationEndpoint\ResponseMode\ResponseModeManager; |
|
19
|
|
|
use OAuth2Framework\Component\AuthorizationEndpoint\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\UserInfo; |
|
24
|
|
|
use OAuth2Framework\Component\Scope\ScopeRepository; |
|
25
|
|
|
use OAuth2Framework\Component\TokenEndpoint\GrantTypeManager; |
|
26
|
|
|
use Symfony\Component\Routing\RouterInterface; |
|
27
|
|
|
|
|
28
|
|
|
class MetadataBuilder |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* @var RouterInterface |
|
32
|
|
|
*/ |
|
33
|
|
|
private $router; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var Metadata |
|
37
|
|
|
*/ |
|
38
|
|
|
private $metadata; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* MetadataBuilder constructor. |
|
42
|
|
|
* |
|
43
|
|
|
* @param RouterInterface $router |
|
44
|
|
|
*/ |
|
45
|
|
|
public function __construct(RouterInterface $router) |
|
46
|
|
|
{ |
|
47
|
|
|
$this->router = $router; |
|
48
|
|
|
$this->metadata = new Metadata(); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @return Metadata |
|
53
|
|
|
*/ |
|
54
|
|
|
public function getMetadata(): Metadata |
|
55
|
|
|
{ |
|
56
|
|
|
return $this->metadata; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @param string $name |
|
61
|
|
|
* @param string $routeName |
|
62
|
|
|
* @param array $routeParameters |
|
63
|
|
|
*/ |
|
64
|
|
|
public function addRoute(string $name, string $routeName, array $routeParameters = []) |
|
65
|
|
|
{ |
|
66
|
|
|
$path = $this->router->generate($routeName, $routeParameters, RouterInterface::ABSOLUTE_URL); |
|
67
|
|
|
$this->metadata->set($name, $path); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @param PKCEMethodManager $PKCEMethodManager |
|
72
|
|
|
*/ |
|
73
|
|
|
public function setCodeChallengeMethodsSupported(PKCEMethodManager $PKCEMethodManager) |
|
74
|
|
|
{ |
|
75
|
|
|
$this->metadata->set('code_challenge_methods_supported', $PKCEMethodManager->names()); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @param ClientAssertionJwt $clientAssertionJwt |
|
80
|
|
|
*/ |
|
81
|
|
|
public function setClientAssertionJwt(ClientAssertionJwt $clientAssertionJwt) |
|
82
|
|
|
{ |
|
83
|
|
|
$this->metadata->set('token_endpoint_auth_signing_alg_values_supported', $clientAssertionJwt->getSupportedSignatureAlgorithms()); |
|
84
|
|
|
$this->metadata->set('token_endpoint_auth_encryption_alg_values_supported', $clientAssertionJwt->getSupportedKeyEncryptionAlgorithms()); |
|
85
|
|
|
$this->metadata->set('token_endpoint_auth_encryption_enc_values_supported', $clientAssertionJwt->getSupportedContentEncryptionAlgorithms()); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @param GrantTypeManager $grantTypeManager |
|
90
|
|
|
*/ |
|
91
|
|
|
public function setGrantTypeManager(GrantTypeManager $grantTypeManager) |
|
92
|
|
|
{ |
|
93
|
|
|
$this->metadata->set('grant_types_supported', $grantTypeManager->list()); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @param ResponseTypeManager $responseTypeManager |
|
98
|
|
|
*/ |
|
99
|
|
|
public function setResponseTypeManager(ResponseTypeManager $responseTypeManager) |
|
100
|
|
|
{ |
|
101
|
|
|
$this->metadata->set('response_types_supported', $responseTypeManager->list()); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @param ResponseModeManager $responseModeManager |
|
106
|
|
|
*/ |
|
107
|
|
|
public function setResponseModeManager(ResponseModeManager $responseModeManager) |
|
108
|
|
|
{ |
|
109
|
|
|
$this->metadata->set('response_modes_supported', $responseModeManager->list()); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @param AuthenticationMethodManager $tokenEndpointAuthMethodManager |
|
114
|
|
|
*/ |
|
115
|
|
|
public function setTokenEndpointAuthMethodManager(AuthenticationMethodManager $tokenEndpointAuthMethodManager) |
|
116
|
|
|
{ |
|
117
|
|
|
$this->metadata->set('token_endpoint_auth_methods_supported', $tokenEndpointAuthMethodManager->list()); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @param ScopeRepository $scopeRepository |
|
122
|
|
|
*/ |
|
123
|
|
|
public function setScopeRepository(ScopeRepository $scopeRepository) |
|
124
|
|
|
{ |
|
125
|
|
|
$this->metadata->set('scopes_supported', $scopeRepository->all()); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* @param UserInfo $userInfo |
|
130
|
|
|
*/ |
|
131
|
|
|
public function setUserinfo(UserInfo $userInfo) |
|
132
|
|
|
{ |
|
133
|
|
|
$this->metadata->set('subject_types_supported', $userInfo->isPairwiseSubjectIdentifierSupported() ? ['public', 'pairwise'] : ['public']); |
|
134
|
|
|
$this->metadata->set('claims_supported', $userInfo->getSupportedClaims()); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* @param string $name |
|
139
|
|
|
* @param mixed $value |
|
140
|
|
|
*/ |
|
141
|
|
|
public function addKeyValuePair(string $name, $value) |
|
142
|
|
|
{ |
|
143
|
|
|
$this->metadata->set($name, $value); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* @param AuthorizationRequestLoader $authorizationRequestLoader |
|
148
|
|
|
*/ |
|
149
|
|
|
public function setAuthorizationRequestLoader(AuthorizationRequestLoader $authorizationRequestLoader) |
|
150
|
|
|
{ |
|
151
|
|
|
$requestObjectSupported = $authorizationRequestLoader->isRequestObjectSupportEnabled(); |
|
152
|
|
|
$this->metadata->set('request_parameter_supported', $authorizationRequestLoader->isRequestObjectSupportEnabled()); |
|
153
|
|
|
if ($requestObjectSupported) { |
|
154
|
|
|
$this->metadata->set('request_uri_parameter_supported', $authorizationRequestLoader->isRequestObjectReferenceSupportEnabled()); |
|
155
|
|
|
$this->metadata->set('require_request_uri_registration', $authorizationRequestLoader->isRequestUriRegistrationRequired()); |
|
156
|
|
|
$this->metadata->set('request_object_signing_alg_values_supported', $authorizationRequestLoader->getSupportedSignatureAlgorithms()); |
|
157
|
|
|
$this->metadata->set('request_object_encryption_alg_values_supported', $authorizationRequestLoader->getSupportedKeyEncryptionAlgorithms()); |
|
158
|
|
|
$this->metadata->set('request_object_encryption_enc_values_supported', $authorizationRequestLoader->getSupportedContentEncryptionAlgorithms()); |
|
159
|
|
|
} |
|
160
|
|
|
} |
|
161
|
|
|
} |
|
162
|
|
|
|