@@ -242,6 +242,7 @@ def test_authorized_session(self, instance):
242
242
class TestInstalledAppFlow (object ):
243
243
SCOPES = ["email" , "profile" ]
244
244
REDIRECT_REQUEST_PATH = "/?code=code&state=state"
245
+ AUDIENCE = "dummy-audience"
245
246
246
247
@pytest .fixture
247
248
def instance (self ):
@@ -312,6 +313,46 @@ def test_run_local_server(self, webbrowser_mock, instance, mock_fetch_token, por
312
313
client_secret = CLIENT_SECRETS_INFO ["web" ]["client_secret" ],
313
314
authorization_response = expected_auth_response ,
314
315
code_verifier = None ,
316
+ audience = None ,
317
+ )
318
+
319
+ @pytest .mark .webtest
320
+ @mock .patch ("google_auth_oauthlib.flow.webbrowser" , autospec = True )
321
+ def test_run_local_server_audience (
322
+ self , webbrowser_mock , instance , mock_fetch_token , port
323
+ ):
324
+ auth_redirect_url = urllib .parse .urljoin (
325
+ f"http://localhost:{ port } " , self .REDIRECT_REQUEST_PATH
326
+ )
327
+
328
+ with concurrent .futures .ThreadPoolExecutor (max_workers = 1 ) as pool :
329
+ future = pool .submit (
330
+ partial (
331
+ instance .run_local_server , port = port , token_audience = self .AUDIENCE
332
+ )
333
+ )
334
+
335
+ while not future .done ():
336
+ try :
337
+ requests .get (auth_redirect_url )
338
+ except requests .ConnectionError : # pragma: NO COVER
339
+ pass
340
+
341
+ credentials = future .result ()
342
+
343
+ assert credentials .token == mock .sentinel .access_token
344
+ assert credentials ._refresh_token == mock .sentinel .refresh_token
345
+ assert credentials .id_token == mock .sentinel .id_token
346
+ assert webbrowser_mock .open .called
347
+ assert instance .redirect_uri == f"http://localhost:{ port } /"
348
+
349
+ expected_auth_response = auth_redirect_url .replace ("http" , "https" )
350
+ mock_fetch_token .assert_called_with (
351
+ CLIENT_SECRETS_INFO ["web" ]["token_uri" ],
352
+ client_secret = CLIENT_SECRETS_INFO ["web" ]["client_secret" ],
353
+ authorization_response = expected_auth_response ,
354
+ code_verifier = None ,
355
+ audience = self .AUDIENCE ,
315
356
)
316
357
317
358
@pytest .mark .webtest
@@ -353,6 +394,7 @@ def test_run_local_server_code_verifier(
353
394
client_secret = CLIENT_SECRETS_INFO ["web" ]["client_secret" ],
354
395
authorization_response = expected_auth_response ,
355
396
code_verifier = "amanaplanacanalpanama" ,
397
+ audience = None ,
356
398
)
357
399
358
400
@mock .patch ("google_auth_oauthlib.flow.webbrowser" , autospec = True )
0 commit comments