-
Notifications
You must be signed in to change notification settings - Fork 112
Embracing middlewares #307
Description
Hi everyone,
In overall, this package has been very stable over the last few months, and I'd like to think about the future of it.
With the increase of API, and tools like Zend\Expressive, it may be interesting to simplify this package. I'd like to support two different branches: 2.x that would be based as a ZF2 module, and a 3.x branch, that would remove dependency completely toward ZF, and embrace middlewares and an API first design.
Here are the various things I'm thinking, let me know if you have any suggestion.
Removing guards
Guards were nice, but to be honest, they were a bit problematic. They were tied very strongly to the ZF2 router / ZF2 MVC model, and while useful to "guard" a bunch of route (/admin/*), the advent of middlewares allow to create much better solution to this issue.
Also, guards introduced potential security issue, as some methods could be called outside the context of a route/controller, hence bypassing the guard.
This also made testing harder, because, well... testing taht kind of things is hard because it's 100% config.
Instead, we should encourage people to check their permissions at the controller/service level. I've always done it at the controller level, and it was super nice. Very easy to see which permissions were needed, very easy to test...
** Removed dependencies **: zend\mvc
Removing views
As a package that would be API driven does not need the views anymore.
** Removed dependencies ** : zend\view
Removing collector and various ZfTool
No longer really needed, and we don't have yet a tool for that in middleware's world.
Authentication
ZfcRbac would no longer rely on Zend\Authentication. Instead, the isGranted
signature would be changed so that the first parameter is an IdentityInterface
:
interface AuthorizationServiceInterface
{
public function isGranted(IdentityInterface $identity, $permission, $context = null);
}
Consumer would be responsible to extract it. In PSR-7, each request can be set attribute, for instance here is a possible controller:
public function fooAction(ServerRequestInterface $request)
{
$identity = $request->getAttribute('logged_user');
if ($this->authService->isGranted($identity, 'my_perm', ['context' => 'bar']) {
}
}
Maybe we could provide some simple, common interfaces for retrieving logged identity, I'm not so sure.
ping @danizord @weierophinney