Passed
Push — master ( 904589...078d26 )
by Thomas Mauro
02:52
created

getIdTokenEncryptionAlgValuesSupported()   A

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