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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

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
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.