Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
sjorg
Frequent Visitor

Authentication and Read/Write using Javascript API

Trying to do something really really simple - but it seems like you have to scale a 100ft wall every step of the way.

 

Background:

 

1) I'd like to use this https://github.com/Microsoft/PowerBI-JavaScript API wrapper to push data / embed PowerBI reports in an "App Owns Data" scenario, authenticating server-side.

 

2) Following this tutorial, but can't get past the first step

https://docs.microsoft.com/en-us/power-bi/developer/walkthrough-push-data

 

 

Problem:

 

1) Before I can even authenticate, need to register an app. Ok. Tried to follow this https://docs.microsoft.com/en-us/power-bi/developer/register-app.

 

But, amazingly, the dev.powerbi.com/apps page is broken.

So now, tried to register via the azure portal. I got the ClientID by doing this, but where do I get the ClientSecret, to call the API server side?

 

2) Let's assume I have the ClientID and ClientSecret. Trying to follow this tutorial now: https://docs.microsoft.com/en-us/power-bi/developer/get-azuread-access-token

 

But this only has examples using C# auth libraries. And while https://msdn.microsoft.com/library/mt784614.aspx might work for getting Embed Tokens for individual reports etc, I don't think it works for Pushing Data to Datasets.

So I tried to use this:

https://github.com/AzureAD/azure-activedirectory-library-for-js

The closest code sample I can find is

adalAuthenticationServiceProvider.init(
        {
            // Config to specify endpoints and similar for your app
            tenant: "52d4b072-9470-49fb-8721-bc3a1c9912a1", // Optional by default, it sends common
            clientId: "e9a5a8b6-8af7-4719-9821-0deef255f68e", // Required
            //localLoginUrl: "/login",  // optional
            //redirectUri : "your site", optional
            endpoints: endpoints  // If you need to send CORS api requests.
        }
)

 but I don't think even this works because there is no ClientSecret being used. 

 

How do I authenticate to AAD from server-side javascript??

 

 

3>Let's assume I now have an Access Token , that I can  theoretically use with https://github.com/Microsoft/PowerBI-JavaScript

 

How do I construct an authenticated API request using that library? Documentation here  https://powerbi.docs.apiary.io/#introduction/authenticate-with-power-bi says to use an Authorization header entry, but that's for a vanilla REST request...what's the syntax for the API wrapper?

 

I'm not sure if this process was made intentionally convoluted + lacking in any examples, but I can't imagine how anyone new to this actually uses it. If anyone has any code samples, esp for the authentication piece, I would be very grateful.

 

Any help is appreciated. Thanks!

1 ACCEPTED SOLUTION
Eric_Zhang
Employee
Employee

@sjorg

 

As far as I know, the Power BI JavaScript wrapper is only for embedding purpose. It is not for pushing data at all. As to the "App Owns Data" scenario, it usually requires a Native app, so no client_secret is involved. For your interest, you can referece Creating the application Client ID and Client Secret from Microsoft Azure new portal

 

To get an accesstoken for pushing data, it is the ADAL lib, the github lib you've already known. You can reference sample in @Anonymous last reply in this thread

 

By the way, why all in Javascript? For "App Owns Data", it actually uses a master account. While using ADAL, you'll have to do the authentication through a pop up log-on window. I'm not an expert on ADAL however I doubt ADAL would support to do the authentication by passing username&&password instead of the pop-up. Even it supports, I don't think it is a good idea to hard coded the username&&password in your Javascript or Web page, it is definitely risky.

View solution in original post

1 REPLY 1
Eric_Zhang
Employee
Employee

@sjorg

 

As far as I know, the Power BI JavaScript wrapper is only for embedding purpose. It is not for pushing data at all. As to the "App Owns Data" scenario, it usually requires a Native app, so no client_secret is involved. For your interest, you can referece Creating the application Client ID and Client Secret from Microsoft Azure new portal

 

To get an accesstoken for pushing data, it is the ADAL lib, the github lib you've already known. You can reference sample in @Anonymous last reply in this thread

 

By the way, why all in Javascript? For "App Owns Data", it actually uses a master account. While using ADAL, you'll have to do the authentication through a pop up log-on window. I'm not an expert on ADAL however I doubt ADAL would support to do the authentication by passing username&&password instead of the pop-up. Even it supports, I don't think it is a good idea to hard coded the username&&password in your Javascript or Web page, it is definitely risky.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.