| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Facile\JoseVerifier\Internal\Checker; |
| 6 |
|
| 7 |
use Jose\Component\Checker\ClaimChecker; |
| 8 |
use Jose\Component\Checker\InvalidClaimException; |
| 9 |
|
| 10 |
use function sprintf; |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
final class NonceChecker implements ClaimChecker |
| 16 |
{ |
| 17 |
private const CLAIM_NAME = 'nonce'; |
| 18 |
|
| 19 |
private string $nonce; |
| 20 |
|
| 21 |
public function __construct(string $nonce) |
| 22 |
{ |
| 23 |
$this->nonce = $nonce; |
| 24 |
} |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
public function checkClaim($value): void |
| 32 |
{ |
| 33 |
if ($value !== $this->nonce) { |
| 34 |
throw new InvalidClaimException(sprintf('Nonce mismatch, expected %s, got: %s', $this->nonce, (string) $value), self::CLAIM_NAME, $value); |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
public function supportedClaim(): string |
| 39 |
{ |
| 40 |
return self::CLAIM_NAME; |
| 41 |
} |
| 42 |
} |