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 3 - Fatal error: Cannot use object of type Slim\Http\Request as array #8

Closed
ronaldo-systemar opened this issue Sep 9, 2015 · 3 comments

Comments

@ronaldo-systemar
Copy link

$app->add(new \Slim\Middleware\JwtAuthentication([
    "secret" => "supersecretkeyyoushouldnotcommittogithub",
    "callback" => function ($options) use ($app) {
        $app->jwt = $options["decoded"];
    }
]));

The example above doesn't work anymore. Maybe Slim 3 is overriding properties or don't allow to set the property. Just to remeber, Slim 3 changed some concepts, since DI container appears, is not possible get app instance like this: $app = \Slim\Slim::getInstance();

@tuupola
Copy link
Owner

tuupola commented Sep 9, 2015

Use examples from Slim 3 branch README instead. Master is currently for Slim 2.

$app->add(new \Slim\Middleware\JwtAuthentication([
    "secret" => "supersecretkeyyoushouldnotcommittogithub",
    "callback" => function ($request, $response, $arguments) use ($app) {
        $app->jwt = $arguments["decoded"];
    }
]));

@ronaldo-systemar
Copy link
Author

Since we can't get $app instance inside a route callable class, what's the purpose of set $app->jwt? Sounds wrong, it's only work inside a route function() definition.

@tuupola
Copy link
Owner

tuupola commented Sep 9, 2015

Callback is just an example and that is how I happen to use it. You can of course store the the decoded value somewhere else. Or you can decide not to store it anywhere at all.

As the readme says it is up to you to implement how the token data is stored or possible authorization implemented. Middleware itself does only authentication, ie makes sure the passed token is valid. Using callback is optional. It is provided that you can do something with the decoded token when needed.

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

2 participants