audience = $audience; $this->protectedHeader = $protectedHeader; } /** * {@inheritdoc} */ public function checkClaim($value): void { $this->checkValue($value, InvalidClaimException::class); } /** * {@inheritdoc} */ public function checkHeader($value): void { $this->checkValue($value, InvalidHeaderException::class); } public function supportedClaim(): string { return self::CLAIM_NAME; } public function supportedHeader(): string { return self::CLAIM_NAME; } public function protectedHeaderOnly(): bool { return $this->protectedHeader; } /** * @param mixed $value * * @throws InvalidClaimException if the claim is invalid * @throws InvalidHeaderException if the header is invalid */ private function checkValue($value, string $class): void { if (is_string($value) && $value !== $this->audience) { throw new $class('Bad audience.', self::CLAIM_NAME, $value); } if (is_array($value) && !in_array($this->audience, $value, true)) { throw new $class('Bad audience.', self::CLAIM_NAME, $value); } if (!is_array($value) && !is_string($value)) { throw new $class('Bad audience.', self::CLAIM_NAME, $value); } } }