locked
[Node.js][Web Apps] Power BI A.P.I Authentication RRS feed

  • Question

  • I am currently trying to make a call to the power b.i a.p.i so that I can use it for my application and understand how to make api calls to microsoft api's. I have not been able to get a response from the api. I get an unauthorized error, that no access control allow origin header is present on the requested resource. I come from a front-end background where I am used to making API calls using javascript and angular.js. I am not familiar with the microsoft API and how it must be authorized. I have tried to read articles but they go over my head. 

    The errors are as follows- 

     Failed to load resource: the server responded with a status of 404 (Not Found)

    XMLHttpRequest: cannot load https://api.powerbi.com/v1.0/myorg/dashboards. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://renniesb.github.io' is therefore not allowed access. The response had HTTP status code 404.

        nope

    Repository with my project code- https://github.com/Renniesb/sample_dashboard/tree/gh-pages

    File with Power B.I API call - https://github.com/Renniesb/sample_dashboard/blob/gh-pages/app/services/powerbi.service.js

    expected behavior- Show power bi dashboards in the console to test the communication between the app and the power bi A.P.I

    Test site: https://Renniesb.github.io/sample_dashboard

    To test I authorize with my credentials. How would I let users of this forum test the behavior. How do I enable their credentials?


    List of things I've tried already- 
    • Created a reverse proxy using the following website: http://shawnsimondeveloper.com/nodeproxyangular/
    • Used the JSONP hack to attempt to get around CORS problem.

    • Tested the site both locally and on a webpage on github



    Sunday, January 3, 2016 3:29 PM

Answers

  • It seems that your issue is occurred in the getting access token for power bi rest api.

    I followed Authenticate to Power BI service and Authorization Code Grant Flow leveraging Postman to get access token for power bi rest api, the set the token in authorization header in angular app in $http to have a test. It worked fine.

    Request an authorization code

    Authorization Code Request

    leverage access token in angular:

    $http.get('https://api.powerbi.com/beta/myorg/dashboards', {
    headers: {'Authorization': 'Bearer eyJ0-XXXXXXX-XXXXXX-XXXXXXX-SR9A'}
    }).success(function(data, status, headers, config){
    console.log(data)
    })

    Additionally, If you'd like to use angular to get access tokens, you can refer to https://github.com/AzureAD/azure-activedirectory-library-for-js 

    Monday, January 4, 2016 2:54 AM