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 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