Debian Codegraph @

lib/3rdParty/composer/facile-it/php-openid-client/src/Client/Metadata/ClientMetadata.php

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