Skip to content
This repository has been archived by the owner on Apr 3, 2023. It is now read-only.

Error 404 on route GET users/{id} when not logged in #30

Open
TeddyRoncin opened this issue May 10, 2022 · 2 comments
Open

Error 404 on route GET users/{id} when not logged in #30

TeddyRoncin opened this issue May 10, 2022 · 2 comments
Assignees
Labels
Bug 🐛 Something isn't working or don't work correctly

Comments

@TeddyRoncin
Copy link
Member

Description

When you make a request on route GET users/{id}, API returns an error 404 (Resource not found), even if user was found. It should return an error 401 (Unauthorized), both in the case the user does not exist and in the case it does exist
image

There is a problem that occurs in the same situation when doing tests :
image
However, the problem is not the same, this is an error, and the problem I described earlier was a bug

Investigation of the issue

I tried changing function supports of class App\DataProvider\UserDataVisibilityItemDataProvider to make it also check for login : $checkLogin = $this->security->getUser() != null;.
This fixes the issue in tests :
image
This fix does not change anything in a normal call. It seems like by changing this function, the getItem method of the same class is not called anymore (which is the behaviour we would expect). But APIPlateform still returns a 404 code instead of a 401 code

@TeddyRoncin TeddyRoncin added the Bug 🐛 Something isn't working or don't work correctly label May 10, 2022
TeddyRoncin pushed a commit that referenced this issue May 17, 2022
Now method UserDataVisibilityItemProvider::supports cannot return true if user is not logged in. The method "supports"
of authenticator now always return true : if CAS-LOGIN is not set, then we know the user is not logged in. It makes
unauthorized responses (401) cleaner, and you cannot see the stacktrace anymore

Closes #30
@TeddyRoncin
Copy link
Member Author

The same error occurs on route DELETE /users/{id}. It seems like all routes which need to fetch a single User (maybe other Entities ?) have this problem

@TeddyRoncin
Copy link
Member Author

I think the problem might be that the ApiPlatform\Symfony\EventListener\ReadListener listener is called before the security checks. The ReadListener is called when the kernel.request event is called, with a priority of 4. It may be possible to modify the order of events by fetching the main instance of Symfony\Component\EventDispatcher\EventDispatcher to add and remove listeners.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug 🐛 Something isn't working or don't work correctly
Projects
None yet
Development

No branches or pull requests

2 participants