For most cases it is enough just to update the classname. Instead of using the old Slim\Middleware
namespace:
$app->add(new Slim\Middleware\JwtAuthentication([
"secret" => "supersecretkeyyoushouldnotcommittogithub"
]));
You should now use Tuupola\Middleware
instead:
$app->add(new Tuupola\Middleware\JwtAuthentication([
"secret" => "supersecretkeyyoushouldnotcommittogithub"
]));
Parameters callback
and passthrough
were renamed to before
and ignore
. In other words instead of doing:
$app->add(new Tuupola\Middleware\JwtAuthentication([
"passthrough" => ["/token"],
"callback" => function ($request, $response, $arguments) {
print_r($arguments);
}
]));
You should now do the following instead. Note also that $response
object is not bassed to before
anymore. The before
handler should return ``Psr\Http\Message\ServerRequestInterface`. Anything else will be ignored.
$app->add(new Tuupola\Middleware\JwtAuthentication([
"ignore" => ["/token"],
"before" => function ($request, $arguments) {
return $request->withHeader("Foo", "bar");
}
]));
Error handler signature was changed. In other words instead of doing:
$app->add(new Tuupola\Middleware\JwtAuthentication([
"error" => function ($request, $response, $arguments) {
print_r($arguments);
}
]));
You should now do the following instead.
$app->add(new Tuupola\Middleware\JwtAuthentication([
"error" => function ($response, $arguments) {
return $response->witHeader("Foo", "bar");
}
]));
Note that error
should now return an instance of Psr\Http\Message\ResponseInterface
. Anything else will be ignored.
Most public setters and getters were removed. If you had code like following:
$auth = (new Tuupola\Middleware\JwtAuthentication)
->setPath(["/admin", "/api"])
->setSecret("supersecretkeyyoushouldnotcommittogithub");
$app->add($auth);
Settings should now be passed in constructor instead:
$app->add(new Tuupola\Middleware\JwtAuthentication([
"path" => ["/admin", "/api"],
"secret" => "supersecretkeyyoushouldnotcommittogithub"
]));
The decoded token attached to the $request
object is now an array instead of an object. This might require changes to token handling code.