@@ -555,3 +555,42 @@ def mock_post(url, headers=None, *args, **kwargs):
555
555
result = self .app .acquire_token_on_behalf_of ("assertion" , ["s" ], post = mock_post )
556
556
self .assertEqual (at , result .get ("access_token" ))
557
557
558
+
559
+ class TestClientApplicationWillGroupAccounts (unittest .TestCase ):
560
+ def test_get_accounts (self ):
561
+ client_id = "my_app"
562
+ scopes = ["scope_1" , "scope_2" ]
563
+ environment = "login.microsoftonline.com"
564
+ uid = "home_oid"
565
+ utid = "home_tenant_guid"
566
+ username = "Jane Doe"
567
+ cache = msal .SerializableTokenCache ()
568
+ for tenant in ["contoso" , "fabrikam" ]:
569
+ cache .add ({
570
+ "client_id" : client_id ,
571
+ "scope" : scopes ,
572
+ "token_endpoint" :
573
+ "https://{}/{}/oauth2/v2.0/token" .format (environment , tenant ),
574
+ "response" : TokenCacheTestCase .build_response (
575
+ uid = uid , utid = utid , access_token = "at" , refresh_token = "rt" ,
576
+ id_token = TokenCacheTestCase .build_id_token (
577
+ aud = client_id ,
578
+ sub = "oid_in_" + tenant ,
579
+ preferred_username = username ,
580
+ ),
581
+ ),
582
+ })
583
+ app = ClientApplication (
584
+ client_id ,
585
+ authority = "https://{}/common" .format (environment ),
586
+ token_cache = cache )
587
+ accounts = app .get_accounts ()
588
+ self .assertEqual (1 , len (accounts ), "Should return one grouped account" )
589
+ account = accounts [0 ]
590
+ self .assertEqual ("{}.{}" .format (uid , utid ), account ["home_account_id" ])
591
+ self .assertEqual (environment , account ["environment" ])
592
+ self .assertEqual (username , account ["username" ])
593
+ self .assertIn ("authority_type" , account , "Backward compatibility" )
594
+ self .assertIn ("local_account_id" , account , "Backward compatibility" )
595
+ self .assertIn ("realm" , account , "Backward compatibility" )
596
+
0 commit comments