<?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: Power BI Embed - get embed token with Azure Functions in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-Embed-get-embed-token-with-Azure-Functions/m-p/2702477#M37906</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/332010"&gt;@cdout&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;You can refer the following links to get it:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://docs.microsoft.com/en-us/power-bi/developer/embedded/embed-tokens?tabs=embed-for-customers#embed-token" target="_self"&gt;Embedded analytics application tokens&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://docs.microsoft.com/en-us/power-bi/developer/embedded/embed-sample-for-customers?tabs=net-core" target="_self"&gt;Tutorial: Embed Power BI content using a sample embed for your customers' application&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://docs.microsoft.com/en-us/power-bi/developer/embedded/embed-service-principal" target="_self"&gt;Embed Power BI content with service principal and an application secret&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.youtube.com/watch?v=271LkXJ8niM" target="_self"&gt;Embed Power BI Report for Customers using App Own Concept and Service Principal&lt;/A&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;FONT size="3"&gt;&lt;A href="https://github.com/Dhruvinshah16/PBI-Embedded-ASP.NET/tree/master/PBI-Embedded-App-Owns-Data" target="_self"&gt;Authenticate-ServicePrincipal/Embed for your customers&lt;/A&gt;&lt;/FONT&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="yingyinr_0-1660638114307.png" style="width: 999px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/765701i8886D7A7B7BEC845/image-size/large?v=v2&amp;amp;px=999" role="button" title="yingyinr_0-1660638114307.png" alt="yingyinr_0-1660638114307.png" /&gt;&lt;/span&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Best Regards&lt;/P&gt;</description>
    <pubDate>Tue, 16 Aug 2022 08:44:14 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2022-08-16T08:44:14Z</dc:date>
    <item>
      <title>Power BI Embed - get embed token with Azure Functions</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-Embed-get-embed-token-with-Azure-Functions/m-p/2696028#M37843</link>
      <description>&lt;P&gt;I have a Power BI Embed application through an AD Azure registration on an "embed for your customers" method with a service principal.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have been following this Taygan tutorial to embed power bi into my applications using Azure Functions. Link to the blog - &lt;A href="https://www.taygan.co/blog/2018/05/14/embedded-analytics-with-power-bi" target="_blank"&gt;https://www.taygan.co/blog/2018/05/14/embedded-analytics-with-power-bi&lt;/A&gt;.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need help passing the service principal instead of the username and password authentication, see lines in this section below:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; // Authenticate with Azure Ad &amp;gt; Get Access Token &amp;gt; Get Token Credentials&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;STRONG&gt; var credential = new UserPasswordCredential(username, password);&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var authenticationContext = new AuthenticationContext(authorityUrl);&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;STRONG&gt; var authenticationResult = await authenticationContext.AcquireTokenAsync(resourceUrl, clientId, credential);&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; string accessToken = authenticationResult.AccessToken;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This blog is four years old so the code may need updating in general. Any thoughts on updating it are very welcome.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks, C.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;#r "Newtonsoft.Json"

using System.Configuration;

using System.Net;

using System.Text;

using System.Web.Script.Serialization;

using Microsoft.IdentityModel.Clients;

using Microsoft.PowerBI.Api.V2;

using Microsoft.PowerBI.Api.V2.Models;

using Microsoft.Rest;

//added MS declarations here

using Microsoft.AspNetCore.Mvc;

using Microsoft.Extensions.Primitives;

using Newtonsoft.Json;





// Static Values



//Comment out Taygan's authorityURL for the new one

//static string authorityUrl = "https://login.windows.net/common/oauth2/authorize/";

static string authorityUrl: "https://login.microsoftonline.com/organizations/",

//Add authentication mode of "Service Principal" reference back to the Function App settings

Static string authenticationmode = ConfigurationManager.AppSettings["PBIE_AUTHENTICATION_MODE"]

static string resourceUrl = "https://analysis.windows.net/powerbi/api";

static string apiUrl = "https://api.powerbi.com/";

static string clientId = ConfigurationManager.AppSettings["PBIE_CLIENT_ID"];

//Added for client secret

Static string clientsecret =  ConfigurationManager.AppSettings["PBIE_CLIENT_SECRET"];

//Comment out Taygan's username and password auth

//static string username = ConfigurationManager.AppSettings["PBIE_USERNAME"];

//static string password = ConfigurationManager.AppSettings["PBIE_PASSWORD"];

static string groupId = ConfigurationManager.AppSettings["PBIE_GROUP_ID"];

static string reportId = ConfigurationManager.AppSettings["PBIE_REPORT_ID"];



public static async Task&amp;lt;HttpResponseMessage&amp;gt; Run(HttpRequestMessage req, TraceWriter log)

