I have implemented tymon/jwt-auth version 1.0.0-rc4.1 as third-party in my Lumen(5.8.4) application and now when I continue with implementing Authetication with Dingo following https://github.com/dingo/api/wiki/Authentication at step where I need to add this (or any other way registering jwt with dingo)
app('Dingo\Api\Auth\Auth')->extend('jwt', function ($app) {
return new Dingo\Api\Auth\Provider\JWT($app['Tymon\JWTAuth\JWTAuth']);
});
to app.php I get this error
Error: Target [Dingo\Api\Contract\Routing\Adapter] is not instantiable while building [Dingo\Api\Auth\Auth, Dingo\Api\Routing\Router].
I think I've searched and tried all the things that exists on internet on this theme because I'm working on it for 2 days, and most of them are using old version of dingo and/or Lumen. I've also tried different adapters I've found on git but non of them works.
This is my setup: composer.json:
"require": {
"php": ">=7.1.3",
"dingo/api": "^2",
"flipbox/lumen-generator": "^5.6",
"laravel/lumen-framework": "5.8.*",
"nesbot/carbon": "^2.17",
"tymon/jwt-auth": "1.0.0-rc4.1",
"vlucas/phpdotenv": "^3.3"
}
app.php
app('Dingo\Api\Auth\Auth')->extend('jwt', function ($app) {
return new Dingo\Api\Auth\Provider\JWT($app['Tymon\JWTAuth\JWTAuth']);
}); <- this makes problem, without this everything works, I even get jwt in postman
$app->register(Tymon\JWTAuth\Providers\LumenServiceProvider::class);
$app->register(Dingo\Api\Provider\LumenServiceProvider::class);
$app->register(App\Providers\AppServiceProvider::class);
$app->register(App\Providers\AuthServiceProvider::class);
Anyone worked with implementation on newer versions, or have some better way of doing this? I've tried one working example https://github.com/krisanalfa/lumen-jwt but as I saw last update was 2 years ago and Lumen version is 5.4. Should I maybe use it or it is deprecated?
OK, I've finally get it to work. If someone run into the same problem, I've done next, in AppServiceProvider I've registered
and in boot method in the same file:
in auth.php
in jwt.php
and then protect route, for example:
Also, quick note, if you are having an Exception "Token Signature Could not be verified", remove quotes when sending jwt through POSTMAN :)
Best regards.