@@ -25,8 +25,8 @@ def _get_app_and_auth_code(
25
25
client_id , client_secret , authority = authority , http_client = MinimalHttpClient ())
26
26
redirect_uri = "http://localhost:%d" % port
27
27
ac = obtain_auth_code (port , auth_uri = app .get_authorization_request_url (
28
- scopes , redirect_uri = redirect_uri , ** kwargs ),
29
- text = "Open this link to sign in. You may use incognito window" )
28
+ scopes , redirect_uri = redirect_uri , ** kwargs ),
29
+ text = "Open this link to sign in. You may use incognito window" )
30
30
assert ac is not None
31
31
return (app , ac , redirect_uri )
32
32
@@ -400,6 +400,27 @@ def _test_acquire_token_by_auth_code(
400
400
error_description = result .get ("error_description" )))
401
401
self .assertCacheWorksForUser (result , scope , username = None )
402
402
403
+ def _test_acquire_token_interactive (
404
+ self , client_id = None , authority = None , scope = None ,
405
+ ** ignored ):
406
+ assert client_id and authority and scope
407
+ self .app = msal .ClientApplication (
408
+ client_id , authority = authority , http_client = MinimalHttpClient ())
409
+ result = self .app .acquire_token_interactive (scope )
410
+ logger .debug (
411
+ "%s: cache = %s, id_token_claims = %s" ,
412
+ self .id (),
413
+ json .dumps (self .app .token_cache ._cache , indent = 4 ),
414
+ json .dumps (result .get ("id_token_claims" ), indent = 4 ),
415
+ )
416
+ self .assertIn (
417
+ "access_token" , result ,
418
+ "{error}: {error_description}" .format (
419
+ # Note: No interpolation here, cause error won't always present
420
+ error = result .get ("error" ),
421
+ error_description = result .get ("error_description" )))
422
+ self .assertCacheWorksForUser (result , scope , username = None )
423
+
403
424
def _test_acquire_token_obo (self , config_pca , config_cca ):
404
425
# 1. An app obtains a token representing a user, for our mid-tier service
405
426
pca = msal .PublicClientApplication (
@@ -558,6 +579,17 @@ def test_b2c_acquire_token_by_ropc(self):
558
579
scope = config ["defaultScopes" ].split (',' ),
559
580
)
560
581
582
+ @unittest .skipIf (os .getenv ("TRAVIS" ), "Browser automation is not yet implemented" )
583
+ def test_acquire_token_interactive (self ):
584
+ """When prompted, you can manually login using this account:
585
+
586
+ # https://msidlab.com/api/user?usertype=cloud
587
+ username = "..." # The upn from the link above
588
+ password="***" # From https://aka.ms/GetLabUserSecret?Secret=msidlabXYZ
589
+ """
590
+ config = self .get_lab_user (usertype = "cloud" )
591
+ self ._test_acquire_token_interactive (** config )
592
+
561
593
562
594
class ArlingtonCloudTestCase (LabBasedTestCase ):
563
595
environment = "azureusgovernment"
0 commit comments