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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
dalby_sdu
New Member

Power BI Embedded log in

Hi,

 

We use Power BI Embedded to show reports to users that do not have a Power BI account.

 

We can login to PBI embedded and retrieve a Report.WebUrl but when we redirect to this page, Power BI requests login.

 

Our code is adapted from CriticalPathTraining and ported to .NET Core.

 

We wish to be able to show users the report without asking for login. It is our understanding that this should be possible with a PBI Embedded license.

 

    public class PbiEmbeddedManager
    {
        private static PowerBIClient GetPowerBiClient(PowerBiConfiguration powerBiConfiguration)
        {
           ClientCredential credential = new ClientCredential(powerBiConfiguration.ClientId, powerBiConfiguration.ClientSecret);

            AuthenticationContext authContext = new AuthenticationContext(powerBiConfiguration.AuthorityUri);
            string token = authContext.AcquireTokenAsync(powerBiConfiguration.ResourceUri, credential).Result.AccessToken;

            var tokenCredentials = new TokenCredentials(token, "Bearer");

            var client = new PowerBIClient(new Uri("https://api.powerbi.com/"), tokenCredentials);
            return client;
        }

        public static async Task<ReportViewModel> GetReports(PowerBiConfiguration powerBiConfiguration, string reportName)
        {
            var client = GetPowerBiClient(powerBiConfiguration);
            var reports = (await client.Reports.GetReportsInGroupAsync(powerBiConfiguration.AppWorkspaceId)).Value;

            Report report = reports.First(r => r.Name == reportName);

            var generateTokenRequestParameters = new GenerateTokenRequest(accessLevel: "view", datasetId: report.DatasetId);
           var token = client.Reports.GenerateTokenInGroupAsync(powerBiConfiguration.AppWorkspaceId, report.Id, generateTokenRequestParameters).Result;

            var embedConfig = new EmbedConfiguration()
            {
                EmbedToken = token,
                EmbedUrl = report.EmbedUrl,
                Id = report.Id
            };

            ReportViewModel reportViewModel = new ReportViewModel
            {
                Report = report,
                EmbedConfig = embedConfig
            };
            return reportViewModel;
        }
    }

 

We simpy Redirects to the URL in an MVC Core 2.1 controller (details removed):

 

    public class PowerBiController : Controller
    {
        public async Task<IActionResult> ShowReport()
        {
            PowerBiConfiguration powerBiConfiguration = ConfigurationHelper.GetPowerBiConfiguration(_configuration);
            ReportViewModel reportViewModel = await PbiEmbeddedManager.GetReports(powerBiConfiguration, "Glad Data from datamodel (Glad) with Excel Filer from SharePoint");
            return Redirect(reportViewModel.Report.WebUrl);
        }
    }

Can you tell us what we can do to make this work?

 

Thanks in advance

Soeren

 

 

This is our code:

2 REPLIES 2
v-diye-msft
Community Support
Community Support

Hi @dalby_sdu 

 

Based on my research, it's not accessible to share with users who do not have a power bi account. The viewer should be a Power bi free user at least. you can refer to the official document for more reference:

https://docs.microsoft.com/en-us/power-bi/service-embed-report-spo#grant-access-to-reports

 

Community Support Team _ Dina Ye
If this post helps, then please consider Accept it as the solution to help the other members find it more
quickly.
Anonymous
Not applicable

Hi,

I am afraid that there is a misunderstanding. We are using Power Bi Embedded Service in Azure (Paas).

Acording to the Microsoft Documentation we don't need Power BI account for our customers.

 

https://docs.microsoft.com/en-us/power-bi/developer/embedding

 

Best Regards

Kasia

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors