feat: adds support for audience in client_options (#379)
feat: adds support for audience in client_options.
diff --git a/google/api_core/client_options.py b/google/api_core/client_options.py
index 4a2a84a..ee9f28a 100644
--- a/google/api_core/client_options.py
+++ b/google/api_core/client_options.py
@@ -70,6 +70,11 @@
scopes (Optional[Sequence[str]]): OAuth access token override scopes.
api_key (Optional[str]): Google API key. ``credentials_file`` and
``api_key`` are mutually exclusive.
+ api_audience (Optional[str]): The intended audience for the API calls
+ to the service that will be set when using certain 3rd party
+ authentication flows. Audience is typically a resource identifier.
+ If not set, the service endpoint value will be used as a default.
+ An example of a valid ``api_audience`` is: "https://language.googleapis.com".
Raises:
ValueError: If both ``client_cert_source`` and ``client_encrypted_cert_source``
@@ -85,6 +90,7 @@
credentials_file=None,
scopes=None,
api_key=None,
+ api_audience=None,
):
if client_cert_source and client_encrypted_cert_source:
raise ValueError(
@@ -99,6 +105,7 @@
self.credentials_file = credentials_file
self.scopes = scopes
self.api_key = api_key
+ self.api_audience = api_audience
def __repr__(self):
return "ClientOptions: " + repr(self.__dict__)
diff --git a/tests/unit/test_client_options.py b/tests/unit/test_client_options.py
index 334b8c1..d56a1b3 100644
--- a/tests/unit/test_client_options.py
+++ b/tests/unit/test_client_options.py
@@ -36,6 +36,7 @@
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/cloud-platform.read-only",
],
+ api_audience="foo2.googleapis.com",
)
assert options.api_endpoint == "foo.googleapis.com"
@@ -46,6 +47,7 @@
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/cloud-platform.read-only",
]
+ assert options.api_audience == "foo2.googleapis.com"
def test_constructor_with_encrypted_cert_source():
@@ -114,6 +116,7 @@
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/cloud-platform.read-only",
],
+ "api_audience": "foo2.googleapis.com",
}
)
@@ -126,6 +129,7 @@
"https://www.googleapis.com/auth/cloud-platform.read-only",
]
assert options.api_key is None
+ assert options.api_audience == "foo2.googleapis.com"
def test_from_dict_bad_argument():