microsoft / powerbi-client-angular

Power BI Angular component. This library lets you embed Power BI report, dashboard, dashboard tile, report visual, or Q&A in your Angular application.
Other
135 stars 65 forks source link

Can someone please explain how the token is delivered? #50

Closed RupenAnjaria closed 10 months ago

RupenAnjaria commented 11 months ago

As per the code we are calling an API: https://aka.ms/CaptureViewsReportEmbedConfig This API returns token and other details. I don't understand what the API URL is doing? is it just returning some hardcoded data? If I have a PowerBI report then how can I generate these details?

Thank you.

v-MadhavC commented 11 months ago

Hello, in order to embed a Power BI report using powerbi-client-angular we have to pass reportID, embedURL and embedToken. In order to generate embedURL and embedToken for you Power BI report please follow the following documentations:

Embed URL: In order to generate embed URL we need to pass groupID. https://learn.microsoft.com/en-us/rest/api/power-bi/reports/get-reports-in-group#code-try-0

Embed Token: In order to generate embed Token we need to pass groupID and reportID along with the requestBody.

image

https://learn.microsoft.com/en-us/rest/api/power-bi/embed-token/reports-generate-token-in-group#code-try-0

Hope this helps, if you still have some queries, please feel free to reach out to us.

RupenAnjaria commented 11 months ago

Thank you for the quick response. This was really helpful as I was able to integrate my report.

Questions:

  1. Is there any authentication for those APIs? or just passing GroupId and Reportid is enough.
  2. Will GroupId stay same for all my PowerBI reports within my company? I believe so.
  3. May I please see what is the code for https://aka.ms/CaptureViewsReportEmbedConfig? I mean, what is it doing behind the scene? Is it calling two APIs and combining the results?
  4. Is there any way we can get Embed URL and ReportID straight from the PowerBI portal?

Thanks again.

v-MadhavC commented 11 months ago
  1. The Authentication type is based on the scenario in which you are trying to embed your Power BI content:
  2. Yes, if all the Power BI reports within your company are in the same workspace. Group ID is basically an unique ID for your Power BI workspace. All the reports in same workspace will have same Group ID.
  3. Please refer to this repository: powerbi-embedded-React-demo/GenerateToken.csx
  4. Yes, you can get both Embed URL and Report ID from Power BI Service.
    • Embed URL: Open a report, click on file on the top left corner, click on Embed report, click on Website or portal.
    • Report ID: open the report, You will be able to see Report ID in the URL.

Hope this helps, please reach out to use in case of any other queries.

RupenAnjaria commented 10 months ago

That was helpful and I am seems making progress, however regarding the URL you shared (https://learn.microsoft.com/en-us/rest/api/power-bi/reports/get-reports-in-group#code-try-0) I am just curious about from where does it gets the token in the playground section:

See the image below: image

This is the only last piece where I am stuck.

I tried to bet token like this:

https://stackoverflow.com/questions/77796971/getting-bearer-access-token-for-powerbi

but that didn't work and gave me 401 unauthorized error.

KotanaSai21 commented 10 months ago

@RupenAnjaria , The Error you're facing while getting the Embed URL PowerBINotAuthorizedException is due to either Unauthorized group or wrong group Id. Refer Troubleshoot documentation for the Error details.

Refer to this documentation Embed using service principal. Follow the steps, where you need to add service principal to your workspace. Then You would be able to hit the API and get the Embed URL.

Feel free to reach out if you have any other queries.

RupenAnjaria commented 10 months ago

Sure, but I am able to integrate the report even without these settings. Here is what I did:

  1. Visit sample
  2. Copy the Bearer token
  3. Make a call to https://api.powerbi.com/v1.0/myorg/groups/{groupid}/reports/{reportid} using the token
  4. Copy the EmbedURL from the response
  5. Use above values (token and URL) in your Angular demo app (in app.component.ts:
    // Update the reportConfig to embed the PowerBI report
    this.reportConfig = {
      ...this.reportConfig,
      id: '{reportID}', //reportConfigResponse.Id,
      embedUrl: '{embedURL}',  //reportConfigResponse.EmbedUrl,
      accessToken:  '{token}', //reportConfigResponse.EmbedToken.Token,
    };

if I take a token from it is working fine. So not sure if we have to make additional changes in the Entra. Please suggest.

RupenAnjaria commented 10 months ago

@KotanaSai21 Please close this as I was able to integrate after allowing the Entra app in powerbi workspace.

jaspreet1234567 commented 10 months ago

@RupenAnjaria - From where you getting the bearer token? I am bit confused here. Here is my understanding, Please correct me if I'm wrong:

Thanks in advance.