use async controller actions - AzureAD/azure-activedirectory-library-for-dotnet GitHub Wiki
When calling ADAL.NET in an ASP.NET or ASP.NET Core Web Application or Web API controller, you need to make sure that you use the async/await pattern and have your controller actions be async method, otherwise you'll experience multi-threading issues.
In particular you should not use .Result(). See Reminder: Do not call ADAL or MSAL async methods synchronously from the UI thread
Make sure your controller actions be async
and return Task<HttpResponseMessage>
, and then change the following line to:
var user = await authenticationContext.AcquireTokenXXXAsync()
For more information about the kind of experience you could get if you use .Result
, please see Issue #555: Cannot acquire token in web app context