A
A
animr2019-10-22 13:34:04
PHP
animr, 2019-10-22 13:34:04

Why doesn't the jwt class see the file in the same folder?

Guys, please tell me why an error is generated that the class does not see the file to connect:

Fatal error:  Uncaught Error: Class 'ExpiredException' not found in /var/www/****/v1/libs/php-jwt-master/src/JWT.php:136
Stack trace:
#0 /var/www/****/v1/models/ModelHeaders.php(40): JWT::decode('eyJ0eXAiOiJKV1Q...', 'Wr20wBbNpYQi9mg...', Array)
#1 /var/www/****/v1/controllers/AuthController.php(35): ModelHeaders::validationTOken('eyJ0eXAiOiJKV1Q...')
#2 /var/www/****/v1/core/Router.php(121): AuthController->actionIndex()
#3 /var/www/****/v1/index.php(30): Router->run()
#4 {main}
  thrown in /var/www/****/v1/libs/php-jwt-master/src/JWT.php on line  136

I output the code from which I am accessing:
public static function validationToken( $token ) {
    include_once ROOT. '/core/config.php';
          include_once ROOT. '/libs/php-jwt-master/src/ExpiredException.php';
          include_once ROOT. '/libs/php-jwt-master/src/BeforeValidException.php';
          include_once ROOT. '/libs/php-jwt-master/src/SignatureInvalidException.php';
          include_once ROOT. '/libs/php-jwt-master/src/JWT.php';

    $data = json_decode( $token );
    $jwt = isset( $data->jwt ) ? $data->jwt : "";

          if( $jwt ) {
        try {
                        // Ошибка в этой строке 
            $decoded = JWT::decode($jwt, $key, array('HS256'));
            http_response_code(200);
            
                        $arr = array(
                    "message" => "Доступ разрешен.",
                    "data" => $decoded->data
                );
            }
            catch (Exception $e){
                // код ответа 
                http_response_code(401);
                $arr = array(
                    "message" => "Доступ закрыт.",
                    "error" => $e->getMessage()
                );
            }
        } else{		       
            http_response_code(401);		      
            $arr = array("message" => "Доступ запрещён.");
        }
    }

Here is the JWT class itself:
class JWT
{ 

    /**
     * Decodes a JWT string into a PHP object.
     *
     * @param string        $jwt            The JWT
     * @param string|array  $key            The key, or map of keys.
     *                                      If the algorithm used is asymmetric, this is the public key
     * @param array         $allowed_algs   List of supported verification algorithms
     *                                      Supported algorithms are 'HS256', 'HS384', 'HS512' and 'RS256'
     *
     * @return object The JWT's payload as a PHP object
     *
     * @throws UnexpectedValueException     Provided JWT was invalid
     * @throws SignatureInvalidException    Provided JWT was invalid because the signature verification failed
     * @throws BeforeValidException         Provided JWT is trying to be used before it's eligible as defined by 'nbf'
     * @throws BeforeValidException         Provided JWT is trying to be used before it's been created as defined by 'iat'
     * @throws ExpiredException             Provided JWT has since expired, as defined by the 'exp' claim
     *
     * @uses jsonDecode
     * @uses urlsafeB64Decode
     */
    public static function decode($jwt, $key, array $allowed_algs = array())
    {
        //include_once ROOT. '/libs/php-jwt-master/src/ExpiredException.php';

        $timestamp = is_null(static::$timestamp) ? time() : static::$timestamp;

        if (empty($key)) {
            throw new InvalidArgumentException('Key may not be empty');
        }
        $tks = explode('.', $jwt);
        if (count($tks) != 3) {
            throw new UnexpectedValueException('Wrong number of segments');
        }
        list($headb64, $bodyb64, $cryptob64) = $tks;
        if (null === ($header = static::jsonDecode(static::urlsafeB64Decode($headb64)))) {
            throw new UnexpectedValueException('Invalid header encoding');
        }
        if (null === $payload = static::jsonDecode(static::urlsafeB64Decode($bodyb64))) {
            throw new UnexpectedValueException('Invalid claims encoding');
        }
        if (false === ($sig = static::urlsafeB64Decode($cryptob64))) {
            throw new UnexpectedValueException('Invalid signature encoding');
        }
        if (empty($header->alg)) {
            throw new UnexpectedValueException('Empty algorithm');
        }
        if (empty(static::$supported_algs[$header->alg])) {
            throw new UnexpectedValueException('Algorithm not supported');
        }
        if (!in_array($header->alg, $allowed_algs)) {
            throw new UnexpectedValueException('Algorithm not allowed');
        }
        if (is_array($key) || $key instanceof \ArrayAccess) {
            if (isset($header->kid)) {
                if (!isset($key[$header->kid])) {
                    throw new UnexpectedValueException('"kid" invalid, unable to lookup correct key');
                }
                $key = $key[$header->kid];
            } else {
                throw new UnexpectedValueException('"kid" empty, unable to lookup correct key');
            }
        }

        // Check the signature
        if (!static::verify("$headb64.$bodyb64", $sig, $key, $header->alg)) {
            throw new SignatureInvalidException('Signature verification failed');
        }

        // Check if the nbf if it is defined. This is the time that the
        // token can actually be used. If it's not yet that time, abort.
        if (isset($payload->nbf) && $payload->nbf > ($timestamp + static::$leeway)) {
            throw new BeforeValidException(
                'Cannot handle token prior to ' . date(DateTime::ISO8601, $payload->nbf)
            );
        }

        // Check that this token has been created before 'now'. This prevents
        // using tokens that have been created for later use (and haven't
        // correctly used the nbf claim).
        if (isset($payload->iat) && $payload->iat > ($timestamp + static::$leeway)) {
            throw new BeforeValidException(
                'Cannot handle token prior to ' . date(DateTime::ISO8601, $payload->iat)
            );
        }

        // Check if this token has expired.
        if (isset($payload->exp) && ($timestamp - static::$leeway) >= $payload->exp) {

//Тут не может класс подключить

            throw new ExpiredException('Expired token');
        }

        return $payload;
    }
   
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question