Forum Discussion

visure's avatar
visure
Regular Visitor
9 years ago
Solved

REST API Silent Authentication (Token)

Hi guys,

 

I was following the steps in this topic:
Http://community.powerbi.com/t5/Developer/How-to-use-Power-BI-Rest-API-without-GUI-authentication-redirect/m-p/6030/highlight/true#

 

To perform the same operations in PHP however I am having some difficulty playing in php,

- I created an an App at https://dev.powerbi.com/apps as NativeApp
- I gave all the permissions
- I got my client_id

 

Basically I'm making a request (post) on:
https://login.windows.net/common/oauth2/token

 

With the parameters:
grant_type = password
scope = openid
resource = https: //analysis.windows.net/powerbi/api
client_id = MY_CLIENT_IS
username = MY_USER_NAME
password = MY_PASSWORD

 

But I always get:
AADSTS65001: The user or administrator has not consented to use the application with ID 'CLIENT_ID'. Send an interactive authorization request for this user and resource. Trace ID: f9380076-1990-4d5d-b615-925a47121100

 

What's wrong?

 

Note: I don't use Azure Management Portal

  • visure's avatar
    visure
    9 years ago

    Thanks Eric_Zhang, I already solved it,

     

    Just read a little more how the authentication flow works :)

  • visure's avatar
    visure
    9 years ago

    Eric_Zhang

     

    Of course,

     

    When I calmly read the message "The user or administrator has not consented to use the application" I started to ask myself "where could I consent the permissions", the quick response came "Azure AD".

     

    I started to search how the Azure AD permissions system works and I found this link:
    Https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-integrating-applications

     

    After reading it I conclude: I created the application through PowerBI (http://dev.powerbi.com/apps) which generated an application in Azure AD (http://portal.azure.com), so I still had to delegate the application permissions - my user was also the account administrator so I just needed to grant the permissions.

     

    Steps: 

    Create app on PowerBI > Go to Azure Portal > Find Azure Active Directory > Find the Application > Grant Permissions

     

    Any questions are welcome.

15 Replies

    • visure's avatar
      visure
      Regular Visitor

      Thanks Eric_Zhang, I already solved it,

       

      Just read a little more how the authentication flow works :)

  • Janavarsha's avatar
    Janavarsha
    Frequent Visitor

    I want power bi authenication code in java.can please give some codes.

  • msplants's avatar
    msplants
    Frequent Visitor

    I was getting this same error in a native application using ADAL trying to access the PowerBI REST API. I had given all of the correct permissions in AAD as discussed in previous solutions, but had already received a token from a previous signin (before I gave the PowerBI Service permissions in AAD). My issue was that the previous token was stale and did not contain the updated claims. For me, the solution was to use PromptBehavior.RefreshSession as per the code below.

     

    AuthenticationResult result = await authenticationContext.AcquireTokenAsync(resourceId, clientId, redirectURI, new PlatformParameters(PromptBehavior.RefreshSession, false));

     

    As per MSDN, PromptBehavior.RefreshSession "Re-authorizes (through displaying webview) the resource usage, making sure that the resulting access token contains updated claims. If user logon cookies are available, the user will not be asked for credentials again and the logon dialog will dismiss automatically."

  • Please look at below blog post see it helps. 

     

    https://zappysys.com/blog/howto-import-json-rest-api-power-bi/

     

    Using ZappySys ODBC API drivers you can import any REST API.  

     

    Check below example how to use OAuth connection in ZappySys ODBC driver. You can select Custom Provider + OAuth 2.0 Version. Select Scope, Grant Type (i.e. Password Grant), Client ID, Userid, password.

     

    You can also supply non-standard OAuth attributes on Advanced Tab (e.g. resource=http://your-resource-url)

     

     

    ZappySys Driver - OAuth Configuration (Grant Type, Scope, Auth URL)

     

    ZappySys ODBC JSON Driver - Configure REST API callZappySys ODBC JSON Driver - SQL Query Preview (Read from JSON / XML / CSV File or REST API

    • visure's avatar
      visure
      Regular Visitor

      ZappySys I do not think it's the case of promoting a product on an important integration issue.