Skip to content

AcquireTokenSilentAsync using a cached token

Jean-Marc Prieur edited this page Mar 6, 2018 · 23 revisions

Token are cached

Once MSAL.NET has acquired a token for a user for a Web API, it caches it. Next time the application wants a token, it should first call AcquireTokenSilentAsync to verify if an acceptable token is in the cache, and if not, call AcquireTokenAsync.

AcquireTokenAsync don't get token from the cache

Contrary to what happens in ADAL.NET, the design of MSAL.NET is such that AcquireTokenAsync never looks at the cache. This is your responsibility as an application developer to call AcquireTokenSilentAsync first.

Recommended call pattern

The recommanded call pattern is to first try to call AcquireTokenSilentAsync, and if it fails with a UIRequiredException, call AcquireTokenAsync See: https://github.com/Azure-Samples/active-directory-dotnet-desktop-msgraph-v2/blob/master/active-directory-wpf-msgraph-v2/MainWindow.xaml.cs#L45-L67

Getting started with MSAL.NET

Acquiring tokens

Web Apps / Web APIs / daemon apps

Desktop/Mobile apps

Advanced topics

FAQ

Other resources

Clone this wiki locally