Skip to content

Commit 4a86d7c

Browse files
committed
change to prevent race condition as suggested by @jdelic
1 parent 99e8c3b commit 4a86d7c

File tree

1 file changed

+3
-15
lines changed

1 file changed

+3
-15
lines changed

oauth2_provider/oauth2_validators.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -332,21 +332,9 @@ def _get_token_from_authentication_server(
332332
scope = content.get("scope", "")
333333
expires = make_aware(expires)
334334

335-
try:
336-
access_token = AccessToken.objects.select_related("application", "user").get(token=token)
337-
except AccessToken.DoesNotExist:
338-
access_token, _created = AccessToken.objects.get_or_create(
339-
token=token,
340-
user=user,
341-
application=None,
342-
scope=scope,
343-
expires=expires
344-
)
345-
else:
346-
access_token.expires = expires
347-
access_token.scope = scope
348-
access_token.save()
349-
335+
access_token = AccessToken.objects.select_related().get_or_create(token=token, user=user,
336+
application=None, scope=scope,
337+
expires=expires)
350338
return access_token
351339

352340
def validate_bearer_token(self, token, scopes, request):

0 commit comments

Comments
 (0)