本文整理汇总了Python中google.auth.exceptions.GoogleAuthError方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.GoogleAuthError方法的具体用法?Python exceptions.GoogleAuthError怎么用?Python exceptions.GoogleAuthError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类google.auth.exceptions
的用法示例。
在下文中一共展示了exceptions.GoogleAuthError方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from google.auth import exceptions [as 别名]
# 或者: from google.auth.exceptions import GoogleAuthError [as 别名]
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
示例2: __init__
# 需要导入模块: from google.auth import exceptions [as 别名]
# 或者: from google.auth.exceptions import GoogleAuthError [as 别名]
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
示例3: _get_service
# 需要导入模块: from google.auth import exceptions [as 别名]
# 或者: from google.auth.exceptions import GoogleAuthError [as 别名]
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
示例4: _get_customer_service
# 需要导入模块: from google.auth import exceptions [as 别名]
# 或者: from google.auth.exceptions import GoogleAuthError [as 别名]
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
示例5: test_id_token_invalid_cred
# 需要导入模块: from google.auth import exceptions [as 别名]
# 或者: from google.auth.exceptions import GoogleAuthError [as 别名]
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")
示例6: test_verify_oauth2_token_invalid_iss
# 需要导入模块: from google.auth import exceptions [as 别名]
# 或者: from google.auth.exceptions import GoogleAuthError [as 别名]
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
)
示例7: verify_oauth2_token
# 需要导入模块: from google.auth import exceptions [as 别名]
# 或者: from google.auth.exceptions import GoogleAuthError [as 别名]
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
示例8: _fetch_table
# 需要导入模块: from google.auth import exceptions [as 别名]
# 或者: from google.auth.exceptions import GoogleAuthError [as 别名]
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))
示例9: validate_credentials
# 需要导入模块: from google.auth import exceptions [as 别名]
# 或者: from google.auth.exceptions import GoogleAuthError [as 别名]
def validate_credentials(self) -> None:
try:
for _ in self.client.list_buckets():
break
except GoogleAuthError as err:
raise CredentialsError(str(err))