Skip to content

Commit 86ca379

Browse files
committed
Revert "change to prevent race condition as suggested by @jdelic"
This reverts commit 4a86d7c.
1 parent 4a86d7c commit 86ca379

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

oauth2_provider/oauth2_validators.py

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

335-
access_token = AccessToken.objects.select_related().get_or_create(token=token, user=user,
336-
application=None, scope=scope,
337-
expires=expires)
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+
338350
return access_token
339351

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

0 commit comments

Comments
 (0)