1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace TMV\OpenIdClient\Model; |
6
|
|
|
|
7
|
|
|
use TMV\OpenIdClient\Exception\InvalidArgumentException; |
8
|
|
|
|
9
|
|
|
class ClientMetadata implements ClientMetadataInterface |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var array |
13
|
|
|
*/ |
14
|
|
|
private $claims; |
15
|
|
|
|
16
|
|
|
private static $requiredKeys = [ |
17
|
|
|
'client_id', |
18
|
|
|
]; |
19
|
|
|
|
20
|
|
|
private static $defaults = [ |
21
|
|
|
'client_id' => null, |
22
|
|
|
'redirect_uris' => [], |
23
|
|
|
'client_secret' => null, |
24
|
|
|
'jwks' => null, |
25
|
|
|
'jwks_uri' => null, |
26
|
|
|
'id_token_signed_response_alg' => 'RS256', |
27
|
|
|
'id_token_encrypted_response_alg' => null, |
28
|
|
|
'id_token_encrypted_response_enc' => null, |
29
|
|
|
'userinfo_signed_response_alg' => null, |
30
|
|
|
'userinfo_encrypted_response_alg' => null, |
31
|
|
|
'userinfo_encrypted_response_enc' => null, |
32
|
|
|
'response_types' => ['code'], |
33
|
|
|
'post_logout_redirect_uris' => [], |
34
|
|
|
'require_auth_time' => false, |
35
|
|
|
'request_object_signing_alg' => null, |
36
|
|
|
'request_object_encryption_alg' => null, |
37
|
|
|
'request_object_encryption_enc' => null, |
38
|
|
|
'token_endpoint_auth_method' => 'client_secret_basic', |
39
|
|
|
//'introspection_endpoint_auth_method' => 'client_secret_basic', |
40
|
|
|
//'revocation_endpoint_auth_method' => 'client_secret_basic', |
41
|
|
|
'token_endpoint_auth_signing_alg' => null, |
42
|
|
|
'introspection_endpoint_auth_signing_alg' => null, |
43
|
|
|
'revocation_endpoint_auth_signing_alg' => null, |
44
|
|
|
'tls_client_certificate_bound_access_tokens' => false, |
45
|
|
|
]; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* IssuerMetadata constructor. |
49
|
|
|
* |
50
|
|
|
* @param string $clientId |
51
|
|
|
* @param array<string, mixed> $claims |
52
|
|
|
*/ |
53
|
19 |
|
public function __construct(string $clientId, $claims = []) |
54
|
|
|
{ |
55
|
|
|
$requiredClaims = [ |
56
|
19 |
|
'client_id' => $clientId, |
57
|
|
|
]; |
58
|
|
|
|
59
|
19 |
|
$defaults = static::$defaults; |
|
|
|
|
60
|
|
|
|
61
|
19 |
|
$this->claims = \array_merge($defaults, $claims, $requiredClaims); |
62
|
19 |
|
} |
63
|
|
|
|
64
|
2 |
|
public static function fromClaims(array $claims): self |
65
|
|
|
{ |
66
|
2 |
|
$missingKeys = \array_diff(static::$requiredKeys, \array_keys($claims)); |
|
|
|
|
67
|
2 |
|
if (0 !== \count($missingKeys)) { |
68
|
1 |
|
throw new InvalidArgumentException('Invalid client metadata. Missing keys: ' . \implode(', ', $missingKeys)); |
69
|
|
|
} |
70
|
|
|
|
71
|
1 |
|
return new self($claims['client_id'], $claims); |
72
|
|
|
} |
73
|
|
|
|
74
|
2 |
|
public function getClientId(): string |
75
|
|
|
{ |
76
|
2 |
|
return $this->claims['client_id']; |
77
|
|
|
} |
78
|
|
|
|
79
|
1 |
|
public function getClientSecret(): ?string |
80
|
|
|
{ |
81
|
1 |
|
return $this->claims['client_secret'] ?? null; |
82
|
|
|
} |
83
|
|
|
|
84
|
1 |
|
public function getRedirectUris(): array |
85
|
|
|
{ |
86
|
1 |
|
return $this->claims['redirect_uris'] ?? []; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function getResponseTypes(): array |
90
|
|
|
{ |
91
|
|
|
return $this->claims['response_types'] ?? ['code']; |
92
|
|
|
} |
93
|
|
|
|
94
|
4 |
|
public function getTokenEndpointAuthMethod(): string |
95
|
|
|
{ |
96
|
4 |
|
return $this->claims['token_endpoint_auth_method']; |
97
|
|
|
} |
98
|
|
|
|
99
|
1 |
|
public function getAuthorizationSignedResponseAlg(): ?string |
100
|
|
|
{ |
101
|
1 |
|
return $this->claims['authorization_signed_response_alg'] ?? null; |
102
|
|
|
} |
103
|
|
|
|
104
|
1 |
|
public function getAuthorizationEncryptedResponseAlg(): ?string |
105
|
|
|
{ |
106
|
1 |
|
return $this->claims['authorization_encrypted_response_alg'] ?? null; |
107
|
|
|
} |
108
|
|
|
|
109
|
1 |
|
public function getAuthorizationEncryptedResponseEnc(): ?string |
110
|
|
|
{ |
111
|
1 |
|
return $this->claims['authorization_encrypted_response_enc'] ?? null; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function getIdTokenSignedResponseAlg(): string |
115
|
|
|
{ |
116
|
|
|
return $this->claims['id_token_signed_response_alg']; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
public function getIdTokenEncryptedResponseAlg(): ?string |
120
|
|
|
{ |
121
|
|
|
return $this->claims['id_token_encrypted_response_alg'] ?? null; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
public function getIdTokenEncryptedResponseEnc(): ?string |
125
|
|
|
{ |
126
|
|
|
return $this->claims['id_token_encrypted_response_enc'] ?? null; |
127
|
|
|
} |
128
|
|
|
|
129
|
1 |
|
public function getUserinfoSignedResponseAlg(): ?string |
130
|
|
|
{ |
131
|
1 |
|
return $this->claims['userinfo_signed_response_alg'] ?? null; |
132
|
|
|
} |
133
|
|
|
|
134
|
1 |
|
public function getUserinfoEncryptedResponseAlg(): ?string |
135
|
|
|
{ |
136
|
1 |
|
return $this->claims['userinfo_encrypted_response_alg'] ?? null; |
137
|
|
|
} |
138
|
|
|
|
139
|
1 |
|
public function getUserinfoEncryptedResponseEnc(): ?string |
140
|
|
|
{ |
141
|
1 |
|
return $this->claims['userinfo_encrypted_response_enc'] ?? null; |
142
|
|
|
} |
143
|
|
|
|
144
|
1 |
|
public function getRequestObjectSigningAlg(): ?string |
145
|
|
|
{ |
146
|
1 |
|
return $this->claims['request_object_signing_alg'] ?? null; |
147
|
|
|
} |
148
|
|
|
|
149
|
1 |
|
public function getRequestObjectEncryptionAlg(): ?string |
150
|
|
|
{ |
151
|
1 |
|
return $this->claims['request_object_encryption_alg'] ?? null; |
152
|
|
|
} |
153
|
|
|
|
154
|
1 |
|
public function getRequestObjectEncryptionEnc(): ?string |
155
|
|
|
{ |
156
|
1 |
|
return $this->claims['request_object_encryption_enc'] ?? null; |
157
|
|
|
} |
158
|
|
|
|
159
|
1 |
|
public function getIntrospectionEndpointAuthMethod(): string |
160
|
|
|
{ |
161
|
1 |
|
return $this->claims['introspection_endpoint_auth_method'] ?? $this->getTokenEndpointAuthMethod(); |
162
|
|
|
} |
163
|
|
|
|
164
|
1 |
|
public function getRevocationEndpointAuthMethod(): string |
165
|
|
|
{ |
166
|
1 |
|
return $this->claims['revocation_endpoint_auth_method'] ?? $this->getTokenEndpointAuthMethod(); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* @return array<string, mixed> |
171
|
|
|
*/ |
172
|
1 |
|
private function getFilteredClaims(): array |
173
|
|
|
{ |
174
|
|
|
return \array_filter($this->claims, static function ($value, string $key) { |
175
|
1 |
|
return \array_key_exists($key, static::$requiredKeys) |
|
|
|
|
176
|
1 |
|
|| $value !== (static::$defaults[$key] ?? null); |
|
|
|
|
177
|
1 |
|
}, \ARRAY_FILTER_USE_BOTH); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* @return array<string, mixed> |
182
|
|
|
*/ |
183
|
1 |
|
public function jsonSerialize(): array |
184
|
|
|
{ |
185
|
1 |
|
return $this->getFilteredClaims(); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* @param string $name |
190
|
|
|
* |
191
|
|
|
* @return bool |
192
|
|
|
*/ |
193
|
1 |
|
public function has(string $name): bool |
194
|
|
|
{ |
195
|
1 |
|
return \array_key_exists($name, $this->claims); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @param string $name |
200
|
|
|
* |
201
|
|
|
* @return mixed|null |
202
|
|
|
*/ |
203
|
2 |
|
public function get(string $name) |
204
|
|
|
{ |
205
|
2 |
|
return $this->claims[$name] ?? null; |
206
|
|
|
} |
207
|
|
|
} |
208
|
|
|
|