@@ -662,6 +662,35 @@ def test_organizations_authority_should_emit_warning(self):
662
662
authority = "https://login.microsoftonline.com/organizations" )
663
663
664
664
665
+ class TestRemoveTokensForClient (unittest .TestCase ):
666
+ def test_remove_tokens_for_client_should_remove_client_tokens_only (self ):
667
+ at_for_user = "AT for user"
668
+ cca = msal .ConfidentialClientApplication (
669
+ "client_id" , client_credential = "secret" ,
670
+ authority = "https://login.microsoftonline.com/microsoft.onmicrosoft.com" )
671
+ self .assertEqual (
672
+ 0 , len (cca .token_cache .find (msal .TokenCache .CredentialType .ACCESS_TOKEN )))
673
+ cca .acquire_token_for_client (
674
+ ["scope" ],
675
+ post = lambda url , ** kwargs : MinimalResponse (
676
+ status_code = 200 , text = json .dumps ({"access_token" : "AT for client" })))
677
+ self .assertEqual (
678
+ 1 , len (cca .token_cache .find (msal .TokenCache .CredentialType .ACCESS_TOKEN )))
679
+ cca .acquire_token_by_username_password (
680
+ "johndoe" , "password" , ["scope" ],
681
+ post = lambda url , ** kwargs : MinimalResponse (
682
+ status_code = 200 , text = json .dumps (build_response (
683
+ access_token = at_for_user , expires_in = 3600 ,
684
+ uid = "uid" , utid = "utid" , # This populates home_account_id
685
+ ))))
686
+ self .assertEqual (
687
+ 2 , len (cca .token_cache .find (msal .TokenCache .CredentialType .ACCESS_TOKEN )))
688
+ cca .remove_tokens_for_client ()
689
+ remaining_tokens = cca .token_cache .find (msal .TokenCache .CredentialType .ACCESS_TOKEN )
690
+ self .assertEqual (1 , len (remaining_tokens ))
691
+ self .assertEqual (at_for_user , remaining_tokens [0 ].get ("secret" ))
692
+
693
+
665
694
class TestScopeDecoration (unittest .TestCase ):
666
695
def _test_client_id_should_be_a_valid_scope (self , client_id , other_scopes ):
667
696
# B2C needs this https://learn.microsoft.com/en-us/azure/active-directory-b2c/access-tokens#openid-connect-scopes
0 commit comments