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

PHP Fatal error: Class 'Tuupola\\Middleware\\JwtAuthentication' not found #145

Closed jasmin83 closed 5 years ago

jasmin83 commented 5 years ago

Hi,

I have xampp installed and the php version is 5.6.

After composer installed 'tuupola/slim-jwt-auth' package, I am getting 'PHP Fatal error: Class 'Tuupola\Middleware\JwtAuthentication' not found' error.

below is my code:

$app = new Slim\App;

// e.g: $app->add(new \Slim\Csrf\Guard); $app->add(new Tuupola\Middleware\JwtAuthentication([ "path" => "/api", / or ["/api", "/admin"] / "attribute" => "decoded_token_data", "secure" => false, "secret" => "supersecretkeyyoushouldnotcommittogithub", "algorithm" => ["HS256"], "error" => function ($response, $arguments) { $data["status"] = "error"; $data["message"] = $arguments["message"]; return $response ->withHeader("Content-Type", "application/json") ->write(json_encode($data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT)); } ]));

use \Firebase\JWT\JWT;

When I hit API using postman, I am getting below error: Fatal error: Class 'Tuupola\Middleware\JwtAuthentication' not found in

Please suggest me to solve this issue.

Thanks.

tuupola commented 5 years ago

You have installed the older 2.x version which has different namespace. Instead of Tuupola\Middleware\JwtAuthentication older version uses Slim\Middleware\JwtAuthentication.

There are some other smaller differences too. So make sure you are following the older README.

jasmin83 commented 5 years ago

Hi,

Thanks..now I am able to generate token.

I have a question, in slim framework 3 - how to get token from header and authenticate.? Please guide me.

Thanks

On Wed, Jan 2, 2019 at 3:36 PM Mika Tuupola notifications@github.com wrote:

You have installed the older 2.x https://github.com/tuupola/slim-jwt-auth/tree/2.x version which has different namespace. Instead of Tuupola\Middleware\JwtAuthentication older version uses Slim\Middleware\JwtAuthentication.

There are some other smaller differences too. So make sure you are following the older README https://github.com/tuupola/slim-jwt-auth/blob/2.x/README.md.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/tuupola/slim-jwt-auth/issues/145#issuecomment-450825553, or mute the thread https://github.com/notifications/unsubscribe-auth/AsK3BM7ZntrllfjvScSpeXr65PSjUZrGks5u_IS6gaJpZM4ZmZJo .

tuupola commented 5 years ago

This middleware does authentication automatically. It is the purpose if this middleware.

If you use some other header than default Authorization: Bearer xxxx you might need to change the header and regexp settings though.