<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Embed Power BI dashboard in ASP.Net core in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Embed-Power-BI-dashboard-in-ASP-Net-core/m-p/284314#M8436</link>
    <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The above suggestion from Eric_Zang won't work for Asp .Net Core as the UserPasswordCredentials is not supported in .NET Core. See:&amp;nbsp;&lt;A href="https://github.com/AzureAD/azure-activedirectory-library-for-dotnet/issues/482" target="_blank"&gt;https://github.com/AzureAD/azure-activedirectory-library-for-dotnet/issues/482&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I&amp;nbsp;came across the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;same issues&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;recently. My work-around was to use make a native REST call to the Azure AD for a token. I was pointed to this approach here:&amp;nbsp;&lt;A href="https://github.com/Microsoft/PowerBI-CSharp/issues/116" target="_blank"&gt;https://github.com/Microsoft/PowerBI-CSharp/issues/116&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My solution is as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Replace the following from&amp;nbsp;&lt;SPAN&gt;Eric_Zang's example&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;var credential = new UserPasswordCredential(Username, Password);

// Authenticate using created credentials
var authenticationContext = new AuthenticationContext(AuthorityUrl);
var authenticationResult = await authenticationContext.AcquireTokenAsync(ResourceUrl, ClientId, credential);&lt;/PRE&gt;&lt;P&gt;with:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;var authenticationResult = await AuthenticateAsync();

private static async Task&amp;lt;OAuthResult&amp;gt; AuthenticateAsync()
{
    var oauthEndpoint = new Uri(AuthorityUrl);

    using (var client = new HttpClient())
    {
        var result = await client.PostAsync(oauthEndpoint, new FormUrlEncodedContent(new[]
        {
            new KeyValuePair&amp;lt;string, string&amp;gt;("resource", ResourceUrl),
            new KeyValuePair&amp;lt;string, string&amp;gt;("client_id", ClientId),
            new KeyValuePair&amp;lt;string, string&amp;gt;("grant_type", "password"),
            new KeyValuePair&amp;lt;string, string&amp;gt;("username", Username),
            new KeyValuePair&amp;lt;string, string&amp;gt;("password", Password),
            new KeyValuePair&amp;lt;string, string&amp;gt;("scope", "openid"),
        }));

        var content = await result.Content.ReadAsStringAsync();
        return JsonConvert.DeserializeObject&amp;lt;OAuthResult&amp;gt;(content);
    }
}

class OAuthResult
{
    [JsonProperty("token_type")]
    public string TokenType { get; set; }
    [JsonProperty("scope")]
    public string Scope { get; set; }
    [JsonProperty("experies_in")]
    public int ExpiresIn { get; set; }
    [JsonProperty("ext_experies_in")]
    public int ExtExpiresIn { get; set; }
    [JsonProperty("experies_on")]
    public int ExpiresOn { get; set; }
    [JsonProperty("not_before")] 
    public int NotBefore { get; set; }
    [JsonProperty("resource")]
    public Uri Resource { get; set; }
    [JsonProperty("access_token")]
    public string AccessToken { get; set; }
    [JsonProperty("refresh_token")]
    public string RefreshToken { get; set; }
}&lt;/PRE&gt;&lt;P&gt;I understand that using the OAuth Password grant&amp;nbsp;was removed from ADAL for .NET Core to strongly discourage transporting and&amp;nbsp;saving user credentials.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like very much for a recommended approach for using PowerBI Embedded in as Asp .Net Core app.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;P&gt;Jeremy&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 20 Oct 2017 17:06:30 GMT</pubDate>
    <dc:creator>jhorgan</dc:creator>
    <dc:date>2017-10-20T17:06:30Z</dc:date>
    <item>
      <title>Embed Power BI dashboard in ASP.Net core</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Embed-Power-BI-dashboard-in-ASP-Net-core/m-p/273279#M8229</link>
      <description>&lt;P&gt;Dear All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We would like to Embed power bi dashboard in ASP.Net core web application not MVC based. I am struggling get a working example nor I am able to find step-by-step process to build this feature.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Eveyone leads into following exampe which is build on MVC,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://powerbi.microsoft.com/en-us/documentation/powerbi-developer-embed-sample-app-owns-data/" target="_blank"&gt;https://powerbi.microsoft.com/en-us/documentation/powerbi-developer-embed-sample-app-owns-data/&lt;/A&gt; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone suggest me how to embed power bi dashboard on core asp.net web application.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Prasanna V.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Oct 2017 11:02:20 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Embed-Power-BI-dashboard-in-ASP-Net-core/m-p/273279#M8229</guid>
      <dc:creator>send2prasan</dc:creator>
      <dc:date>2017-10-09T11:02:20Z</dc:date>
    </item>
    <item>
      <title>Re: Embed Power BI dashboard in ASP.Net core</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Embed-Power-BI-dashboard-in-ASP-Net-core/m-p/273730#M8240</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/36509"&gt;@send2prasan&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Dear All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We would like to Embed power bi dashboard in ASP.Net core web application not MVC based. I am struggling get a working example nor I am able to find step-by-step process to build this feature.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Eveyone leads into following exampe which is build on MVC,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://powerbi.microsoft.com/en-us/documentation/powerbi-developer-embed-sample-app-owns-data/" target="_blank"&gt;https://powerbi.microsoft.com/en-us/documentation/powerbi-developer-embed-sample-app-owns-data/&lt;/A&gt; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can someone suggest me how to embed power bi dashboard on core asp.net web application.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Prasanna V.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/36509"&gt;@send2prasan&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Where are you stuck? Here's a static HTML for your reference.&lt;/P&gt;
