-
Notifications
You must be signed in to change notification settings - Fork 808
Description
Describe the bug
While trying to refresh an OAuth token using an older refresh token, the server returns a 500 Internal Server Error instead of the expected 401 Unauthorized response. This occurs when an attempt is made to refresh the token with an older refresh token after it has been invalidated, resulting in a oauth2_provider.models.AccessToken.DoesNotExist error message.
To Reproduce
- Obtain a new token and a corresponding refresh token.
- Invalidate the new token by removing it (i.e., leave the "Authorization: Bearer" line empty) and attempt to refresh the token using the refresh token obtained in step 1.
- Use the new token obtained in step 2 to refresh the token again, successfully this time.
- Now, try to refresh the token using the original token obtained in step 1.
- At this point, a 500 Internal Server Error is encountered, with the error message oauth2_provider.models.AccessToken.DoesNotExist: AccessToken matching query does not exist.
Expected behavior
Upon attempting to refresh using an older or non-existent token, the server should return a 401 Unauthorized response. The system's current behavior of querying the database to find an AccessToken entry at this stage seems unnecessary and unclear.
Version
Django OAuth Toolkit Version: 2.2.0
- I have tested with the latest published release and it's still a problem.
- I have tested with the master branch and it's still a problem.
Additional context
When attempting to refresh an non-existing token the response should be Unauthorized