Closed dakujem closed 5 years ago
@tuupola Mika, as stupid as the above question might seem (considering that both Slim v3 and Slim v4 are PSR-7 compatible), currently the middleware does not work with Slim v4 when used together with slim/psr7
(one of the HTTP providers).\
See https://github.com/tuupola/http-factory/issues/9
I prepared an update that adds support for the package here: https://github.com/tuupola/http-factory/pull/10 With the changes, Slim v4 runs with the middleware as expected.
Slim 4 will have PSR-15 support so this middleware should be supported too. Currently the problem is that tuupola/http-factory
does not yet autodetect the new slim/psr7
. I believe your PR should fix this problem. Will check on it soon.
For Slim 4 support tuupola/http-factory:^1.1
must be used.
@tuupola on slim 4, when require tuupola/slim-jwt-auth
it's install http-factory
other version. You can see this here:
Can you update composer.json
to require 1.1
?
@gravataLonga
All versions of tuupola/slim-jwt-auth
since version 3.1.1
can install http-factory
version 1.1
, since ^1.0.2
is forward-compatible with 1.1
. Read more here: Semantic versioning
Observe the requirement on packagist (as per the link you sent abovce):
tuupola/http-factory: ^0.4.0|^1.0.2
You probably want to call composer update tuupola/*
\
or check why the specific version is blocked by running composer why tuupola/http-factory
,\
also check what version of the middleware you are running composer show tuupola/slim-jwt-auth
, you need 3.1.1
or above.
Yeah, that is true, but got this issue when using with php-di
:
Argument 2 passed to Tuupola\Middleware\JwtAuthentication::__invoke() must be an instance of Psr\Http\Message\ResponseInterface, instance of Slim\Routing\Route given
That's not really a problem of the middleware, is it?
@gravataLonga you are obviously doing something wrong. PHP-DI has nothing to do with it.
Here, let mi give you a tip. There are basically 3 possible cases how you add this (or any other) middleware to slim (both v3 and v4), to the whole app, to a certain group or to a single route:
$slim = new Slim\App(...);
$authOptions = [...];
// add to the whole app / middleware stack
$slim->add(new JwtAuthentication($authOptions));
$slim
->group('/foo', function ($group) use ($authOptions) {
$group
->get('/bar', function (Request $request, Response $response) {
echo 'The end. 42';
})
// add to the single route
->add(new JwtAuthentication($authOptions));
})
// add to the whole group
->add(new JwtAuthentication($authOptions));
I'm obviously not doing something wrong, if you get class from container it will work. Take this example:
This not work:
$app = new App();
// ... some code boot, container, php-di, etc.
$app->get('/jwt', function (Request $request, Response $response) {
return $response->json($request->getAttribute('token'));
})->add(JwtAuthentication::class);
This will work:
$app = new App();
// ... some code boot, container, php-di, etc.
$app->get('/jwt', function (Request $request, Response $response) {
return $response->json($request->getAttribute('token'));
})->add($container->get(JwtAuthentication::class));
And again, it's not a problem of this middleware.
First, check the callable resolver you are using, this is most problably your misconfiguration issue. If you still think that it is a bug, I suggest you file an issue with either Slim or PHP-DI.
I'm don't think that is a bug of this middleware, only point out that the problem is another than "i'm don't known what are doing". Will try to debugging.. and yes, i'm think the problem is php-di. ;)
@dakujem only for reference...
Any plans to support the upcomming Slim v4?
I'm currently starting to build an app based on v3, but decided to switch to Slim v4 (http://slim-website.lgse.com/docs/v4/start/upgrade.html), so it might be a good opportunity to also help with the integration, I have not yet startet to investigate whether the changes in Slim v4 actually mean any changes to this middleware are needed.