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

Return 401 instead of 403 response for invalid token #760

Open
mihow opened this issue Sep 6, 2023 · 1 comment
Open

Return 401 instead of 403 response for invalid token #760

mihow opened this issue Sep 6, 2023 · 1 comment

Comments

@mihow
Copy link

mihow commented Sep 6, 2023

Right now both permission denied & invalid token errors return 403 responses. It would be nice to know if a user was actually logged out, or if a user is still logged in but isn't authorized to do something.

I am willing to fork or add a workaround if someone is able to give me guidance on where to make the change.

Thanks!

@tomwojcik
Copy link
Contributor

You're talking about a case when the token WAS valid but it either expired or was removed from the DB? If so, then I think you're right, it should rather return 401. We handle that in UserViewSet.permission_denied.

Please start by writing test cases. Once you fork and clone the repo, make init is all you need (if you have poetry).

Let me know if you need additional help!

Note that we already have some tests where 401 is returned.

./testapp/tests/test_user_detail.py:43:        self.assert_status_equal(response, status.HTTP_401_UNAUTHORIZED)
./testapp/tests/test_user_list.py:24:        self.assert_status_equal(response, status.HTTP_401_UNAUTHORIZED)
./testapp/tests/test_token_destroy.py:34:        self.assert_status_equal(response, status.HTTP_401_UNAUTHORIZED)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants