How to use the hubspot3.oauth2.OAuth2Client function in hubspot3

To help you get started, we’ve selected a few hubspot3 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jpetrucciani / hubspot3 / hubspot3 / oauth2.py View on Github external
def __init__(self, *args, **kwargs):
        """initialize a contacts client"""
        # Since this client is used to generate tokens for authentication, it does not require
        # authentication itself.
        kwargs["disable_auth"] = True
        super(OAuth2Client, self).__init__(*args, **kwargs)
        self.log = get_log("hubspot3.oauth2")
        self.options["content_type"] = "application/x-www-form-urlencoded"
        # Make sure that certain credentials that wouldn't be used anyway are not set. Not having
        # an access token will also make sure that the `_call_raw` implementation does not try to
        # refresh access tokens on its own.
        self.api_key = None
        self.access_token = None
github jpetrucciani / hubspot3 / hubspot3 / base.py View on Github external
and self.refresh_token
                    and self.client_id
                    and self.client_secret
                ):
                    if retried:
                        self.log.error(
                            "Refreshed token, but request still was not authorized. "
                            "You may need to grant additional permissions."
                        )
                        raise

                    from hubspot3.oauth2 import OAuth2Client

                    self.log.info("Refreshing access token")
                    try:
                        client = OAuth2Client(**self.options)
                        refresh_result = client.refresh_tokens(
                            client_id=self.client_id,
                            client_secret=self.client_secret,
                            refresh_token=self.refresh_token,
                        )
                        self.access_token = refresh_result["access_token"]
                        self.refresh_token = refresh_result["refresh_token"]
                        self.log.info(
                            "Retrying with new token {}".format(self.access_token)
                        )
                    except Exception as exception:
                        self.log.error(
                            "Unable to refresh access_token: {}".format(exception)
                        )
                        raise
                    return self._call_raw(
github jpetrucciani / hubspot3 / hubspot3 / __init__.py View on Github external
def oauth2(self):
        """returns a hubspot3 OAuth2 client"""
        from hubspot3.oauth2 import OAuth2Client

        return OAuth2Client(**self.auth, **self.options)