Get and remove accounts from the token cache using MSAL for Java
MSAL for Java provides an in-memory token cache by default. The in-memory token cache persists for the duration of the application execution.
See which accounts are in the cache
You can check what accounts are in the cache by calling PublicClientApplication.getAccounts()
as shown in the following example:
PublicClientApplication pca = new PublicClientApplication.Builder(
labResponse.getAppId()).
authority(TestConstants.ORGANIZATIONS_AUTHORITY).
build();
Set<IAccount> accounts = pca.getAccounts().join();
Remove accounts from the cache
To remove an account from the cache, find the account that needs to be removed and then call PublicClientApplication.removeAccount()
as shown in the following example:
Set<IAccount> accounts = pca.getAccounts().join();
IAccount accountToBeRemoved = accounts.stream().filter(
x -> x.username().equalsIgnoreCase(
UPN_OF_USER_TO_BE_REMOVED)).findFirst().orElse(null);
pca.removeAccount(accountToBeRemoved).join();
Learn more
If you are using MSAL for Java, learn about Custom token cache serialization in MSAL for Java.
フィードバック
https://aka.ms/ContentUserFeedback」を参照してください。
以下は間もなく提供いたします。2024 年を通じて、コンテンツのフィードバック メカニズムとして GitHub の issue を段階的に廃止し、新しいフィードバック システムに置き換えます。 詳細については、「フィードバックの送信と表示