MSAL。Desktop.4.36.0.0.MsalService异常:在 Windows Server 2016 上运行 WPF 时,用户取消了身份验证'ErrorCode: authentica



我正在尝试从WPF桌面应用程序读取团队用户状态。为此,我使用Microsoft.Identity。客户端-4.36.0v, Microsoft.Identity.Client.Desktop-4.36.0v获取令牌以访问MS Graph api。

我的应用程序在运行Windows 10的本地机器上运行完美。当我将源代码移动到在Windows server 2016上运行的VM时,它给出了以下代码中的'MsalServiceException: User canceled authentication'。帐户选择器正在闪烁和消失。我没有取消任何东西。

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()

请帮我解决这个问题。

请检查这些可能的工作

Msal exception

如果用户关闭进程或者点击浏览器返回按钮,MSAL会生成一个错误:authentication_cancelled .

当发生这种情况时,你可以试着通知用户:参考

也看这个线程

Error Faulting application name: ....

此错误的原因因场景而异。看看下面列出的几个。

设置Enable 32-Bit Applications:如果部署的是32位(x86)应用,则设置为True,如果是64位则设置为false。参考

检查

如果你有最新的Azure SDK和正确的dll引用。如果你使用的是4.0版本,请确保所有引用都使用相同的版本。从项目中删除任何不必要的引用。

  1. 所有引用(包括包和自己的库)都启用了"Copy Local" = True,它们包含在包bin/assemblies中。
  2. 尝试从NuGet中卸载和重新安装包,例如:Azure缓存包
  3. 检查连接字符串和密钥的有效性,以防存储。
  4. 检查业务配置有正确的osFamily(例如:3)和osVersion,您的目标在servicecconfiguration . cloud .cscfg是兼容的

否则尝试intelliTrace。暂时禁用"延迟初始化";在IntelliTrace设置下->IntelliTrace事件。参考

最新更新