简体   繁体   中英

PowerBi authentication issue with Azure AD Oauth

I am trying to authenticate my app to use PowerBi REST APIs. For this I am trying to use the example given here for non-power BI users. Here is my code that I used for authentication. But it is giving the following exception.

Microsoft.IdentityModel.Clients.ActiveDirectory.AdalServiceException was unhandled Message: An unhandled exception of type 'Microsoft.IdentityModel.Clients.ActiveDirectory.AdalServiceException' occurred in mscorlib.dll Additional information: Federated service at https://msft.sts.microsoft.com/adfs/services/trust/13/usernamemixed returned error: ID3242: The security token could not be authenticated or authorized.

I have made sure i have entered the correct application and group 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.");

        }

I want to know what I am doing wrong here? My Azure user name has got owner access in this app.

Your code is correct, however this error happens because you need to create your application in Azure. You need to set some informations like: the correct callback

Try to follow this document to create your application:

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

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