getIntrospectionEncryptionEncValuesSupported()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TMV\OpenIdClient\Issuer\Metadata;
6
7
use function array_diff;
8
use function array_filter;
9
use const ARRAY_FILTER_USE_BOTH;
10
use function array_key_exists;
11
use function array_keys;
12
use function array_merge;
13
use function count;
14
use function implode;
15
use TMV\OpenIdClient\Exception\InvalidArgumentException;
16
17
final class IssuerMetadata implements IssuerMetadataInterface
18
{
19
    /** @var array<string, mixed> */
20
    private $metadata;
21
22
    /** @var string[] */
23
    private static $requiredKeys = [
24
        'issuer',
25
        'authorization_endpoint',
26
        'jwks_uri',
27
    ];
28
29
    /** @var array<string, mixed> */
30
    private static $defaults = [
31
        'scopes_supported' => ['openid'],
32
        'response_types_supported' => ['code', 'id_token', 'token id_token'],
33
        'response_modes_supported' => ['query', 'fragment'],
34
        'grant_types_supported' => ['authorization_code', 'implicit'],
35
        'acr_values_supported' => [],
36
        'subject_types_supported' => ['public'],
37
        'display_values_supported' => [],
38
        'claim_types_supported' => ['normal'],
39
        'claim_supported' => [],
40
41
        'claims_parameter_supported' => false,
42
        'request_parameter_supported' => false,
43
        'request_uri_parameter_supported' => true,
44
        'require_request_uri_registration' => false,
45
        'token_endpoint_auth_methods_supported' => ['client_secret_basic'],
46
        'token_endpoint_auth_signing_alg_values_supported' => ['RS256'],
47
48
        'id_token_signing_alg_values_supported' => ['RS256'],
49
        'id_token_encryption_alg_values_supported' => [],
50
        'id_token_encryption_enc_values_supported' => [],
51
52
        'userinfo_signing_alg_values_supported' => ['RS256'],
53
        'userinfo_encryption_alg_values_supported' => [],
54
        'userinfo_encryption_enc_values_supported' => [],
55
56
        'authorization_signing_alg_values_supported' => ['RS256'],
57
        'authorization_encryption_alg_values_supported' => [],
58
        'authorization_encryption_enc_values_supported' => [],
59
60
        'introspection_endpoint_auth_methods_supported' => ['client_secret_basic'],
61
        'introspection_endpoint_auth_signing_alg_values_supported' => ['RS256'],
62
63
        'introspection_signing_alg_values_supported' => ['RS256'],
64
        'introspection_encryption_alg_values_supported' => [],
65
        'introspection_encryption_enc_values_supported' => [],
66
67
        'request_object_signing_alg_values_supported' => ['RS256'],
68
        'request_object_encryption_alg_values_supported' => [],
69
        'request_object_encryption_enc_values_supported' => [],
70
71
        'revocation_endpoint_auth_methods_supported' => [],
72
        'revocation_signing_alg_values_supported' => ['RS256'],
73
74
        'frontchannel_logout_supported' => false,
75
        'frontchannel_logout_session_supported' => false,
76
        'backchannel_logout_supported' => false,
77
        'backchannel_logout_session_supported' => false,
78
        'tls_client_certificate_bound_access_tokens' => false,
79
        'mtls_endpoint_aliases' => [],
80
    ];
81
82
    /**
83
     * IssuerMetadata constructor.
84
     *
85
     * @param string $issuer
86
     * @param string $authorizationEndpoint
87
     * @param string $jwksUri
88
     * @param array<string, mixed> $claims
89
     */
90 70
    public function __construct(
91
        string $issuer,
92
        string $authorizationEndpoint,
93
        string $jwksUri,
94
        array $claims = []
95
    ) {
96
        $requiredClaims = [
97 70
            'issuer' => $issuer,
98 70
            'authorization_endpoint' => $authorizationEndpoint,
99 70
            'jwks_uri' => $jwksUri,
100
        ];
101
102 70
        $defaults = self::$defaults;
103
104 70
        $this->metadata = array_merge($defaults, $claims, $requiredClaims);
105 70
    }
106
107 1
    public static function fromArray(array $claims): self
108
    {
109 1
        $missingKeys = array_diff(self::$requiredKeys, array_keys($claims));
110 1
        if (0 !== count($missingKeys)) {
111
            throw new InvalidArgumentException('Invalid issuer metadata. Missing keys: ' . implode(', ', $missingKeys));
112
        }
113
114 1
        return new self(
115 1
            $claims['issuer'],
116 1
            $claims['authorization_endpoint'],
117 1
            $claims['jwks_uri'],
118
            $claims
119
        );
120
    }
121
122
    /**
123
     * @return string
124
     */
125 2
    public function getIssuer(): string
126
    {
127 2
        return $this->metadata['issuer'];
128
    }
129
130
    /**
131
     * @return string
132
     */
133 2
    public function getAuthorizationEndpoint(): string
134
    {
135 2
        return $this->metadata['authorization_endpoint'];
136
    }
137
138
    /**
139
     * @return string|null
140
     */
141 1
    public function getTokenEndpoint(): ?string
142
    {
143 1
        return $this->metadata['token_endpoint'];
144
    }
145
146
    /**
147
     * @return string|null
148
     */
149 1
    public function getUserinfoEndpoint(): ?string
150
    {
151 1
        return $this->metadata['userinfo_endpoint'];
152
    }
153
154
    /**
155
     * @return string|null
156
     */
157 1
    public function getRegistrationEndpoint(): ?string
158
    {
159 1
        return $this->metadata['registration_endpoint'];
160
    }
161
162
    /**
163
     * @return string
164
     */
165 2
    public function getJwksUri(): string
166
    {
167 2
        return $this->metadata['jwks_uri'];
168
    }
169
170
    /**
171
     * @return string[]
172
     */
173 1
    public function getScopesSupported(): array
174
    {
175 1
        return $this->metadata['scopes_supported'];
176
    }
177
178
    /**
179
     * @return string[]
180
     */
181 1
    public function getResponseTypesSupported(): array
182
    {
183 1
        return $this->metadata['response_types_supported'];
184
    }
185
186
    /**
187
     * @return string[]
188
     */
189 1
    public function getResponseModesSupported(): array
190
    {
191 1
        return $this->metadata['response_modes_supported'];
192
    }
193
194
    /**
195
     * @return string[]
196
     */
197 1
    public function getGrantTypesSupported(): array
198
    {
199 1
        return $this->metadata['grant_types_supported'];
200
    }
201
202
    /**
203
     * @return string[]
204
     */
205 1
    public function getAcrValuesSupported(): array
206
    {
207 1
        return $this->metadata['acr_values_supported'];
208
    }
209
210
    /**
211
     * @return string[]
212
     */
213 1
    public function getSubjectTypesSupported(): array
214
    {
215 1
        return $this->metadata['subject_types_supported'];
216
    }
217
218
    /**
219
     * @return string[]
220
     */
221 1
    public function getDisplayValuesSupported(): array
222
    {
223 1
        return $this->metadata['display_values_supported'];
224
    }
225
226
    /**
227
     * @return string[]
228
     */
229 1
    public function getClaimTypesSupported(): array
230
    {
231 1
        return $this->metadata['claim_types_supported'];
232
    }
233
234
    /**
235
     * @return string[]
236
     */
237 1
    public function getClaimSupported(): array
238
    {
239 1
        return $this->metadata['claim_supported'];
240
    }
241
242
    /**
243
     * @return string|null
244
     */
245 1
    public function getServiceDocumentation(): ?string
246
    {
247 1
        return $this->metadata['service_documentation'];
248
    }
249
250
    /**
251
     * @return string[]|null
252
     */
253 1
    public function getClaimsLocalesSupported(): ?array
254
    {
255 1
        return $this->metadata['claims_locales_supported'];
256
    }
257
258
    /**
259
     * @return string[]|null
260
     */
261 1
    public function getUiLocalesSupported(): ?array
262
    {
263 1
        return $this->metadata['ui_locales_supported'];
264
    }
265
266
    /**
267
     * @return bool
268
     */
269 2
    public function isClaimsParameterSupported(): bool
270
    {
271 2
        return $this->metadata['claims_parameter_supported'];
272
    }
273
274
    /**
275
     * @return bool
276
     */
277 2
    public function isRequestParameterSupported(): bool
278
    {
279 2
        return $this->metadata['request_parameter_supported'];
280
    }
281
282
    /**
283
     * @return bool
284
     */
285 2
    public function isRequestUriParameterSupported(): bool
286
    {
287 2
        return $this->metadata['request_uri_parameter_supported'];
288
    }
289
290
    /**
291
     * @return bool
292
     */
293 2
    public function isRequireRequestUriRegistration(): bool
294
    {
295 2
        return $this->metadata['require_request_uri_registration'];
296
    }
297
298
    /**
299
     * @return string|null
300
     */
301 1
    public function getOpPolicyUri(): ?string
302
    {
303 1
        return $this->metadata['op_policy_uri'];
304
    }
305
306
    /**
307
     * @return string|null
308
     */
309 1
    public function getOpTosUri(): ?string
310
    {
311 1
        return $this->metadata['op_tos_uri'];
312
    }
313
314
    /**
315
     * @return string[]|null
316
     */
317 1
    public function getCodeChallengeMethodsSupported(): ?array
318
    {
319 1
        return $this->metadata['code_challenge_methods_supported'];
320
    }
321
322
    /**
323
     * @return string|null
324
     */
325 1
    public function getSignedMetadata(): ?string
326
    {
327 1
        return $this->metadata['signed_metadata'];
328
    }
329
330
    /**
331
     * @return string[]
332
     */
333 1
    public function getTokenEndpointAuthMethodsSupported(): array
334
    {
335 1
        return $this->metadata['token_endpoint_auth_methods_supported'];
336
    }
337
338
    /**
339
     * @return string[]
340
     */
341 1
    public function getTokenEndpointAuthSigningAlgValuesSupported(): array
342
    {
343 1
        return $this->metadata['token_endpoint_auth_signing_alg_values_supported'];
344
    }
345
346
    /**
347
     * @return string[]
348
     */
349 1
    public function getIdTokenSigningAlgValuesSupported(): array
350
    {
351 1
        return $this->metadata['id_token_signing_alg_values_supported'];
352
    }
353
354
    /**
355
     * @return string[]
356
     */
357 1
    public function getIdTokenEncryptionAlgValuesSupported(): array
358
    {
359 1
        return $this->metadata['id_token_encryption_alg_values_supported'];
360
    }
361
362
    /**
363
     * @return string[]
364
     */
365 1
    public function getIdTokenEncryptionEncValuesSupported(): array
366
    {
367 1
        return $this->metadata['id_token_encryption_enc_values_supported'];
368
    }
369
370
    /**
371
     * @return string[]
372
     */
373 1
    public function getUserinfoSigningAlgValuesSupported(): array
374
    {
375 1
        return $this->metadata['userinfo_signing_alg_values_supported'];
376
    }
377
378
    /**
379
     * @return string[]
380
     */
381 1
    public function getUserinfoEncryptionAlgValuesSupported(): array
382
    {
383 1
        return $this->metadata['userinfo_encryption_alg_values_supported'];
384
    }
385
386
    /**
387
     * @return string[]
388
     */
389 1
    public function getUserinfoEncryptionEncValuesSupported(): array
390
    {
391 1
        return $this->metadata['userinfo_encryption_enc_values_supported'];
392
    }
393
394
    /**
395
     * @return string[]
396
     */
397 1
    public function getAuthorizationSigningAlgValuesSupported(): array
398
    {
399 1
        return $this->metadata['authorization_signing_alg_values_supported'];
400
    }
401
402
    /**
403
     * @return string[]
404
     */
405 1
    public function getAuthorizationEncryptionAlgValuesSupported(): array
406
    {
407 1
        return $this->metadata['authorization_encryption_alg_values_supported'];
408
    }
409
410
    /**
411
     * @return string[]
412
     */
413 1
    public function getAuthorizationEncryptionEncValuesSupported(): array
414
    {
415 1
        return $this->metadata['authorization_encryption_enc_values_supported'];
416
    }
417
418
    /**
419
     * @return string|null
420
     */
421 1
    public function getIntrospectionEndpoint(): ?string
422
    {
423 1
        return $this->metadata['introspection_endpoint'];
424
    }
425
426
    /**
427
     * @return string[]
428
     */
429 1
    public function getIntrospectionEndpointAuthMethodsSupported(): array
430
    {
431 1
        return $this->metadata['introspection_endpoint_auth_methods_supported'];
432
    }
433
434
    /**
435
     * @return string[]
436
     */
437 1
    public function getIntrospectionEndpointAuthSigningAlgValuesSupported(): array
438
    {
439 1
        return $this->metadata['introspection_endpoint_auth_signing_alg_values_supported'];
440
    }
441
442
    /**
443
     * @return string[]
444
     */
445 1
    public function getIntrospectionSigningAlgValuesSupported(): array
446
    {
447 1
        return $this->metadata['introspection_signing_alg_values_supported'];
448
    }
449
450
    /**
451
     * @return string[]
452
     */
453 1
    public function getIntrospectionEncryptionAlgValuesSupported(): array
454
    {
455 1
        return $this->metadata['introspection_encryption_alg_values_supported'];
456
    }
457
458
    /**
459
     * @return string[]
460
     */
461 1
    public function getIntrospectionEncryptionEncValuesSupported(): array
462
    {
463 1
        return $this->metadata['introspection_encryption_enc_values_supported'];
464
    }
465
466
    /**
467
     * @return string[]
468
     */
469 1
    public function getRequestObjectSigningAlgValuesSupported(): array
470
    {
471 1
        return $this->metadata['request_object_signing_alg_values_supported'];
472
    }
473
474
    /**
475
     * @return string[]
476
     */
477 1
    public function getRequestObjectEncryptionAlgValuesSupported(): array
478
    {
479 1
        return $this->metadata['request_object_encryption_alg_values_supported'];
480
    }
481
482
    /**
483
     * @return string[]
484
     */
485 1
    public function getRequestObjectEncryptionEncValuesSupported(): array
486
    {
487 1
        return $this->metadata['request_object_encryption_enc_values_supported'];
488
    }
489
490
    /**
491
     * @return string|null
492
     */
493 1
    public function getRevocationEndpoint(): ?string
494
    {
495 1
        return $this->metadata['revocation_endpoint'];
496
    }
497
498
    /**
499
     * @return string[]
500
     */
501 1
    public function getRevocationEndpointAuthMethodsSupported(): array
502
    {
503 1
        return $this->metadata['revocation_endpoint_auth_methods_supported'];
504
    }
505
506
    /**
507
     * @return string[]
508
     */
509 1
    public function getRevocationEndpointAuthSigningAlgValuesSupported(): array
510
    {
511 1
        return $this->metadata['revocation_endpoint_auth_signing_alg_values_supported'];
512
    }
513
514
    /**
515
     * @return string|null
516
     */
517 1
    public function getCheckSessionIframe(): ?string
518
    {
519 1
        return $this->metadata['check_session_iframe'];
520
    }
521
522
    /**
523
     * @return string|null
524
     */
525 1
    public function getEndSessionIframe(): ?string
526
    {
527 1
        return $this->metadata['end_session_iframe'];
528
    }
529
530
    /**
531
     * @return bool
532
     */
533 2
    public function isFrontchannelLogoutSupported(): bool
534
    {
535 2
        return $this->metadata['frontchannel_logout_supported'];
536
    }
537
538
    /**
539
     * @return bool
540
     */
541 2
    public function isFrontchannelLogoutSessionSupported(): bool
542
    {
543 2
        return $this->metadata['frontchannel_logout_session_supported'];
544
    }
545
546
    /**
547
     * @return bool
548
     */
549 2
    public function isBackchannelLogoutSupported(): bool
550
    {
551 2
        return $this->metadata['backchannel_logout_supported'];
552
    }
553
554
    /**
555
     * @return bool
556
     */
557 2
    public function isBackchannelLogoutSessionSupported(): bool
558
    {
559 2
        return $this->metadata['backchannel_logout_session_supported'];
560
    }
561
562
    /**
563
     * @return bool
564
     */
565 2
    public function isTlsClientCertificateBoundAccessTokens(): bool
566
    {
567 2
        return $this->metadata['tls_client_certificate_bound_access_tokens'];
568
    }
569
570
    /**
571
     * @return array<string, string>
572
     */
573 1
    public function getMtlsEndpointAliases(): array
574
    {
575 1
        return $this->metadata['mtls_endpoint_aliases'];
576
    }
577
578
    /**
579
     * @return array<string, mixed>
580
     */
581 1
    private function getFilteredClaims(): array
582
    {
583
        return array_filter($this->metadata, static function ($value, string $key) {
584 1
            return array_key_exists($key, self::$requiredKeys)
585 1
                || $value !== (self::$defaults[$key] ?? null);
586 1
        }, ARRAY_FILTER_USE_BOTH);
587
    }
588
589
    /**
590
     * @return array<string, mixed>
591
     */
592 1
    public function jsonSerialize(): array
593
    {
594 1
        return $this->getFilteredClaims();
595
    }
596
597
    /**
598
     * @param string $name
599
     *
600
     * @return bool
601
     */
602 1
    public function has(string $name): bool
603
    {
604 1
        return array_key_exists($name, $this->metadata);
605
    }
606
607
    /**
608
     * @param string $name
609
     *
610
     * @return mixed|null
611
     */
612 1
    public function get(string $name)
613
    {
614 1
        return $this->metadata[$name] ?? null;
615
    }
616
}
617