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,
|
resp, content = request_orig(uri, method, body, headers,
|
||||||
redirections, connection_type)
|
redirections, connection_type)
|
||||||
|
|
||||||
if resp.status == 401:
|
# Older API (GData) respond with 403
|
||||||
logger.info('Refreshing due to a 401')
|
if resp.status in [401, 403]:
|
||||||
|
logger.info('Refreshing due to a %s' % str(resp.status))
|
||||||
self._refresh(request_orig)
|
self._refresh(request_orig)
|
||||||
self.apply(headers)
|
self.apply(headers)
|
||||||
return request_orig(uri, method, body, headers,
|
return request_orig(uri, method, body, headers,
|
||||||
|
|||||||
@@ -99,8 +99,10 @@ class OAuth2CredentialsTests(unittest.TestCase):
|
|||||||
user_agent)
|
user_agent)
|
||||||
|
|
||||||
def test_token_refresh_success(self):
|
def test_token_refresh_success(self):
|
||||||
|
# Older API (GData) respond with 403
|
||||||
|
for status_code in ['401', '403']:
|
||||||
http = HttpMockSequence([
|
http = HttpMockSequence([
|
||||||
({'status': '401'}, ''),
|
({'status': status_code}, ''),
|
||||||
({'status': '200'}, '{"access_token":"1/3w","expires_in":3600}'),
|
({'status': '200'}, '{"access_token":"1/3w","expires_in":3600}'),
|
||||||
({'status': '200'}, 'echo_request_headers'),
|
({'status': '200'}, 'echo_request_headers'),
|
||||||
])
|
])
|
||||||
@@ -110,8 +112,10 @@ class OAuth2CredentialsTests(unittest.TestCase):
|
|||||||
self.assertFalse(self.credentials.access_token_expired)
|
self.assertFalse(self.credentials.access_token_expired)
|
||||||
|
|
||||||
def test_token_refresh_failure(self):
|
def test_token_refresh_failure(self):
|
||||||
|
# Older API (GData) respond with 403
|
||||||
|
for status_code in ['401', '403']:
|
||||||
http = HttpMockSequence([
|
http = HttpMockSequence([
|
||||||
({'status': '401'}, ''),
|
({'status': status_code}, ''),
|
||||||
({'status': '400'}, '{"error":"access_denied"}'),
|
({'status': '400'}, '{"error":"access_denied"}'),
|
||||||
])
|
])
|
||||||
http = self.credentials.authorize(http)
|
http = self.credentials.authorize(http)
|
||||||
@@ -148,8 +152,10 @@ class AccessTokenCredentialsTests(unittest.TestCase):
|
|||||||
self.credentials = AccessTokenCredentials(access_token, user_agent)
|
self.credentials = AccessTokenCredentials(access_token, user_agent)
|
||||||
|
|
||||||
def test_token_refresh_success(self):
|
def test_token_refresh_success(self):
|
||||||
|
# Older API (GData) respond with 403
|
||||||
|
for status_code in ['401', '403']:
|
||||||
http = HttpMockSequence([
|
http = HttpMockSequence([
|
||||||
({'status': '401'}, ''),
|
({'status': status_code}, ''),
|
||||||
])
|
])
|
||||||
http = self.credentials.authorize(http)
|
http = self.credentials.authorize(http)
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user