Skip to content

Commit 4a8e1c5

Browse files
ziXetjleclanche
authored andcommitted
- use "source_refresh_token" for getting the refresh_token of an access_token
- add an assertion for checking if it's returning the same refresh_token for the grace period or not.
1 parent 3e8176a commit 4a8e1c5

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

oauth2_provider/oauth2_validators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,8 +530,8 @@ def save_bearer_token(self, token, request, *args, **kwargs):
530530
else:
531531
# make sure that the token data we're returning matches
532532
# the existing token
533-
token["refresh_token"] = previous_access_token.refresh_token.token
534533
token["access_token"] = previous_access_token.token
534+
token["refresh_token"] = previous_access_token.source_refresh_token.token
535535
token["scope"] = previous_access_token.scope
536536

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

tests/test_authorization_code.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,19 +636,23 @@ def test_refresh_with_grace_period(self):
636636
"refresh_token": content["refresh_token"],
637637
"scope": content["scope"],
638638
}
639+
refresh_token = content["refresh_token"]
639640
response = self.client.post(reverse("oauth2_provider:token"), data=token_request_data, **auth_headers)
640641
self.assertEqual(response.status_code, 200)
641642

642643
content = json.loads(response.content.decode("utf-8"))
643644
self.assertTrue("access_token" in content)
644645
first_access_token = content["access_token"]
645646

646-
# check refresh token returns same data if used twice, see #497
647+
# check access token returns same data if used twice, see #497
647648
response = self.client.post(reverse("oauth2_provider:token"), data=token_request_data, **auth_headers)
648649
self.assertEqual(response.status_code, 200)
649650
content = json.loads(response.content.decode("utf-8"))
650651
self.assertTrue("access_token" in content)
651652
self.assertEqual(content["access_token"], first_access_token)
653+
# refresh token should be the same as well
654+
self.assertTrue("refresh_token" in content)
655+
self.assertEqual(content["refresh_token"], refresh_token)
652656
oauth2_settings.REFRESH_TOKEN_GRACE_PERIOD_SECONDS = 0
653657

654658
def test_refresh_invalidates_old_tokens(self):

0 commit comments

Comments
 (0)