&lt;PRE&gt;&amp;lt;html&amp;gt;
&amp;lt;script src="https://microsoft.github.io/PowerBI-JavaScript/demo/node_modules/jquery/dist/jquery.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script src="https://microsoft.github.io/PowerBI-JavaScript/demo/node_modules/powerbi-client/dist/powerbi.js"&amp;gt;&amp;lt;/script&amp;gt;

&amp;lt;script type="text/javascript"&amp;gt; 
window.onload = function () {
 // Read embed application token from Model
    var accessToken = "H4sIAAAAAAAEAC2Wxa7FDHKExxxxxxxxigEVoLAAA=";

    // Read embed URL from Model
    var embedUrl = "https://msit.powerbi.com/dashboardEmbed?dashboardId=66d6daxxxxx96-13e88c1cbdde&amp;amp;groupId=dc581184-a20xxxxx6b6c15";

    // Read dashboard Id from Model
    var embedDashboardId = "66d6dafxxxx-13e88c1cbdde";

    // Get models. models contains enums that can be used.
    var models = window['powerbi-client'].models	

    // Embed configuration used to describe the what and how to embed.
    // This object is used when calling powerbi.embed.
    // This also includes settings and options such as filters.
    // You can find more information at https://github.com/Microsoft/PowerBI-JavaScript/wiki/Embed-Configuration-Details.
    var config = {
        type: 'dashboard',
        tokenType: models.TokenType.Embed,
        accessToken: accessToken,
        embedUrl: embedUrl,
		pageView: "fitToWidth",
        id: embedDashboardId
    };

    // Get a reference to the embedded dashboard HTML element
    var dashboardContainer = $('#dashboardContainer')[0] ;

    // Embed the dashboard and display it within the div container.
    var dashboard = powerbi.embed(dashboardContainer, config); 	 
} 
&amp;lt;/script&amp;gt; 
&amp;lt;p&amp;gt;&amp;lt;input type="hidden" id="Textinput" /&amp;gt;&amp;lt;/p&amp;gt; 
&amp;lt;div id="dashboardContainer"&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;/html&amp;gt;  &lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As to how to get the embedded token, you can reference below snippet or the REST API&amp;nbsp;&lt;A href="https://msdn.microsoft.com/en-us/library/mt784614.aspx" target="_self"&gt;GenerateToken&lt;/A&gt;&lt;/P&gt;
&lt;PRE&gt;           string ClientId = {clientid of the registered native app};
            // Create a user password cradentials.
            var credential = new UserPasswordCredential(Username, Password);

            // Authenticate using created credentials
            var authenticationContext = new AuthenticationContext(AuthorityUrl);
            var authenticationResult = await authenticationContext.AcquireTokenAsync(ResourceUrl, ClientId, credential);

            if (authenticationResult == null)
            {
                return View(new EmbedConfig()
                {
                    ErrorMessage = "Authentication Failed."
                });
            }

            var tokenCredentials = new TokenCredentials(authenticationResult.AccessToken, "Bearer");

            // Create a Power BI Client object. It will be used to call Power BI APIs.
            using (var client = new PowerBIClient(new Uri(ApiUrl), tokenCredentials))
            {
                // Get a list of dashboards.
                var dashboards = await client.Dashboards.GetDashboardsInGroupAsync(GroupId);

                // Get the first report in the group.
                var dashboard = dashboards.Value.FirstOrDefault();

                if (dashboard == null)
                {
                    return View(new EmbedConfig()
                    {
                        ErrorMessage = "Group has no dashboards."
                    });
                }

                // Generate Embed Token.
                var generateTokenRequestParameters = new GenerateTokenRequest(accessLevel: "view");
                var embedToken= await client.Dashboards.GenerateTokenInGroupAsync(GroupId, dashboard.Id, generateTokenRequestParameters);
&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Oct 2017 03:04:41 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Embed-Power-BI-dashboard-in-ASP-Net-core/m-p/273730#M8240</guid>
      <dc:creator>Eric_Zhang</dc:creator>
      <dc:date>2017-10-10T03:04:41Z</dc:date>
    </item>
    <item>
      <title>Re: Embed Power BI dashboard in ASP.Net core</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Embed-Power-BI-dashboard-in-ASP-Net-core/m-p/284314#M8436</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The above suggestion from Eric_Zang won't work for Asp .Net Core as the UserPasswordCredentials is not supported in .NET Core. See:&amp;nbsp;&lt;A href="https://github.com/AzureAD/azure-activedirectory-library-for-dotnet/issues/482" target="_blank"&gt;https://github.com/AzureAD/azure-activedirectory-library-for-dotnet/issues/482&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I&amp;nbsp;came across the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;same issues&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;recently. My work-around was to use make a native REST call to the Azure AD for a token. I was pointed to this approach here:&amp;nbsp;&lt;A href="https://github.com/Microsoft/PowerBI-CSharp/issues/116" target="_blank"&gt;https://github.com/Microsoft/PowerBI-CSharp/issues/116&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My solution is as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Replace the following from&amp;nbsp;&lt;SPAN&gt;Eric_Zang's example&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;var credential = new UserPasswordCredential(Username, Password);

// Authenticate using created credentials
var authenticationContext = new AuthenticationContext(AuthorityUrl);
var authenticationResult = await authenticationContext.AcquireTokenAsync(ResourceUrl, ClientId, credential);&lt;/PRE&gt;&lt;P&gt;with:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;var authenticationResult = await AuthenticateAsync();

private static async Task&amp;lt;OAuthResult&amp;gt; AuthenticateAsync()
{
    var oauthEndpoint = new Uri(AuthorityUrl);

    using (var client = new HttpClient())
    {
        var result = await client.PostAsync(oauthEndpoint, new FormUrlEncodedContent(new[]
        {
            new KeyValuePair&amp;lt;string, string&amp;gt;("resource", ResourceUrl),
            new KeyValuePair&amp;lt;string, string&amp;gt;("client_id", ClientId),
            new KeyValuePair&amp;lt;string, string&amp;gt;("grant_type", "password"),
            new KeyValuePair&amp;lt;string, string&amp;gt;("username", Username),
            new KeyValuePair&amp;lt;string, string&amp;gt;("password", Password),
            new KeyValuePair&amp;lt;string, string&amp;gt;("scope", "openid"),
        }));

        var content = await result.Content.ReadAsStringAsync();
        return JsonConvert.DeserializeObject&amp;lt;OAuthResult&amp;gt;(content);
    }
}

class OAuthResult
{
    [JsonProperty("token_type")]
    public string TokenType { get; set; }
    [JsonProperty("scope")]
    public string Scope { get; set; }
    [JsonProperty("experies_in")]
    public int ExpiresIn { get; set; }
    [JsonProperty("ext_experies_in")]
    public int ExtExpiresIn { get; set; }
    [JsonProperty("experies_on")]
    public int ExpiresOn { get; set; }
    [JsonProperty("not_before")] 
    public int NotBefore { get; set; }
    [JsonProperty("resource")]
    public Uri Resource { get; set; }
    [JsonProperty("access_token")]
    public string AccessToken { get; set; }
    [JsonProperty("refresh_token")]
    public string RefreshToken { get; set; }
}&lt;/PRE&gt;&lt;P&gt;I understand that using the OAuth Password grant&amp;nbsp;was removed from ADAL for .NET Core to strongly discourage transporting and&amp;nbsp;saving user credentials.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like very much for a recommended approach for using PowerBI Embedded in as Asp .Net Core app.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;P&gt;Jeremy&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 17:06:30 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Embed-Power-BI-dashboard-in-ASP-Net-core/m-p/284314#M8436</guid>
      <dc:creator>jhorgan</dc:creator>
      <dc:date>2017-10-20T17:06:30Z</dc:date>
    </item>
    <item>
      <title>Re: Embed Power BI dashboard in ASP.Net core</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Embed-Power-BI-dashboard-in-ASP-Net-core/m-p/390773#M11614</link>
      <description>&lt;P&gt;It's quite annoying that Microsoft were&amp;nbsp;only able to provide samples for a full .net framework and not for .net core. At the same time, MS' AD team decides not to include UserName/Password authentication in .net standard version of the framework&lt;/P&gt;</description>
      <pubDate>Fri, 06 Apr 2018 02:42:14 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Embed-Power-BI-dashboard-in-ASP-Net-core/m-p/390773#M11614</guid>
      <dc:creator>borlip</dc:creator>
      <dc:date>2018-04-06T02:42:14Z</dc:date>
    </item>
    <item>
      <title>Re: Embed Power BI dashboard in ASP.Net core</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Embed-Power-BI-dashboard-in-ASP-Net-core/m-p/708981#M19591</link>
      <description>&lt;P&gt;So when is Microsoft going to provide a sample for Net Core? I have been migrating my SaaS app from MVC to Net COre 2.2 in order to be ready for 3.0 which will go preview live soon and there still isn't a way to get Power BI Embedded to work. While that may have been an acceptable level of support when MS was charging only $10/month for Power BI Embedded, under the current pricing tier, they need to do &lt;U&gt;&lt;STRONG&gt;much&lt;/STRONG&gt;&lt;/U&gt; better. Net Core 3.0 is supposed to be the wave of the future.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jun 2019 01:52:04 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Embed-Power-BI-dashboard-in-ASP-Net-core/m-p/708981#M19591</guid>
      <dc:creator>OutdoorEd</dc:creator>
      <dc:date>2019-06-07T01:52:04Z</dc:date>
    </item>
    <item>
      <title>Re: Embed Power BI dashboard in ASP.Net core</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Embed-Power-BI-dashboard-in-ASP-Net-core/m-p/808046#M20964</link>
      <description>&lt;P&gt;Are there any updates to this? We are moving to .Net Core 3.0 and it would be nice to have examples to guide us through the process.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Oct 2019 14:18:34 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Embed-Power-BI-dashboard-in-ASP-Net-core/m-p/808046#M20964</guid>
      <dc:creator>vega</dc:creator>
      <dc:date>2019-10-02T14:18:34Z</dc:date>
    </item>
    <item>
      <title>Re: Embed Power BI dashboard in ASP.Net core</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Embed-Power-BI-dashboard-in-ASP-Net-core/m-p/1679250#M27982</link>
      <description>&lt;P&gt;Hi, I tried this solution, but got null response. content is empty due to 404 Status code - Not Found.&lt;/P&gt;&lt;P&gt;Any idea what can cause this status, please?&lt;/P&gt;</description>
      <pubDate>Sun, 21 Feb 2021 17:09:34 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Embed-Power-BI-dashboard-in-ASP-Net-core/m-p/1679250#M27982</guid>
      <dc:creator>saramoshe</dc:creator>
      <dc:date>2021-02-21T17:09:34Z</dc:date>
    </item>
  </channel>
</rss>

