I have a WPF desktop app, .NET 8, that uses MSAL and the WAM broker to get a token.
I configure WAM as such:
BrokerOptions brokerOptions = new BrokerOptions(BrokerOptions.OperatingSystems.Windows);
brokerOptions.ListOperatingSystemAccounts = true;
builder.WithBroker(brokerOptions);
I am using the code below that you find on the Microsoft website and many other locations (GitHub) to sign-out of all the accounts when I’m done with the token.
When I use this code, it enters an endless loop at (accounts.Any()) because the call to RemoveAsync() does not appear to remove the accounts. The code compiles correctly and there are no exceptions. What could cause this?
var accounts = await App.PublicClientApp.GetAccountsAsync();
if (accounts.Any())
{
try
{
await App.PublicClientApp.RemoveAsync(accounts.FirstOrDefault());
}
catch (MsalException ex)
{
ResultText.Text = $"Error signing-out user: {ex.Message}";
}
}