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 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기