From ccbe7aa4ec174f7bb2c54973d42f52273ac800cd Mon Sep 17 00:00:00 2001 From: Ivan Naranjo Date: Tue, 3 May 2016 19:33:21 +0100 Subject: [PATCH] Ensuring that a new url is used after refreshing the credentials. --- apitools/base/py/credentials_lib.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/apitools/base/py/credentials_lib.py b/apitools/base/py/credentials_lib.py index 7612f275..ba179608 100644 --- a/apitools/base/py/credentials_lib.py +++ b/apitools/base/py/credentials_lib.py @@ -570,18 +570,23 @@ def GetUserinfo(credentials, http=None): # pylint: disable=invalid-name aren't available. """ http = http or httplib2.Http() - url_root = 'https://www.googleapis.com/oauth2/v2/tokeninfo' - query_args = {'access_token': credentials.access_token} - url = '?'.join((url_root, urllib.parse.urlencode(query_args))) + url = _GetUserinfoUrl(credentials) # We ignore communication woes here (i.e. SSL errors, socket # timeout), as handling these should be done in a common location. response, content = http.request(url) if response.status == http_client.BAD_REQUEST: credentials.refresh(http) + url = _GetUserinfoUrl(credentials) response, content = http.request(url) return json.loads(content or '{}') # Save ourselves from an empty reply. +def _GetUserinfoUrl(credentials): + url_root = 'https://www.googleapis.com/oauth2/v2/tokeninfo' + query_args = {'access_token': credentials.access_token} + return '?'.join((url_root, urllib.parse.urlencode(query_args))) + + @_RegisterCredentialsMethod def _GetServiceAccountCredentials( client_info, service_account_name=None, service_account_keyfile=None,