BookOps-CAT / overload

BookOps toolkit
MIT License
0 stars 1 forks source link

Google API changes #49

Open klinga opened 4 years ago

klinga commented 4 years ago

A while back Google changed access token response for their authorization service. The response lists refresh_token param twice making it too long for Windows Credentials Manager to store. The best would be to move away from oauth2client to a newer, Python 3 library such as google-auth or oauthlib. That would require though refactoring Overload to Python 3 - a large undertaking, especially considering its reliance on PyZ3950 which is Py2 only.

In the meantime, the easiest way to deal with access token response is to delete one of the refresh_token params from credentials object in the oauth2client.contrib.keyring_storage in the locked_put method.

def locked_put(self, credentials):
    """Write Credentials to file.

    Args:
        credentials: Credentials, the credentials to store.
    """

    # google updated their API auth server response, which duplicates
    # the refresh_token param, which makes credential string too long
    # for Windows credential manager
    # this is a walkaround the problem
    del credentials.token_response["refresh_token"]

    keyring.set_password(self._service_name, self._user_name,
                         credentials.to_json())
klinga commented 4 years ago

exception handling

    try:
        del credentials.token_response["refresh_token"]
    except KeyError:
        pass

    keyring.set_password(self._service_name, self._user_name,
                         credentials.to_json())
klinga commented 2 years ago

add following (reponse got even longer apparently):

    try:
        del credentials.token_response["refresh_token"]
        del credentials.token_response["access_token"]
    except KeyError:
        pass
klinga commented 2 years ago

this seems to work better:

del token response data as it duplicates the rest of creds info

    credentials.token_response = None