Skip to content

clearing token cache

Bogdan Gavril edited this page Aug 22, 2019 · 6 revisions

Clearing the cache is achieved by removing the accounts (or the users in MSAL 2.x) from the cache.

This does not remove the session cookie which is in the browser, though.

MSAL 2.x+

The code is the following where app is a IClientApplicationBase

   // clear the cache
   var accounts = await app.GetAccountsAsync();
   while (accounts.Any())
   {
    await app.RemoveAsync(accounts.First());
    accounts = await app.GetAccountsAsync();
   }

MSAL 1.x

   // clear the cache
   while (app.Users.Any())
   {
    await app.Remove(app.Users.First());
   }

Getting started with MSAL.NET

Acquiring tokens

Desktop/Mobile apps

Web Apps / Web APIs / daemon apps

Advanced topics

News

FAQ

Other resources

Clone this wiki locally