Token refresh to work with 'old' GData API
Contributed by crhyme. Reviewed in http://codereview.appspot.com/6373049/.
This commit is contained in:
@@ -416,8 +416,9 @@ class OAuth2Credentials(Credentials):
|
||||
resp, content = request_orig(uri, method, body, headers,
|
||||
redirections, connection_type)
|
||||
|
||||
if resp.status == 401:
|
||||
logger.info('Refreshing due to a 401')
|
||||
# Older API (GData) respond with 403
|
||||
if resp.status in [401, 403]:
|
||||
logger.info('Refreshing due to a %s' % str(resp.status))
|
||||
self._refresh(request_orig)
|
||||
self.apply(headers)
|
||||
return request_orig(uri, method, body, headers,
|
||||
|
||||
@@ -99,8 +99,10 @@ class OAuth2CredentialsTests(unittest.TestCase):
|
||||
user_agent)
|
||||
|
||||
def test_token_refresh_success(self):
|
||||
# Older API (GData) respond with 403
|
||||
for status_code in ['401', '403']:
|
||||
http = HttpMockSequence([
|
||||
({'status': '401'}, ''),
|
||||
({'status': status_code}, ''),
|
||||
({'status': '200'}, '{"access_token":"1/3w","expires_in":3600}'),
|
||||
({'status': '200'}, 'echo_request_headers'),
|
||||
])
|
||||
@@ -110,8 +112,10 @@ class OAuth2CredentialsTests(unittest.TestCase):
|
||||
self.assertFalse(self.credentials.access_token_expired)
|
||||
|
||||
def test_token_refresh_failure(self):
|
||||
# Older API (GData) respond with 403
|
||||
for status_code in ['401', '403']:
|
||||
http = HttpMockSequence([
|
||||
({'status': '401'}, ''),
|
||||
({'status': status_code}, ''),
|
||||
({'status': '400'}, '{"error":"access_denied"}'),
|
||||
])
|
||||
http = self.credentials.authorize(http)
|
||||
@@ -148,8 +152,10 @@ class AccessTokenCredentialsTests(unittest.TestCase):
|
||||
self.credentials = AccessTokenCredentials(access_token, user_agent)
|
||||
|
||||
def test_token_refresh_success(self):
|
||||
# Older API (GData) respond with 403
|
||||
for status_code in ['401', '403']:
|
||||
http = HttpMockSequence([
|
||||
({'status': '401'}, ''),
|
||||
({'status': status_code}, ''),
|
||||
])
|
||||
http = self.credentials.authorize(http)
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user