Skip to content
This repository has been archived by the owner on Nov 5, 2019. It is now read-only.

Commit

Permalink
Fall back to using an access_token for revocation.
Browse files Browse the repository at this point in the history
According to the [OAuth2
docs](https://developers.google.com/accounts/docs/OAuth2WebServer#tokenrevoke),
we can use either the refresh token or access token when revoking a token. If
we've lost the refresh token for some reason, we should fall back to revoking
via access token. (Note that if the access token has expired, this will still
raise, which is the correct behavior.)

Fixes #132.
  • Loading branch information
craigcitro committed Mar 17, 2015
1 parent d68049b commit b574bc2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 3 additions & 3 deletions oauth2client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -811,16 +811,16 @@ def _do_refresh_request(self, http_request):
raise AccessTokenRefreshError(error_msg)

def _revoke(self, http_request):
"""Revokes the refresh_token and deletes the store if available.
"""Revokes this credential and deletes the stored copy (if it exists).
Args:
http_request: callable, a callable that matches the method signature of
httplib2.Http.request, used to make the revoke request.
"""
self._do_revoke(http_request, self.refresh_token)
self._do_revoke(http_request, self.refresh_token or self.access_token)

def _do_revoke(self, http_request, token):
"""Revokes the credentials and deletes the store if available.
"""Revokes this credential and deletes the stored copy (if it exists).
Args:
http_request: callable, a callable that matches the method signature of
Expand Down
8 changes: 8 additions & 0 deletions tests/test_oauth2client.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,14 @@ def test_token_revoke_failure(self):
self, '400', revoke_raise=True,
valid_bool_value=False, token_attr='refresh_token')

def test_token_revoke_fallback(self):
original_credentials = self.credentials.to_json()
self.credentials.refresh_token = None
_token_revoke_test_helper(
self, '200', revoke_raise=False,
valid_bool_value=True, token_attr='access_token')
self.credentials = self.credentials.from_json(original_credentials)

def test_non_401_error_response(self):
http = HttpMockSequence([
({'status': '400'}, b''),
Expand Down

0 comments on commit b574bc2

Please sign in to comment.