Tutorial: Embed Power BI content using a sample embed for your customers application

Embedded analytics and Power BI Embedded (the Azure offer) allow you to embed Power BI content such as reports, dashboards and tiles, into your application.

In this tutorial, you'll learn how to:

  • Set up your embedded environment.
  • Configure an embed for your customers (also known as app owns data) sample application.

To use your application, your users will not need to sign in to Power BI or have a Power BI license.

We recommend using the embed for your customers method to embed your Power BI content, if you're an independent software vendor (ISV) or a developer, who wants to create applications for third parties.

Code sample specifications

This tutorial includes instructions for configuring an embed for your customers sample application in one of the following frameworks:

  • .NET Framework
  • .NET Core
  • Java
  • Node JS
  • Python

The code samples support the following browsers:

  • Microsoft Edge
  • Google Chrome
  • Mozilla Firefox

Prerequisites

Before you start this tutorial, verify that you have both the Power BI and code dependencies listed below:

Method

To create an embed for your customers sample app, follow these steps:

  1. Select your authentication method.

  2. Register an Azure AD application.

  3. Create a Power BI workspace.

  4. Create and publish a Power BI report.

  5. Get the embedding parameter values.

  6. Service principal API access

  7. Enable workspace access.

  8. Embed your content.

Step 1 - Select your authentication method

Your embedded solution will vary depending on the authentication method you select. Therefore, it's important to understand the differences between the authentication methods, and decide which one best suits your solution.

The table below describes a few key differences between the service principal and master user authentication methods.

Consideration Service principal Master user
Mechanism Your Azure AD app's service principal object allows Azure AD to authenticate your embedded solution app against Power BI. Your Azure AD app uses the credentials (username and password) of a Power BI user, to authenticate against Power BI.
Security Service principal is the Azure AD recommended authorization method. If you're using a service principal,* you can authenticate using either an application secret or a certificate.

This tutorial only describes using service principal with an application secret. To embed using a service principal and a certificate, refer to the service principal with a certificate article.
This authentication method is not considered as secure as using a service principal. This is because you have to be vigilant with the master user credentials (username and password). For example, you must not expose them in your embedding application, and you should change the password frequently.
Azure AD delegated permissions Not required. Your master user or an administrator has to grant consent for your app to access Power BI REST API permissions (also known as scopes). For example, Report.ReadWrite.All.
Power BI service access You can't access Power BI service with a service principal. You can access Power BI service with your master user credentials.
License Doesn't require a Pro license. You can use content from any workspace that you're a member or an admin of. Requires a Power BI Pro license.

Step 2 - Register an Azure AD application

Registering your application with Azure AD allows you to:

To register your application with Azure AD, follow the instructions in Register your application.

Note

Before registering your application, you'll need to decide which authentication method to use, service principal or master user.

Step 3 - Create a Power BI workspace

Power BI keeps your reports, dashboards, and tiles in a workspace. To embed these items, you'll need to create them and upload them into a workspace.

Tip

If you already have a workspace, you can skip this step.

To create a workspace, do the following:

  1. Sign in to Power BI.

  2. Select Workspaces.

  3. Select Create a workspace.

  4. Name your workspace and select Save.

Step 4 - Create and publish a Power BI report

Your next step is to create a report and upload it to your workspace. You can create your own report using Power BI Desktop, and then publish it to your workspace. Or, you can upload a sample report to your workspace.

Tip

If you already have a workspace with a report, you can skip this step.

To download a sample report and publish it to your workspace, follow these steps:

  1. Open the GitHub Power BI Desktop samples folder.

  2. Select Code and then select Download zip.

    A screenshot showing the ZIP download option in the Power B I desktop samples GitHub

  3. Extract the downloaded ZIP and navigate to the Samples Reports folder.

  4. Select a report to embed, and publish it to your workspace.

Step 5 - Get the embedding parameter values

To embed your content, you'll need to obtain certain parameter values. The table below shows the required values, and indicates if they're applicable to the service principal authentication method, the master user authentication method, or both.

Before you embed your content, make sure you have all the values listed below. Some of the values will differ, depending on the authentication method you're using.

Parameter Service principal Master user
Client ID Applies to. Applies to.
Workspace ID Applies to. Applies to.
Report ID Applies to. Applies to.
Client secret Applies to. Does not apply to.
Tenant ID Applies to. Does not apply to.
Power BI username Does not apply to. Applies to.
Power BI password Does not apply to. Applies to.

Client ID

Tip

Applies to: Applies to.Service principal Applies to.Master user

To get the client ID GUID (also know as application ID), follow these steps:

  1. Log into Microsoft Azure.

  2. Search for App registrations and select the App registrations link.

  3. Select the Azure AD app your using for embedding your Power BI content.

  4. From the Overview section, copy the Application (client) ID GUID.

Workspace ID

Tip

Applies to: Applies to.Service principal Applies to.Master user

To get the workspace ID GUID, follow these steps:

  1. Sign in to Power BI service.

  2. Open the report you want to embed.

  3. Copy the GUID from the URL. The GUID is the number between /groups/ and /reports/.

    A screenshot showing workspace ID GUID in the Power B I service U R L

