Skip to content

Commit f0666d9

Browse files
atulepparthea
authored andcommitted
feat: adds support for audience in client_options (#379)
feat: adds support for audience in client_options.
1 parent 4ac1df7 commit f0666d9

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

google/api_core/client_options.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ class ClientOptions(object):
7070
scopes (Optional[Sequence[str]]): OAuth access token override scopes.
7171
api_key (Optional[str]): Google API key. ``credentials_file`` and
7272
``api_key`` are mutually exclusive.
73+
api_audience (Optional[str]): The intended audience for the API calls
74+
to the service that will be set when using certain 3rd party
75+
authentication flows. Audience is typically a resource identifier.
76+
If not set, the service endpoint value will be used as a default.
77+
An example of a valid ``api_audience`` is: "https://language.googleapis.com".
7378
7479
Raises:
7580
ValueError: If both ``client_cert_source`` and ``client_encrypted_cert_source``
@@ -85,6 +90,7 @@ def __init__(
8590
credentials_file=None,
8691
scopes=None,
8792
api_key=None,
93+
api_audience=None,
8894
):
8995
if client_cert_source and client_encrypted_cert_source:
9096
raise ValueError(
@@ -99,6 +105,7 @@ def __init__(
99105
self.credentials_file = credentials_file
100106
self.scopes = scopes
101107
self.api_key = api_key
108+
self.api_audience = api_audience
102109

103110
def __repr__(self):
104111
return "ClientOptions: " + repr(self.__dict__)

tests/unit/test_client_options.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def test_constructor():
3636
"https://www.googleapis.com/auth/cloud-platform",
3737
"https://www.googleapis.com/auth/cloud-platform.read-only",
3838
],
39+
api_audience="foo2.googleapis.com",
3940
)
4041

4142
assert options.api_endpoint == "foo.googleapis.com"
@@ -46,6 +47,7 @@ def test_constructor():
4647
"https://www.googleapis.com/auth/cloud-platform",
4748
"https://www.googleapis.com/auth/cloud-platform.read-only",
4849
]
50+
assert options.api_audience == "foo2.googleapis.com"
4951

5052

5153
def test_constructor_with_encrypted_cert_source():
@@ -113,6 +115,7 @@ def test_from_dict():
113115
"https://www.googleapis.com/auth/cloud-platform",
114116
"https://www.googleapis.com/auth/cloud-platform.read-only",
115117
],
118+
"api_audience": "foo2.googleapis.com",
116119
}
117120
)
118121

@@ -125,6 +128,7 @@ def test_from_dict():
125128
"https://www.googleapis.com/auth/cloud-platform.read-only",
126129
]
127130
assert options.api_key is None
131+
assert options.api_audience == "foo2.googleapis.com"
128132

129133

130134
def test_from_dict_bad_argument():

0 commit comments

Comments
 (0)