{



    // Authenticate with Azure Ad &amp;gt; Get Access Token &amp;gt; Get Token Credentials

    var credential = new UserPasswordCredential(username, password);

    var authenticationContext = new AuthenticationContext(authorityUrl);

    var authenticationResult = await authenticationContext.AcquireTokenAsync(resourceUrl, clientId, credential);

    string accessToken = authenticationResult.AccessToken;

    var tokenCredentials = new TokenCredentials(accessToken, "Bearer");

   

    using (var client = new PowerBIClient(new Uri(apiUrl), tokenCredentials))

    {

        // Embed URL

        Report report = client.Reports.GetReportInGroup(groupId, reportId);

        string embedUrl = report.EmbedUrl;



        // Embed Token

        var generateTokenRequestParameters = new GenerateTokenRequest(accessLevel: "view");

        EmbedToken embedToken = client.Reports.GenerateTokenInGroup(groupId, reportId, generateTokenRequestParameters);



        // JSON Response

        EmbedContent data = new EmbedContent();

        data.EmbedToken = embedToken.Token;

        data.EmbedUrl = embedUrl;

        data.ReportId = reportId;

        JavaScriptSerializer js = new JavaScriptSerializer();

        string jsonp = "callback(" +  js.Serialize(data) + ");";



        // Return Response

        return new HttpResponseMessage(HttpStatusCode.OK)

        {

            Content = new StringContent(jsonp, Encoding.UTF8, "application/json")

        };

    }

}



public class EmbedContent

{

    public string EmbedToken { get; set; }

    public string EmbedUrl { get; set; }

    public string ReportId { get; set; }

}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Aug 2022 19:06:16 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-BI-Embed-get-embed-token-with-Azure-Functions/m-p/2696028#M37843</guid>
      <dc:creator>cdout</dc:creator>
      <dc:date>2022-08-11T19:06:16Z</dc:date>
    </item>
    <item>
      <title>Re: Power BI Embed - get embed token with Azure Functions</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-Embed-get-embed-token-with-Azure-Functions/m-p/2702477#M37906</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/332010"&gt;@cdout&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;You can refer the following links to get it:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://docs.microsoft.com/en-us/power-bi/developer/embedded/embed-tokens?tabs=embed-for-customers#embed-token" target="_self"&gt;Embedded analytics application tokens&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://docs.microsoft.com/en-us/power-bi/developer/embedded/embed-sample-for-customers?tabs=net-core" target="_self"&gt;Tutorial: Embed Power BI content using a sample embed for your customers' application&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://docs.microsoft.com/en-us/power-bi/developer/embedded/embed-service-principal" target="_self"&gt;Embed Power BI content with service principal and an application secret&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.youtube.com/watch?v=271LkXJ8niM" target="_self"&gt;Embed Power BI Report for Customers using App Own Concept and Service Principal&lt;/A&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;FONT size="3"&gt;&lt;A href="https://github.com/Dhruvinshah16/PBI-Embedded-ASP.NET/tree/master/PBI-Embedded-App-Owns-Data" target="_self"&gt;Authenticate-ServicePrincipal/Embed for your customers&lt;/A&gt;&lt;/FONT&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="yingyinr_0-1660638114307.png" style="width: 999px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/765701i8886D7A7B7BEC845/image-size/large?v=v2&amp;amp;px=999" role="button" title="yingyinr_0-1660638114307.png" alt="yingyinr_0-1660638114307.png" /&gt;&lt;/span&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Best Regards&lt;/P&gt;</description>
      <pubDate>Tue, 16 Aug 2022 08:44:14 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-BI-Embed-get-embed-token-with-Azure-Functions/m-p/2702477#M37906</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-08-16T08:44:14Z</dc:date>
    </item>
    <item>
      <title>Re: Power BI Embed - get embed token with Azure Functions</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-Embed-get-embed-token-with-Azure-Functions/m-p/2753865#M38485</link>
      <description>&lt;P&gt;Hello yingyinr and thank you for the reply. This above links aren't working for me because they use the method of embedding through a coded application loaded to the client website. I tried that and it works in a local host.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am looking for details using the method of an Azure Function App to run all of the code because my client doesn't allow a .net or vs code or other project to be loaded. The client only allows a one-page HTML and/or JS script.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm looking for a methodology where the bulk of the work of getting the embed token and calling the api is done outside of the client, such as the az function app. Any thoughts?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards, cdout&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Sep 2022 20:07:12 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-BI-Embed-get-embed-token-with-Azure-Functions/m-p/2753865#M38485</guid>
      <dc:creator>cdout</dc:creator>
      <dc:date>2022-09-07T20:07:12Z</dc:date>
    </item>
    <item>
      <title>Re: Power BI Embed - get embed token with Azure Functions</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-Embed-get-embed-token-with-Azure-Functions/m-p/3320299#M43398</link>
      <description>&lt;P&gt;Hi, I am in the same situation. Did you get around the solution for this one? Thanks in advance!"&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2023 11:33:28 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-BI-Embed-get-embed-token-with-Azure-Functions/m-p/3320299#M43398</guid>
      <dc:creator>gaupop</dc:creator>
      <dc:date>2023-07-07T11:33:28Z</dc:date>
    </item>
  </channel>
</rss>

