From 9d85e2ccef6eb9b6b4af8e8226a26e96ef3e0ce5 Mon Sep 17 00:00:00 2001 From: Christopher Vagnetoft Date: Thu, 11 Feb 2021 13:32:10 +0100 Subject: [PATCH] Fixed claim check in JwtValidator * Removed the addRequiredClaimWithValue() method, as checking the value should be up to the implementation. --- README.md | 4 +--- src/Validator/JwtValidator.php | 10 ++++------ 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index aaf6100..7af598d 100644 --- a/README.md +++ b/README.md @@ -78,10 +78,8 @@ Parsing is done by passing the raw token as the 2nd parameter use NoccyLabs\SimpleJwt\Validator\JwtValidator; $validator = new JwtValidator(); - // Require that the claim exists + // Require that some claim exists $validator->addRequiredClaim("some/required/Claim"); - // Require that the claim exists and has a value of true - $validator->addRequiredClaimWithValue("some/required/OtherClaim", true); try { // Pass a JwtToken to validateToken()... diff --git a/src/Validator/JwtValidator.php b/src/Validator/JwtValidator.php index e776cd7..407f8ba 100644 --- a/src/Validator/JwtValidator.php +++ b/src/Validator/JwtValidator.php @@ -21,12 +21,10 @@ class JwtValidator public function addRequiredClaim(string $name) { - $this->requireClaims[$name] = true; - } - - public function addRequiredClaimWithValue(string $name, $value) - { - $this->requireClaims[$name] = [ $value ]; + if (!in_array($name, $this->requireClaims)) { + return; + } + $this->requireClaims[] = $name; } public function validateToken(JwtToken $token)