Forum Discussion

elserafi's avatar
elserafi
Regular Visitor
8 years ago
Solved

PowerBI Application Authentication

We are trying to utilize REST API of Power BI which allows to integrate a Power BI report into an application. We have created an application within our Microsoft Azure Active Directory and given pe...
  • Eric_Zhang's avatar
    8 years ago

    elserafi wrote:

    We are trying to utilize REST API of Power BI which allows to integrate a Power BI report into an application.

    We have created an application within our Microsoft Azure Active Directory and given permission for Microsoft Power BI Reporting.

    We are facing below issues while integrating PowerBI report from WebAPI.

    1.      Acquiring the token from the AZURE Active Directory.

    How do we achieve the “Access Token” without user interaction? ( i.e. not showing Microsoft Authentication Popup).

    We tried getting access token using below code, however the token which we received gives forbidden error.

    TokenCache TC = new TokenCache();

    ClientCredential CC = new ClientCredential (clientID,SecretID);

    Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext authenticationContext1= new Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext(authorityUri, TC);

    AuthenticationResult result3 = authenticationContext.AcquireTokenAsync(resourceUri, CC).Result;


    elserafi

    What is the scenario in your case that required non-user interaction? For App Owns data, you can reference below snippet.

                // Create a user password cradentials.
                var credential = new UserPasswordCredential(Username, Password);
    
                // Authenticate using created credentials
                var authenticationContext = new AuthenticationContext(AuthorityUrl);
                var authenticationResult = await authenticationContext.AcquireTokenAsync(ResourceUrl, ClientId, credential);

    Or you can call the REST API directly.

    POST /common/oauth2/token HTTP/1.1
    Host: login.windows.net
    Content-Type: application/x-www-form-urlencoded
    Cache-Control: no-cache 
    
    client_secret={cilent_secrect}&client_id={client_id}&grant_type=password&resource=https%3A%2F%2Fanalysis.windows.net%2Fpowerbi%2Fapi&username={pbi username}&password={pbi password}