tuupola / slim-jwt-auth

PSR-7 and PSR-15 JWT Authentication Middleware
https://appelsiini.net/projects/slim-jwt-auth
MIT License
828 stars 141 forks source link

\Slim\Middleware\JwtAuthentication Fatal Error with Slim v3 #69

Closed ikwijaya closed 7 years ago

ikwijaya commented 7 years ago

dear master,

i use Slim v3. but i found error middleware not found. here my require "require": { "slim/slim":"^3.0", "tuupola/slim-jwt-auth": "^3.0@RC", "monolog/monolog": "^1.23" }, and here my example code

`use Monolog\Logger; use Monolog\Handler\RotatingFileHandler; use \Slim\App; use \Slim\Container; use \Slim\Middleware\JwtAuthentication;

$config = new \Slim\Container(Config::get('settings')); $this->route = new \Slim\App($config); $this->logger = new Logger('slim'); $this->rotating = new RotatingFileHandler(Config::get('path_log') . "slim.log", 0, Logger::DEBUG); $this->logger->pushHandler($this->rotating);

    $this->jwt_config = [
        "secure" => false,
        "attribute" => "jwt",
        "path" => ["/api"],
        "logger" => $this->logger,
        "passthrough" => ["/api/token"],
        "secret" => "secret_key",
        "relaxed" => ["localhost"],
        "algorithm" => ["HS384"],
        "error" => function($request,$response,$args){
            $data['status'] = 'error';
            $data['message'] = $arguments['message'];
            return $response
                ->withJson($data,200,JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
        }
    ];
    $this->jwt_auth = new JwtAuthentication($this->jwt_config);

`

and error here Fatal error: Uncaught Error: Class 'Slim\Middleware\JwtAuthentication' not found in /home/wksadm/APPS/my_framework/backend/routes/Routes.php:40 Stack trace: #0 /home/wksadm/APPS/my_framework/backend/index.php(5): Routes->__construct() #1 {main} thrown in /home/wksadm/APPS/my_framework/backend/routes/Routes.php on line 40

what version slim i will use?

thanks for advance. ik

tuupola commented 7 years ago

You seem to be using the 3.x version which does not have stable release yet. Your code above is for the 2.x version. To fix the problem you can install the 2.x version.

Alternatively if you already want to use the new 3.x version see the 3.x README for documentation. Some things such as the classname have changed. Changes are rather small though.