Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slim v4 support #169

Closed
dakujem opened this issue Jun 28, 2019 · 12 comments
Closed

Slim v4 support #169

dakujem opened this issue Jun 28, 2019 · 12 comments

Comments

@dakujem
Copy link
Contributor

dakujem commented Jun 28, 2019

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.

@dakujem
Copy link
Contributor Author

dakujem commented Jul 4, 2019

@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 tuupola/http-factory#9

I prepared an update that adds support for the package here:
tuupola/http-factory#10
With the changes, Slim v4 runs with the middleware as expected.

@tuupola
Copy link
Owner

tuupola commented Jul 9, 2019

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.

@tuupola
Copy link
Owner

tuupola commented Aug 7, 2019

For Slim 4 support tuupola/http-factory:^1.1 must be used.

@tuupola tuupola closed this as completed Aug 7, 2019
@gravataLonga
Copy link

@tuupola on slim 4, when require tuupola/slim-jwt-auth it's install http-factory other version. You can see this here:

https://packagist.org/packages/tuupola/slim-jwt-auth

Can you update composer.json to require 1.1 ?

@dakujem
Copy link
Contributor Author

dakujem commented Dec 4, 2020

@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.

@gravataLonga
Copy link

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

@dakujem
Copy link
Contributor Author

dakujem commented Dec 9, 2020

That's not really a problem of the middleware, is it?

@dakujem
Copy link
Contributor Author

dakujem commented Dec 9, 2020

@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));

@gravataLonga
Copy link

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));

@dakujem
Copy link
Contributor Author

dakujem commented Dec 9, 2020

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.

@gravataLonga
Copy link

gravataLonga commented Dec 9, 2020

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. ;)

@gravataLonga
Copy link

@dakujem only for reference...

PHP-DI/Slim-Bridge#51

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants