我正在学习如何将PowerBI仪表板集成到ASP.NET应用程序中,当我尝试对AAD进行身份验证时,我在堆栈跟踪中收到以下错误。
[AdalException: : Unknown error]
[HttpRequestException: Response status code does not indicate success: 406 (NotAcceptable).]
代码是(从web.config中的AppSettings读取用户名和密码):
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
RegisterAsyncTask(new PageAsyncTask(GetToken));
}
}
private async Task<AuthenticationResult> GetToken()
{
UserPasswordCredential credential;
AuthenticationResult authenticationResult;
string AuthorityUrl = "https://login.windows.net/common/oauth2/authorize/";
string resourceUrl = "https://analysis.windows.net/powerbi/api";
var authenticationContext = new AuthenticationContext(AuthorityUrl);
credential = new UserPasswordCredential(Username, Password);
authenticationResult = await authenticationContext.AcquireTokenAsync(resourceUrl, ClientId, credential);
return authenticationResult;
}
任何帮助都会受到赞赏(这是我对API和AAD的第一次体验,所以要温和一点。)