Skip to content

Commit

Permalink
fix(#638): concurrency issue on new token from refresh token
Browse files Browse the repository at this point in the history
(cherry picked from commit 199e818)
  • Loading branch information
gbataille authored and jleclanche committed Oct 2, 2018
1 parent 1157361 commit f47483e
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions oauth2_provider/oauth2_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,12 @@ def save_bearer_token(self, token, request, *args, **kwargs):
else:
# revoke existing tokens if possible to allow reuse of grant
if isinstance(refresh_token_instance, RefreshToken):
# First, to ensure we don't have concurrency issues, we refresh the refresth token
# from the db while acquiring a lock on it
refresh_token_instance = RefreshToken.objects.select_for_update().get(
id=refresh_token_instance.id
)

previous_access_token = AccessToken.objects.filter(
source_refresh_token=refresh_token_instance
).first()
Expand Down

0 comments on commit f47483e

Please sign in to comment.