Debian Codegraph @

lib/3rdParty/composer/web-token/jwt-library/Checker/IssuerChecker.php

raw symbols SCIP
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Jose\Component\Checker;
6
7 use function in_array;
8 use function is_string;
9
10 /**
11 * This class is a header parameter and claim checker. When the "iss" header parameter or claim is present, it will
12 * check if the value is within the allowed ones.
13 */
14 final class IssuerChecker implements ClaimChecker, HeaderChecker
15 {
16 private const CLAIM_NAME = 'iss';
17
18 public function __construct(
19 private readonly array $issuers,
20 private readonly bool $protectedHeader = false
21 ) {
22 }
23
24 public function checkClaim(mixed $value): void
25 {
26 $this->checkValue($value, InvalidClaimException::class);
27 }
28
29 public function checkHeader(mixed $value): void
30 {
31 $this->checkValue($value, InvalidHeaderException::class);
32 }
33
34 public function supportedClaim(): string
35 {
36 return self::CLAIM_NAME;
37 }
38
39 public function supportedHeader(): string
40 {
41 return self::CLAIM_NAME;
42 }
43
44 public function protectedHeaderOnly(): bool
45 {
46 return $this->protectedHeader;
47 }
48
49 private function checkValue(mixed $value, string $class): void
50 {
51 if (! is_string($value)) {
52 throw new $class('Invalid value.', self::CLAIM_NAME, $value);
53 }
54 if (! in_array($value, $this->issuers, true)) {
55 throw new $class('Unknown issuer.', self::CLAIM_NAME, $value);
56 }
57 }
58 }