Azure AD Oauth

时间:2017-09-13 00:46:57

标签: c# azure authentication oauth powerbi

我正在尝试对我的应用进行身份验证以使用PowerBi REST API。为此,我尝试将给定here的示例用于非高级BI用户。这是我用于身份验证的代码。但它给出了以下例外。

Microsoft.IdentityModel.Clients.ActiveDirectory.AdalServiceException未处理 消息:未处理的类型' Microsoft.IdentityModel.Clients.ActiveDirectory.AdalServiceException'发生在mscorlib.dll中 其他信息:https://msft.sts.microsoft.com/adfs/services/trust/13/usernamemixed处的联合服务返回错误:ID3242:无法对安全令牌进行身份验证或授权。

我已确定输入了正确的应用程序和组ID。

 var credential = new UserPasswordCredential(Username, Password);

        // Authenticate using created credentials
        var authenticationContext = new AuthenticationContext(ConfigurationManager.AppSettings["authorityUrl"]);
        AuthenticationResult authenticationResult = await authenticationContext.AcquireTokenAsync(ConfigurationManager.AppSettings["resourceUrl"], ConfigurationManager.AppSettings["clientId"], credential);

        if (authenticationResult == null)
        {

            Console.WriteLine("Authentication Failed.");

        }

我想知道我在这里做错了什么?我的Azure用户名已在此应用中获得所有者访问权限。

1 个答案:

答案 0 :(得分:0)

您的代码是正确的,但是发生此错误是因为您需要在Azure中创建应用程序。您需要设置一些信息,例如:正确的回调

尝试按照此文档创建您的应用程序:

https://powerbi.microsoft.com/en-us/documentation/powerbi-developer-register-app/