Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return the new refresh token during grace period (#702) #703

Merged
merged 1 commit into from
Apr 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion oauth2_provider/oauth2_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,9 @@ def save_bearer_token(self, token, request, *args, **kwargs):
# make sure that the token data we're returning matches
# the existing token
token["access_token"] = previous_access_token.token
token["refresh_token"] = previous_access_token.source_refresh_token.token
token["refresh_token"] = RefreshToken.objects.filter(
access_token=previous_access_token
).first().token
token["scope"] = previous_access_token.scope

# No refresh token should be created, just access token
Expand Down
5 changes: 3 additions & 2 deletions tests/test_authorization_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,13 +672,14 @@ def test_refresh_with_grace_period(self):
"refresh_token": content["refresh_token"],
"scope": content["scope"],
}
refresh_token = content["refresh_token"]

response = self.client.post(reverse("oauth2_provider:token"), data=token_request_data, **auth_headers)
self.assertEqual(response.status_code, 200)

content = json.loads(response.content.decode("utf-8"))
self.assertTrue("access_token" in content)
first_access_token = content["access_token"]
first_refresh_token = content["refresh_token"]

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

def test_refresh_invalidates_old_tokens(self):
Expand Down