Fixed claim check in JwtValidator
* Removed the addRequiredClaimWithValue() method, as checking the value should be up to the implementation.
This commit is contained in:
parent
88b6247e63
commit
9d85e2ccef
@ -78,10 +78,8 @@ Parsing is done by passing the raw token as the 2nd parameter
|
|||||||
use NoccyLabs\SimpleJwt\Validator\JwtValidator;
|
use NoccyLabs\SimpleJwt\Validator\JwtValidator;
|
||||||
|
|
||||||
$validator = new JwtValidator();
|
$validator = new JwtValidator();
|
||||||
// Require that the claim exists
|
// Require that some claim exists
|
||||||
$validator->addRequiredClaim("some/required/Claim");
|
$validator->addRequiredClaim("some/required/Claim");
|
||||||
// Require that the claim exists and has a value of true
|
|
||||||
$validator->addRequiredClaimWithValue("some/required/OtherClaim", true);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Pass a JwtToken to validateToken()...
|
// Pass a JwtToken to validateToken()...
|
||||||
|
@ -21,12 +21,10 @@ class JwtValidator
|
|||||||
|
|
||||||
public function addRequiredClaim(string $name)
|
public function addRequiredClaim(string $name)
|
||||||
{
|
{
|
||||||
$this->requireClaims[$name] = true;
|
if (!in_array($name, $this->requireClaims)) {
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
public function addRequiredClaimWithValue(string $name, $value)
|
$this->requireClaims[] = $name;
|
||||||
{
|
|
||||||
$this->requireClaims[$name] = [ $value ];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function validateToken(JwtToken $token)
|
public function validateToken(JwtToken $token)
|
||||||
|
Loading…
Reference in New Issue
Block a user