def get_client(): scope = ['https://spreadsheets.google.com/feeds'] s = Signer.from_string( base64.b64decode(os.environ['GOOGLE_API_PRIVATE_KEY'])) credentials = ServiceAccountCredentials( os.environ['GOOGLE_API_CLIENT_EMAIL'], s, scope, ) return gspread.authorize(credentials)
def _generate_assertion(self): """Generate the assertion that will be used in the request.""" now = long(time.time()) payload = { "aud": self.token_uri, "scope": self.scope, "iat": now, "exp": now + SignedJwtAssertionCredentials.MAX_TOKEN_LIFETIME_SECS, "iss": self.service_account_name, } payload.update(self.kwargs) logging.debug(str(payload)) return make_signed_jwt(Signer.from_string(self.private_key, self.private_key_password), payload)
def __authenticate(self): if self.verbose: print('Authenticating for Google Sheets') creds = self.__sheet_cfg['creds'] signer = Signer.from_string(creds['private_key']) scope = self.__sheet_cfg['scope'] return ServiceAccountCredentials( client_id=creds['client_id'], service_account_email=creds['client_email'], private_key_id=creds['private_key_id'], token_uri=creds['token_uri'], scopes=scope, signer=signer)
def _generate_assertion(self): """Generate the assertion that will be used in the request.""" now = long(time.time()) payload = { 'aud': self.token_uri, 'scope': self.scope, 'iat': now, 'exp': now + SignedJwtAssertionCredentials.MAX_TOKEN_LIFETIME_SECS, 'iss': self.service_account_name } payload.update(self.kwargs) logging.debug(str(payload)) return make_signed_jwt( Signer.from_string(self.private_key, self.private_key_password), payload)
def _generate_assertion(self): """Generate the assertion that will be used in the request.""" now = long(time.time()) payload = { 'aud': self.token_uri, 'scope': self.scope, 'iat': now, 'exp': now + SignedJwtAssertionCredentials.MAX_TOKEN_LIFETIME_SECS, 'iss': self.service_account_name } payload.update(self.kwargs) logger.debug(str(payload)) private_key = base64.b64decode(self.private_key) return make_signed_jwt( Signer.from_string(private_key, self.private_key_password), payload)
def sign_string(self, string_to_sign): import base64 from oauth2client.crypt import Signer signer = Signer.from_string(self.oauth2_client._private_key) return base64.b64encode(signer.sign(string_to_sign))