Fixed capitalization, tests
This commit is contained in:
9
src/Validator/JWTClaimException.php
Normal file
9
src/Validator/JWTClaimException.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace NoccyLabs\SimpleJWT\Validator;
|
||||
|
||||
|
||||
class JWTClaimException extends JWTValidatorException
|
||||
{
|
||||
|
||||
}
|
8
src/Validator/JWTHeaderException.php
Normal file
8
src/Validator/JWTHeaderException.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace NoccyLabs\SimpleJWT\Validator;
|
||||
|
||||
class JWTHeaderException extends JWTValidatorException
|
||||
{
|
||||
|
||||
}
|
8
src/Validator/JWTTokenException.php
Normal file
8
src/Validator/JWTTokenException.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace NoccyLabs\SimpleJWT\Validator;
|
||||
|
||||
class JWTTokenException extends JWTValidatorException
|
||||
{
|
||||
|
||||
}
|
@@ -1,11 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace NoccyLabs\SimpleJwt\Validator;
|
||||
namespace NoccyLabs\SimpleJWT\Validator;
|
||||
|
||||
use NoccyLabs\SimpleJwt\JwtToken;
|
||||
use NoccyLabs\SimpleJwt\Key\KeyInterface;
|
||||
use NoccyLabs\SimpleJWT\JWTToken;
|
||||
use NoccyLabs\SimpleJWT\Key\KeyInterface;
|
||||
|
||||
class JwtValidator
|
||||
class JWTValidator
|
||||
{
|
||||
private $requireHeaders = [];
|
||||
|
||||
@@ -41,32 +41,32 @@ class JwtValidator
|
||||
$this->requireAudience = (array)$audience;
|
||||
}
|
||||
|
||||
public function validateToken(JwtToken $token)
|
||||
public function validateToken(JWTToken $token)
|
||||
{
|
||||
if (!$token->isValid()) {
|
||||
throw new JwtTokenException("The token is not valid");
|
||||
throw new JWTTokenException("The token is not valid");
|
||||
}
|
||||
|
||||
if (!$token->header->hasAll($this->requireHeaders)) {
|
||||
throw new JwtHeaderException("The token is missing one or more required headers");
|
||||
throw new JWTHeaderException("The token is missing one or more required headers");
|
||||
}
|
||||
|
||||
if (!$token->claims->hasAll($this->requireClaims)) {
|
||||
throw new JwtHeaderException("The token is missing one or more required claims");
|
||||
throw new JWTHeaderException("The token is missing one or more required claims");
|
||||
}
|
||||
|
||||
if ($this->requireIssuer) {
|
||||
$hasIssuer = $token->header->has("iss");
|
||||
if ((!$hasIssuer)
|
||||
|| (!in_array($token->header->get("iss"), $this->requireIssuer)))
|
||||
throw new JwtTokenException("Invalid issuer");
|
||||
throw new JWTTokenException("Invalid issuer");
|
||||
}
|
||||
|
||||
if ($this->requireAudience) {
|
||||
$hasAudience = $token->header->has("aud");
|
||||
if ((!$hasAudience)
|
||||
|| (!in_array($token->header->get("aud"), $this->requireAudience)))
|
||||
throw new JwtTokenException("Invalid audience");
|
||||
throw new JWTTokenException("Invalid audience");
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -74,7 +74,7 @@ class JwtValidator
|
||||
|
||||
public function validate(KeyInterface $key, string $raw)
|
||||
{
|
||||
$token = new JwtToken($key, $raw);
|
||||
$token = new JWTToken($key, $raw);
|
||||
if ($this->validateToken($token)) {
|
||||
return $token;
|
||||
}
|
8
src/Validator/JWTValidatorException.php
Normal file
8
src/Validator/JWTValidatorException.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace NoccyLabs\SimpleJWT\Validator;
|
||||
|
||||
class JWTValidatorException extends \RuntimeException
|
||||
{
|
||||
|
||||
}
|
@@ -1,9 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace NoccyLabs\SimpleJwt\Validator;
|
||||
|
||||
|
||||
class JwtClaimException extends JwtValidatorException
|
||||
{
|
||||
|
||||
}
|
@@ -1,8 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace NoccyLabs\SimpleJwt\Validator;
|
||||
|
||||
class JwtHeaderException extends JwtValidatorException
|
||||
{
|
||||
|
||||
}
|
@@ -1,8 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace NoccyLabs\SimpleJwt\Validator;
|
||||
|
||||
class JwtTokenException extends JwtValidatorException
|
||||
{
|
||||
|
||||
}
|
@@ -1,8 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace NoccyLabs\SimpleJwt\Validator;
|
||||
|
||||
class JwtValidatorException extends \RuntimeException
|
||||
{
|
||||
|
||||
}
|
Reference in New Issue
Block a user