Forum Discussion

pkmelee337's avatar
pkmelee337
New Member
9 years ago
Solved

Power BI Rest Api with the ADAL JS library

Hi,   In a web part I am creating (only JS) I am using the javascript ADAL library to authenticate users and retrieve access tokens. I have set up te correct registration in AD, found a report ID, ...
  • Eric_Zhang's avatar
    9 years ago

    pkmelee337 wrote:

    Hi,

     

    In a web part I am creating (only JS) I am using the javascript ADAL library to authenticate users and retrieve access tokens. I have set up te correct registration in AD, found a report ID, ADAL config is correct with the right enpoint, client ID and I am retrieving the access token with the correct graph resource. So far, so good.

     

    Now when I am trying to retrieve an embed report (using the npm powerbi-client package or via jquery post) I am getting the 403 (Forbidden) error. I tried googling stackoverflow and this forum, found some answers and all off them came back to the same solution: "add username and password to your login call".

     

    Haven't tried it so far because it is not even possible to add it in the default adal js library (as far as I know), but in an javascript app this will for sure result in an security issue. Where do I store the username and password or does the user have to login every time he accesses the power bi web part?

     

    Am I missing something and how do you guys handle this problem?

     

    With kind regards,

    Henk ter Harmsel


    pkmelee337

    Since this is not Azure AD forum, so we may not give you better support for ADAL JS library.

     

    However I can still give you my two cents.

    At first, please ensure that you've grant sufficient permissions to the registered app.

    Secondly, based on my test, username and password are not mandatory. Based on my test, the accesstoken generated from authorization code approach can work to get the reports from Power BI.

    You need.

    1. send a GET request

    https://login.windows.net/common/oauth2/authorize?client_id={client_id}
    &response_type=code
    &redirect_uri={redirect_uri of your registered app}

    2. send a POST request

    POST /common/oauth2/token HTTP/1.1
    Host: login.windows.net
    Content-Type: application/x-www-form-urlencoded
    Cache-Control: no-cache
    Postman-Token: 990496e9-1d11-7aa5-faf7-f3dc152e8beb
    
    client_secret={client_secret}&client_id={client_id}&grant_type=authorization_code&resource=https%3A%2F%2Fanalysis.windows.net%2Fpowerbi%2Fapi&redirect_uri={redirect_uri}&code={code from above}