<?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 Power BI Report Embed using JavaScript in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-Report-Embed-using-JavaScript/m-p/967238#M22642</link>
    <description>&lt;P&gt;Hello -&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm embedding Power BI Reports into another application using JavaScript and I could generate access token (Barear) using below JavaScript code but it doesn't work in all the browsers. It displays below error message.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT&gt;Access to XMLHttpRequest at '&lt;A target="_blank" rel="noopener"&gt;https://login.microsoftonline.com/&amp;lt;&amp;lt;tenant_id&amp;gt;&amp;gt;/oauth2/token&lt;/A&gt;' from origin 'null' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT&gt;I added required request headers but still the same result. &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;	 var key;  
	 var request = new XMLHttpRequest(); 
    request.open("POST", "https://login.microsoftonline.com/&amp;lt;&amp;lt;tenant_id&amp;gt;&amp;gt;/oauth2/token", true); 
  
	request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	request.setRequestHeader('Access-Control-Allow-Headers', 'x-requested-with');
	request.setRequestHeader('Access-Control-Allow-Origin', '*');
    request.send("grant_type=client_credentials&amp;amp;client_id=&amp;lt;&amp;lt;clientid&amp;gt;&amp;gt;&amp;amp;client_secret=&amp;lt;&amp;lt;clientsecret&amp;gt;&amp;gt;&amp;amp;resource:&amp;lt;&amp;lt;resourceurl&amp;gt;&amp;gt;"); // specify the credentials to receive the token on request
    request.onreadystatechange = function () {
        if (request.readyState == request.DONE) {
            var response = request.responseText;
            var obj = JSON.parse(response); 
            key = obj.access_token; 
            token_ = key; 
        }
    }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Any ideas?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P class="ics-element-donot-delete 1001_CC@"&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 10 Mar 2020 16:43:06 GMT</pubDate>
    <dc:creator>mittalpatel130</dc:creator>
    <dc:date>2020-03-10T16:43:06Z</dc:date>
    <item>
      <title>Power BI Report Embed using JavaScript</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-Report-Embed-using-JavaScript/m-p/967238#M22642</link>
      <description>&lt;P&gt;Hello -&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm embedding Power BI Reports into another application using JavaScript and I could generate access token (Barear) using below JavaScript code but it doesn't work in all the browsers. It displays below error message.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT&gt;Access to XMLHttpRequest at '&lt;A target="_blank" rel="noopener"&gt;https://login.microsoftonline.com/&amp;lt;&amp;lt;tenant_id&amp;gt;&amp;gt;/oauth2/token&lt;/A&gt;' from origin 'null' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT&gt;I added required request headers but still the same result. &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;	 var key;  
	 var request = new XMLHttpRequest(); 
    request.open("POST", "https://login.microsoftonline.com/&amp;lt;&amp;lt;tenant_id&amp;gt;&amp;gt;/oauth2/token", true); 
  
	request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	request.setRequestHeader('Access-Control-Allow-Headers', 'x-requested-with');
	request.setRequestHeader('Access-Control-Allow-Origin', '*');
    request.send("grant_type=client_credentials&amp;amp;client_id=&amp;lt;&amp;lt;clientid&amp;gt;&amp;gt;&amp;amp;client_secret=&amp;lt;&amp;lt;clientsecret&amp;gt;&amp;gt;&amp;amp;resource:&amp;lt;&amp;lt;resourceurl&amp;gt;&amp;gt;"); // specify the credentials to receive the token on request
    request.onreadystatechange = function () {
        if (request.readyState == request.DONE) {
            var response = request.responseText;
            var obj = JSON.parse(response); 
            key = obj.access_token; 
            token_ = key; 
        }
    }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Any ideas?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P class="ics-element-donot-delete 1001_CC@"&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2020 16:43:06 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-BI-Report-Embed-using-JavaScript/m-p/967238#M22642</guid>
      <dc:creator>mittalpatel130</dc:creator>
      <dc:date>2020-03-10T16:43:06Z</dc:date>
    </item>
    <item>
      <title>Re: Power BI Report Embed using JavaScript</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-Report-Embed-using-JavaScript/m-p/974073#M22691</link>
      <description>&lt;P&gt;The browser is blocking the request because you are getting data back from a domain that is not the same as your site. That's a good thing for security reasons. You'll want to execute that request outside of the browser. In my implementation, I have this piece running on an extremely basic Node server using express to expose it to the front end.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 14 Mar 2020 00:40:08 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-BI-Report-Embed-using-JavaScript/m-p/974073#M22691</guid>
      <dc:creator>csjames010</dc:creator>
      <dc:date>2020-03-14T00:40:08Z</dc:date>
    </item>
    <item>
      <title>Re: Power BI Report Embed using JavaScript</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-Report-Embed-using-JavaScript/m-p/976247#M22707</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/214006"&gt;@csjames010&lt;/a&gt; !&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes, I found out below code which uses ADAL.js, but my question is what should be the redirect_uri in my Azure AD app so that below &lt;STRONG&gt;code returns the id_token to ServiceNow Page and further we can access it for embed report javascript&lt;/STRONG&gt;? Currently when I execute this code, it successfully generates the id_token in browser URL after login.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;script src="https://secure.aadcdn.microsoftonline-p.com/lib/1.0.14/js/adal.min.js"&amp;gt;&amp;lt;/script&amp;gt;

&amp;lt;body&amp;gt;
&amp;lt;a href="#" onclick="login();"&amp;gt;login&amp;lt;/a&amp;gt;
&amp;lt;a href="#" onclick="getToken()"&amp;gt;access token&amp;lt;/a&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;script type="text/javascript"&amp;gt;
    var configOptions = {
        tenant: &amp;lt;tenantid&amp;gt;, // Optional by default, it sends common
        clientId: &amp;lt;clientid&amp;gt;,
        redirectUri: "https://login.live.com/oauth20_desktop.srf",
        postLogoutRedirectUri: window.location.origin,
    }
    window.authContext = new AuthenticationContext(configOptions);

    var isCallback = authContext.isCallback(window.location.hash);
    authContext.handleWindowCallback();

    function getToken(){
        authContext.acquireToken("https://graph.microsoft.com",function(error, token){
            console.log(error);
            console.log(token);
        })
    }
    function login(){
        authContext.login();
    }
&amp;lt;/script&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Mar 2020 14:21:50 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-BI-Report-Embed-using-JavaScript/m-p/976247#M22707</guid>
      <dc:creator>mittalpatel130</dc:creator>
      <dc:date>2020-03-16T14:21:50Z</dc:date>
    </item>
    <item>
      <title>Re: Power BI Report Embed using JavaScript</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-Report-Embed-using-JavaScript/m-p/978538#M22728</link>
      <description>&lt;P&gt;Sorry - wish I could help more, there. I'm not really that familiar with the msft libraries. I've prototyped user owns and app owns data scenarios in my app, but both methods are just using POST requests on the auth endpoints on my backend server opposed to leveraging the libraries.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Mar 2020 16:44:43 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-BI-Report-Embed-using-JavaScript/m-p/978538#M22728</guid>
      <dc:creator>csjames010</dc:creator>
      <dc:date>2020-03-17T16:44:43Z</dc:date>
    </item>
  </channel>
</rss>

