Skip to content

Commit 6d0c513

Browse files
Maronatoauvipy
authored andcommitted
return new refresh token during grace period (#703)
1 parent dc429ad commit 6d0c513

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

oauth2_provider/oauth2_validators.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,9 @@ def save_bearer_token(self, token, request, *args, **kwargs):
551551
# make sure that the token data we're returning matches
552552
# the existing token
553553
token["access_token"] = previous_access_token.token
554-
token["refresh_token"] = previous_access_token.source_refresh_token.token
554+
token["refresh_token"] = RefreshToken.objects.filter(
555+
access_token=previous_access_token
556+
).first().token
555557
token["scope"] = previous_access_token.scope
556558

557559
# No refresh token should be created, just access token

tests/test_authorization_code.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -672,13 +672,14 @@ def test_refresh_with_grace_period(self):
672672
"refresh_token": content["refresh_token"],
673673
"scope": content["scope"],
674674
}
675-
refresh_token = content["refresh_token"]
675+
676676
response = self.client.post(reverse("oauth2_provider:token"), data=token_request_data, **auth_headers)
677677
self.assertEqual(response.status_code, 200)
678678

679679
content = json.loads(response.content.decode("utf-8"))
680680
self.assertTrue("access_token" in content)
681681
first_access_token = content["access_token"]
682+
first_refresh_token = content["refresh_token"]
682683

683684
# check access token returns same data if used twice, see #497
684685
response = self.client.post(reverse("oauth2_provider:token"), data=token_request_data, **auth_headers)
@@ -688,7 +689,7 @@ def test_refresh_with_grace_period(self):
688689
self.assertEqual(content["access_token"], first_access_token)
689690
# refresh token should be the same as well
690691
self.assertTrue("refresh_token" in content)
691-
self.assertEqual(content["refresh_token"], refresh_token)
692+
self.assertEqual(content["refresh_token"], first_refresh_token)
692693
oauth2_settings.REFRESH_TOKEN_GRACE_PERIOD_SECONDS = 0
693694

694695
def test_refresh_invalidates_old_tokens(self):

0 commit comments

Comments
 (0)