Python google.auth.exceptions.GoogleAuthError() Examples

The following are 13 code examples of google.auth.exceptions.GoogleAuthError(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module google.auth.exceptions , or try the search function .
Example #1
Source File: impersonated_credentials.py    From google-auth-library-python with Apache License 2.0 6 votes vote down vote up
def __init__(self, target_credentials, target_audience=None, include_email=False):
        """
        Args:
            target_credentials (google.auth.Credentials): The target
                credential used as to acquire the id tokens for.
            target_audience (string): Audience to issue the token for.
            include_email (bool): Include email in IdToken
        """
        super(IDTokenCredentials, self).__init__()

        if not isinstance(target_credentials, Credentials):
            raise exceptions.GoogleAuthError(
                "Provided Credential must be " "impersonated_credentials"
            )
        self._target_credentials = target_credentials
        self._target_audience = target_audience
        self._include_email = include_email 
Example #2
Source File: impersonated_credentials.py    From luci-py with Apache License 2.0 6 votes vote down vote up
def __init__(self, target_credentials,
                 target_audience=None, include_email=False):
        """
        Args:
            target_credentials (google.auth.Credentials): The target
                credential used as to acquire the id tokens for.
            target_audience (string): Audience to issue the token for.
            include_email (bool): Include email in IdToken
        """
        super(IDTokenCredentials, self).__init__()

        if not isinstance(target_credentials,
                          Credentials):
            raise exceptions.GoogleAuthError("Provided Credential must be "
                                             "impersonated_credentials")
        self._target_credentials = target_credentials
        self._target_audience = target_audience
        self._include_email = include_email 
Example #3
Source File: impersonated_credentials.py    From luci-py with Apache License 2.0 6 votes vote down vote up
def __init__(self, target_credentials,
                 target_audience=None, include_email=False):
        """
        Args:
            target_credentials (google.auth.Credentials): The target
                credential used as to acquire the id tokens for.
            target_audience (string): Audience to issue the token for.
            include_email (bool): Include email in IdToken
        """
        super(IDTokenCredentials, self).__init__()

        if not isinstance(target_credentials,
                          Credentials):
            raise exceptions.GoogleAuthError("Provided Credential must be "
                                             "impersonated_credentials")
        self._target_credentials = target_credentials
        self._target_audience = target_audience
        self._include_email = include_email 
Example #4
Source File: impersonated_credentials.py    From luci-py with Apache License 2.0 6 votes vote down vote up
def __init__(self, target_credentials,
                 target_audience=None, include_email=False):
        """
        Args:
            target_credentials (google.auth.Credentials): The target
                credential used as to acquire the id tokens for.
            target_audience (string): Audience to issue the token for.
            include_email (bool): Include email in IdToken
        """
        super(IDTokenCredentials, self).__init__()

        if not isinstance(target_credentials,
                          Credentials):
            raise exceptions.GoogleAuthError("Provided Credential must be "
                                             "impersonated_credentials")
        self._target_credentials = target_credentials
        self._target_audience = target_audience
        self._include_email = include_email 
Example #5
Source File: impersonated_credentials.py    From luci-py with Apache License 2.0 6 votes vote down vote up
def __init__(self, target_credentials,
                 target_audience=None, include_email=False):
        """
        Args:
            target_credentials (google.auth.Credentials): The target
                credential used as to acquire the id tokens for.
            target_audience (string): Audience to issue the token for.
            include_email (bool): Include email in IdToken
        """
        super(IDTokenCredentials, self).__init__()

        if not isinstance(target_credentials,
                          Credentials):
            raise exceptions.GoogleAuthError("Provided Credential must be "
                                             "impersonated_credentials")
        self._target_credentials = target_credentials
        self._target_audience = target_audience
        self._include_email = include_email 
Example #6
Source File: impersonated_credentials.py    From luci-py with Apache License 2.0 6 votes vote down vote up
def __init__(self, target_credentials,
                 target_audience=None, include_email=False):
        """
        Args:
            target_credentials (google.auth.Credentials): The target
                credential used as to acquire the id tokens for.
            target_audience (string): Audience to issue the token for.
            include_email (bool): Include email in IdToken
        """
        super(IDTokenCredentials, self).__init__()

        if not isinstance(target_credentials,
                          Credentials):
            raise exceptions.GoogleAuthError("Provided Credential must be "
                                             "impersonated_credentials")
        self._target_credentials = target_credentials
        self._target_audience = target_audience
        self._include_email = include_email 
Example #7
Source File: ads.py    From airflow with Apache License 2.0 5 votes vote down vote up
def _get_service(self):
        """
        Connects and authenticates with the Google Ads API using a service account
        """
        with NamedTemporaryFile("w", suffix=".json") as secrets_temp:
            self._get_config()
            self._update_config_with_secret(secrets_temp)
            try:
                client = GoogleAdsClient.load_from_dict(self.google_ads_config)
                return client.get_service("GoogleAdsService", version=self.api_version)
            except GoogleAuthError as e:
                self.log.error("Google Auth Error: %s", e)
                raise 
Example #8
Source File: ads.py    From airflow with Apache License 2.0 5 votes vote down vote up
def _get_customer_service(self):
        """
        Connects and authenticates with the Google Ads API using a service account
        """
        with NamedTemporaryFile("w", suffix=".json") as secrets_temp:
            self._get_config()
            self._update_config_with_secret(secrets_temp)
            try:
                client = GoogleAdsClient.load_from_dict(self.google_ads_config)
                return client.get_service("CustomerService", version=self.api_version)
            except GoogleAuthError as e:
                self.log.error("Google Auth Error: %s", e)
                raise 
Example #9
Source File: test_impersonated_credentials.py    From google-auth-library-python with Apache License 2.0 5 votes vote down vote up
def test_id_token_invalid_cred(
        self, mock_donor_credentials, mock_authorizedsession_idtoken
    ):
        credentials = None

        with pytest.raises(exceptions.GoogleAuthError) as excinfo:
            impersonated_credentials.IDTokenCredentials(credentials)

        assert excinfo.match("Provided Credential must be" " impersonated_credentials") 
Example #10
Source File: test_id_token.py    From google-auth-library-python with Apache License 2.0 5 votes vote down vote up
def test_verify_oauth2_token_invalid_iss(verify_token):
    verify_token.return_value = {"iss": "invalid_issuer"}

    with pytest.raises(exceptions.GoogleAuthError):
        id_token.verify_oauth2_token(
            mock.sentinel.token, mock.sentinel.request, audience=mock.sentinel.audience
        ) 
Example #11
Source File: id_token.py    From google-auth-library-python with Apache License 2.0 5 votes vote down vote up
def verify_oauth2_token(id_token, request, audience=None):
    """Verifies an ID Token issued by Google's OAuth 2.0 authorization server.

    Args:
        id_token (Union[str, bytes]): The encoded token.
        request (google.auth.transport.Request): The object used to make
            HTTP requests.
        audience (str): The audience that this token is intended for. This is
            typically your application's OAuth 2.0 client ID. If None then the
            audience is not verified.

    Returns:
        Mapping[str, Any]: The decoded token.

    Raises:
        exceptions.GoogleAuthError: If the issuer is invalid.
    """
    idinfo = verify_token(
        id_token, request, audience=audience, certs_url=_GOOGLE_OAUTH2_CERTS_URL
    )

    if idinfo["iss"] not in _GOOGLE_ISSUERS:
        raise exceptions.GoogleAuthError(
            "Wrong issuer. 'iss' should be one of the following: {}".format(
                _GOOGLE_ISSUERS
            )
        )

    return idinfo 
Example #12
Source File: data_ingestion_configurable.py    From professional-services with Apache License 2.0 5 votes vote down vote up
def _fetch_table(table_name):
    try:
        client = datastore.Client()
    except GoogleAuthError:
        # TODO(lcaggioni.ludomagno): fail gracefully
        pass
    return client.get(client.key('Table', table_name)) 
Example #13
Source File: google.py    From cloudstorage with MIT License 5 votes vote down vote up
def validate_credentials(self) -> None:
        try:
            for _ in self.client.list_buckets():
                break
        except GoogleAuthError as err:
            raise CredentialsError(str(err))