This repository has been archived by the owner on Jan 21, 2020. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR which allows to fix/close the following issues: #97 and #106
First of all, it should be noted that explainations below assume that #92 was never merged. That fix was a mistake and it is reverted by this new PR. See #106 for more details about #92 mistakes.
Expected behavior
Current behavior
Authentication is needed for public and private resources, even if the developer makes them public. This is due to the fact that at the authentication level (authenticationPost), we are returning the response, leading to short-circuit of the route event on which authorization listeners are also attached (they have a lower priority than authentication listeners).
Thus, returning a response from the authentication layer, in case of an authentication failure or if the client get challenged, means that authorization rules for a guest identity are never evaluated and therefore, public resources are not because authentication is always required.
New behavior
Authentication layer
Authorization layer
About 401 status code vs 403 status code
Generally speaking, the 403 status code involves an authenticated user. User is authenticated but is not authorized to access the requested resource. This is generally the case when an authenticated user try to access resource owned by another user.
Currently, Apigility provides a very basic permissions system, based on HTTP methods and static identities. Access to a resource requires either an authenticated identity or a guest identity. The extended permissions system implementation, if it is required, is left to the developer. Of course, a 403 response is still send by the authorization layer in case of an unauthorized client, but only if no authentication is required (case of an already authenticated user). This will be the case if the developer implements extended permissions system (e.g, conditional ACL with assertions).
Regarding the above, it should be noted that even if authentication and authorization layers have differents concerns, this doesn't prevent one layer (e.g. the authorization layer) to be aware of the other. Furthermore, it shouldn't be forgotten that these layers are intimately linked. In other words, we can see the zf-mvc-auth module as a component that provides sub-components (authentication, authorization) which are coworkers. As such, they can share information.
Final note: Sorry for the verbosity here. I wanted to be as clear as possible.