使用AcquireTokenAsync函数无法获取Power BI令牌

问题描述

我的ASP.NET MVC项目之一使用Power BI报表集成到页面中。在控制器中,我使用此代码来获取令牌。

var credential = new UserPasswordCredential("USERNAME","PASSWORD");
var authenticationContext = new AuthenticationContext("https://login.windows.net/common/oauth2/authorize/");
var authenticationResult = await authenticationContext.AcquireTokenAsync("https://analysis.windows.net/powerbi/api","APPLICATION_ID",credential).ConfigureAwait(false);

当代码到达AcquireTokenAsync函数时,它将引发此异常。感谢您的支持。

Microsoft.IdentityModel.Clients.ActiveDirectory.AdalServiceException:unknown_error:未知错误> System.Threading.Tasks.TaskCanceledException:任务被取消。 在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务) 在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) 在Microsoft.IdentityModel.Clients.ActiveDirectory.HttpClientWrapper.d__30.MoveNext() 内部异常堆栈跟踪结束 在Microsoft.IdentityModel.Clients.ActiveDirectory.AdalHttpClient.d__21 1.MoveNext() End of stack trace from previous location where exception was thrown at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.IdentityModel.Clients.ActiveDirectory.AdalHttpClient.<GetResponseAsync>d__21 1.MoveNext() 从之前引发异常的位置开始的堆栈跟踪结束 在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) 在Microsoft.IdentityModel.Clients.ActiveDirectory.AdalHttpClient.d__20 1.MoveNext() End of stack trace from previous location where exception was thrown at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.IdentityModel.Clients.ActiveDirectory.UserRealmDiscoveryResponse.<CreateByDiscoveryAsync>d__24.MoveNext() End of stack trace from previous location where exception was thrown at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.IdentityModel.Clients.ActiveDirectory.AcquireTokenNonInteractiveHandler.<PreTokenRequest>d__5.MoveNext() End of stack trace from previous location where exception was thrown at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.IdentityModel.Clients.ActiveDirectory.AcquireTokenHandlerBase.<RunAsync>d__55.MoveNext() End of stack trace from previous location where exception was thrown at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext.<AcquireTokenCommonAsync>d__52.MoveNext() End of stack trace from previous location where exception was thrown at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContextIntegratedAuthExtensions.<AcquireTokenAsync>d__0.MoveNext() End of stack trace from previous location where exception was thrown at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable 1.ConfiguredTaskAwaiter.GetResult() 在D:\ DashboardController.cs:line 317中的Manpower.TicketTracking.Web.Areas.TicketsManagement.Controllers.DashboardController.d__15.MoveNext() 错误代码:unknown_error 状态码:0

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...