Auth

classes used to authenticate credentials and create service for Google Suite Apps

class pysuite.auth.Authentication(credential: Union[pathlib.PosixPath, str], services: Union[list, str], token: Optional[Union[pathlib.PosixPath, str]] = None)[source]

Bases: object

read from credential file and token file and authenticate with Google service for requested services. if token file does not exists, confirmation is needed from browser prompt and the token file will be created. You can pass a list of services or one service.

get_service_client(service: Optional[str] = None, version: Optional[str] = None)[source]

get a service object for requested service. This service must be within authorized scope set up at initiation stage.

Parameters
  • service – type of service, “drive” or “sheets”. If None and self._services has more than 1 items, an exception will be raised.

  • version – version of target service. if None, default version will be used. it varies with service.

Returns

a service object used to access API for that service.

property is_google_cloud
load_credential() → google.oauth2.credentials.Credentials[source]

load credential json file needed to authenticate Google Suite Apps. If token file does not exists, confirmation is needed from browser prompt and the token file will be created.

Parameters

credential – path to the credential json file.

Returns

a Credential object

refresh()[source]

refresh token if not valid or has expired. In addition token file is overwritten.

Returns

None

write_token()[source]