@@ -184,18 +184,29 @@ def acquire_token_by_authorization_code(
184184 data = {"scope" : decorate_scope (scopes , self .client_id )},
185185 )
186186
187- def get_accounts (self ):
188- """Returns a list of account objects that can later be used to find token .
187+ def get_accounts (self , username = None ):
188+ """Get a list of accounts which previously signed in, i.e. exists in cache .
189189
190- Each account object is a dict containing a "username" field (among others)
191- which can use to determine which account to use.
190+ An account can later be used in acquire_token_silent() to find its tokens.
191+ Each account is a dict. For now, we only document its "username" field.
192+ Your app can choose to display those information to end user,
193+ and allow them to choose one of them to proceed.
194+
195+ :param username:
196+ Filter accounts with this username only. Case insensitive.
192197 """
193198 # The following implementation finds accounts only from saved accounts,
194199 # but does NOT correlate them with saved RTs. It probably won't matter,
195200 # because in MSAL universe, there are always Accounts and RTs together.
196- return self .token_cache .find (
197- self .token_cache .CredentialType .ACCOUNT ,
198- query = {"environment" : self .authority .instance })
201+ accounts = self .token_cache .find (
202+ self .token_cache .CredentialType .ACCOUNT ,
203+ query = {"environment" : self .authority .instance })
204+ if username :
205+ # Federated account["username"] from AAD could contain mixed case
206+ lowercase_username = username .lower ()
207+ accounts = [a for a in accounts
208+ if a ["username" ].lower () == lowercase_username ]
209+ return accounts
199210
200211 def acquire_token_silent (
201212 self , scopes ,
0 commit comments