简体   繁体   中英

MSAL.Desktop.4.36.0.0.MsalServiceException: User canceled authentication 'ErrorCode: authentication_canceled' while running WPF on Windows Server 2016

I am trying to read teams user status from WPF Desktop application. For that, I am using Microsoft.Identity.Client - 4.36.0v, Microsoft.Identity.Client.Desktop-4.36.0v to get token to access MS Graph api's.

My Application works perfectly in local machine which runs on Windows 10. When I moved the sources to VM which runs on Windows server 2016, It gives 'MsalServiceException: User canceled authentication' on the below code. Account picker is blinking and vanishing. I haven't cancel anything.

authResult = await app.AcquireTokenInteractive(scopes) .WithAccount(accounts.FirstOrDefault()) .WithPrompt(Prompt.SelectAccount) .ExecuteAsync();

MSAL.Desktop.4.36.0.0.MsalServiceException: 
    ErrorCode: authentication_canceled
Microsoft.Identity.Client.MsalServiceException: Broker response returned error: User canceled authentication. 
   at Microsoft.Identity.Client.Internal.Broker.BrokerInteractiveRequestComponent.ValidateResponseFromBroker(MsalTokenResponse msalTokenResponse)
   at Microsoft.Identity.Client.Internal.Broker.BrokerInteractiveRequestComponent.<FetchTokensAsync>d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Identity.Client.Internal.Requests.InteractiveRequest.<FetchTokensFromBrokerAsync>d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Identity.Client.Internal.Requests.InteractiveRequest.<GetTokenResponseAsync>d__11.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Identity.Client.Internal.Requests.InteractiveRequest.<ExecuteAsync>d__8.MoveNext()

Please help me to fix this.

Please Check for these Possible work arounds

Msal exception

If the user closes the process or if they hit the browser back button, MSAL generates an error : authentication_canceled .

You may try inform the user when that happens : Reference

Also see this thread

Error Faulting application name: ....

Reason for this error varies from one scenario to other. check few listed among them below.

Set Enable 32-Bit Applications : If deploying a 32-bit (x86) app, set the value to True otherwise set it to false if it is 64 bit. reference

CHECK

If You have latest Azure SDK and correct dll references. eg Make sure that if you have version 4.0, all references use same version. Remove any unnecessary references from the project.

  1. All references (including packages and own libraries) are enabled with "Copy Local" = True and they are included in the package bin /assemblies.
  2. Try to uninstall and reinstall packages from NuGet for ex: Azure Caching package
  3. Check the connection strings and validity of keys, in case of storage.
  4. Check whether service configuration has correct osFamily (ex :3) and osVersion that you are targeting in ServiceConfiguration.Cloud.cscfg are compatible

Otherwise try intelliTrace. Temporarily disable "Lazy Initialization" under IntelliTrace Settings -> IntelliTrace Events. Reference

Try to upgrade Microsoft.Identity.Client - 4.36 to 4.37. if not then try in windows server 2022.

See this Limitation link

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM