JWT implementation error

Hi,

I’m trying to implement JWT following the @odan ebook. But i have an error :

Fatal error: Uncaught TypeError: App\Middleware\JwtClaimMiddleware::__construct(): Argument #1 ($jwtAuth) must be of type App\Security\JwtAuth, null given, called in /var/www/html/vendor/slim/slim/Slim/CallableResolver.php on line 140 and defined in /var/www/html/src/Middleware/JwtClaimMiddleware.php:18 Stack trace: #0 /var/www/html/vendor/slim/slim/Slim/CallableResolver.php(140): App\Middleware\JwtClaimMiddleware->__construct(NULL) #1 /var/www/html/vendor/slim/slim/Slim/CallableResolver.php(90): Slim\CallableResolver->resolveSlimNotation('App\\Middleware\\...') #2 /var/www/html/vendor/slim/slim/Slim/CallableResolver.php(71): Slim\CallableResolver->resolveByPredicate('App\\Middleware\\...', Array, 'process') #3 /var/www/html/vendor/slim/slim/Slim/MiddlewareDispatcher.php(167): Slim\CallableResolver->resolveMiddleware('App\\Middleware\\...') #4 /var/www/html/src/Middleware/LoginMiddleware.php(21): Psr\Http\Server\RequestHandlerInterface@anonymous->handle(Object(Nyholm\Psr7\ServerRequest)) #5 /var/www/html/vendor/slim/slim/Slim/MiddlewareDispatcher.php(269): App\Middleware\LoginMiddleware->__invoke(Object(Nyholm\Psr7\ServerRequest), Object(Psr\Http\Server\RequestHandlerInterface@anonymous)) #6 /var/www/html/vendor/slim/slim/Slim/MiddlewareDispatcher.php(65): Psr\Http\Server\RequestHandlerInterface@anonymous->handle(Object(Nyholm\Psr7\ServerRequest)) #7 /var/www/html/vendor/slim/slim/Slim/App.php(199): Slim\MiddlewareDispatcher->handle(Object(Nyholm\Psr7\ServerRequest)) #8 /var/www/html/vendor/slim/slim/Slim/App.php(183): Slim\App->handle(Object(Nyholm\Psr7\ServerRequest)) #9 /var/www/html/public/index.php(3): Slim\App->run() #10 {main} thrown in /var/www/html/src/Middleware/JwtClaimMiddleware.php on line 18

I noticed an error on the line 58 of the JwtAuth.php file (src/Security/JwtAuth.php · main · LaBaude32 / pvappcore-test · GitLab) : Undefined method 'issuedBy'

Same for validateToken function :

  1. Undefined type ‘Lcobucci\JWT\Token\Plain’
  2. Undefined type ‘Lcobucci\JWT\Validation\Constraint\SignedWith’
  3. Expected type ‘Psr\Clock\ClockInterface’. Found ‘Lcobucci\Clock\SystemClock’
  4. Undefined method ‘claims’

I feel like I’ve missed something, but I really don’t know what.

Does someone have an idea ?

Thx !

There was an update in the Jwt package. Some classes has been canged. This has also been updated in the eBook. Make sure to download or use the latest version.

Hmm that’s wierd because I used the online ebook version yesterday, so that’s the last one.
I’ve just checked again and I did indeed use the last one.

must be of type App\Security\JwtAuth, null given,

This error message indicates that something is wrong with the DI container or the Slim Application setup itself.

Add the line use Slim\App; into your container.php file to define the correct Slim App (namespace) within the DI container definition.

Then try it again.

1 Like

Effectively !

Thx a lot !

1 Like