Skip to content

Commit

Permalink
Ensuring that a new url is used after refreshing the credentials.
Browse files Browse the repository at this point in the history
  • Loading branch information
ivannaranjo committed May 3, 2016
1 parent dd2d897 commit ccbe7aa
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions apitools/base/py/credentials_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit ccbe7aa

Please sign in to comment.