Report ID

Tip

Applies to: Applies to.Service principal Applies to.Master user

To get the report ID GUID, follow these steps:

  1. Sign in to Power BI service.

  2. Open the report you want to embed.

  3. Copy the GUID from the URL. The GUID is the number between /reports/ and /ReportSection.

    A screenshot showing report ID GUID in the Power B I service U R L

Client secret

Tip

Applies to: Applies to.Service principal Does not apply to.Master user

To get the client secret, follow these steps:

  1. Log into Microsoft Azure.

  2. Search for App registrations and select the App registrations link.

  3. Select the Azure AD app your using for embedding your Power BI content.

  4. Under Manage, select Certificates & secrets.

  5. Under Client secrets, select New client secret.

  6. In the Add a client secret pop-up window, provide a description for your application secret, select when the application secret expires, and select Add.

  7. From the Client secrets section, copy the string in the Value column of the newly created application secret. The client secret value is your client ID.

Tenant ID

Tip

Applies to: Applies to.Service principal Does not apply to.Master user

To get the tenant ID GUID, follow these steps:

  1. Log into Microsoft Azure.

  2. Search for App registrations and select the App registrations link.

  3. Select the Azure AD app your using for embedding your Power BI content.

  4. From the Overview section, copy the Directory (tenant) ID GUID.

Power BI username and password

Tip

Applies to: Does not apply to.Service principal Applies to.Master user

Obtain the username and password of the Power BI user you're using as your master user. This is the same user you used to create a workspace and upload a report to, in Power BI service.

Step 6 - Service principal API access

Tip

Applies to: Applies to.Service principal Does not apply to.Master user

This step is only relevant if you're using the service principal authentication method. If you're using a master user, skip this step and continue with Step 7 - Enable workspace access.

For an Azure AD app to be able to access the Power BI content and APIs, a Power BI admin needs to enable service principal access in the Power BI admin portal. If you're not the admin of your tenant, get the tenant's admin to enable the Tenant settings for you.

  1. In Power BI service, select Settings > Settings > Admin portal.

    A screenshot showing the admin settings menu option in the Power B I service settings menu

  2. Select Tenant settings and then scroll down to the Developer settings section.

  3. Expand Allow service principals to use Power BI APIs, and enable this option.

    A screenshot showing how to enable the developer settings option, in the tenant settings menu option, in Power B I service

Note

When using a service principal, it's recommended to limit its access to the tenant settings using a security group. To learn more about this feature, see these sections in the service principal article:

Step 7 - Enable workspace access

To enable your Azure AD app access artifacts such as reports, dashboards and datasets in the Power BI service, add the service principal or master user, as a member or admin to your workspace.

  1. Sign in to Power BI service.

  2. Scroll to the workspace you want to enable access for, and from the More menu, select Workspace access.

    Screenshot showing the workspace access button in the more menu of a Power BI workspace.

  3. In the Access pane, depending on which authentication method you're using, copy the service principal or master user to the Enter email address text box.

    Note

    If you're using a service principal, its name is the name you gave your Azure AD app.

  4. Select Add.

Step 8 - Embed your content

The Power BI embedded sample application allows you to create an embed for your customers Power BI app.

Follow these steps to modify the embed for your customers sample application, to embed your Power BI report.

  1. Open the Power BI developer samples folder.

  2. Select Code and then select Download zip.

    A screenshot showing the ZIP download option in the Power B I developer samples GitHub

  3. Extract the downloaded ZIP and navigate to the PowerBI-Developer-Samples-master folder.

  1. Depending on the language you want your application to use, open one of these folders:

    • .NET Core
    • .NET Framework
    • Java
    • Node JS
    • Python

    Note

    The embed for your customers sample applications only support the frameworks listed above. The React sample application only supports the embed for your organization solution.

  2. Open the Embed for your customers folder.

  1. Open the embed for your customers sample app using one of these methods:

  2. Open appsettings.json.

  3. Depending on your authentication method, fill in the following parameter values:

    Parameter Service principal Master user
    AuthenticationMode ServicePrincipal MasterUser
    ClientId Your Azure AD app client ID Your Azure AD app client ID
    TenantId Your Azure AD tenant ID N/A
    PbiUsername N/A Your master user username, see Power BI username and password
    PbiPassword N/A Your master user password, see Power BI username and password
    ClientSecret Your Azure AD client secret N/A
    WorkspaceId The ID of the workspace with your embedded report, see Workspace ID The ID of the workspace with your embedded report, see Workspace ID
    ReportId The ID of the report you're embedding, see Report ID The ID of the report you're embedding, see Report ID
  4. Run the project by selecting the appropriate option:

    • If you're using Visual Studio, select IIS Express (play).

    • If you're using Visual Studio Code, select Run > Start Debugging.

Developing your application

After configuring and running the embed for your customers sample application, you can start developing your own application.

When you're ready, review the move to production requirements. You'll also need a capacity, and should review the capacity planning article to establish which SKU best suites your needs.

Next steps