Quantcast
Channel: Service topics
Viewing all articles
Browse latest Browse all 61890

Power BI Embedded log in

$
0
0

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:


Viewing all articles
Browse latest Browse all 61890

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>