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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
moizsherwani
Continued Contributor
Continued Contributor

PowerBI Embed Issue

We need to embed a powerBI report into our website dashboard.

To access a powerBI report, the user needs to be authorized and authenticated.

For this we authenticate the user using Microsoft Office 365 Online Services, using the code below:

var settings = {
"async": true,
"crossDomain": true,
"url": "https://login.microsoftonline.com/6c7d5dfa-3948-4782-b5a0-6fd1b2825ae3/oauth2/token",
"method": "POST",
"headers": {
"Content-Type": "application/x-www-form-urlencoded",
"Cache-Control": "no-cache",
},
"data": {
"grant_type": "password",
"scope": "openid",
"resource": "https://analysis.windows.net/powerbi/api",
"client_id": "e701f962-2236-434d-8974-19b649b34590",
"username": "w******@exceedgulf.com",
"password": "**********"
}
}

$.ajax(settings).done(function (response) {
console.log(response);
});

Above code snippet works fine if we access using local machine, or a developer tool like Fiddler or Postman. But when we deploy the same code on our website which is hosted on Azure with a custom domain associated with it. We get an error related to

"Failed to load https://login.microsoftonline.com/...../oauth/token: Resposne to preflight request does not pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://exoppdev.azurewebsites.net' is therefore not allowed access.

After investigating from multiple blogs and forums, we almost tried every resolution that can possibly resolve the issue but till not we are not able to load the report from online hosted environment.

Need help regarding above issue.

Thanks,

Moiz
Was I able to answer your question? Mark my post as a solution to help others. Kudos if you liked the solution.
2 REPLIES 2
v-jiascu-msft
Employee
Employee

Hi @moizsherwani,

 

As we can see from the error message, it seems not the issues caused by Power BI. Please refer to docs/Web/HTTP/CORS and Headers/Access-Control-Allow-Origin.

I would suggest you mask these ids in your post.

 

Best Regards,

Dale

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

The CORS problem is not on our side, but on the Microsoft end.

 

We are the Calling party, so we cannot set the response headers.

 

We make call to Microsoft online rest api services, and it works locally and not from domain.

 

var settings = {

"async": true,

"crossDomain": true,

"url": "https://login.microsoftonline.com/6c7d5dfa-3948-4782-b5a0-6fd1b2825ae3/oauth2/token",

"method": "POST",

"headers": {

"Content-Type": "application/x-www-form-urlencoded",

"Cache-Control": "no-cache",

},

"data": {

"grant_type": "password",

"scope": "openid",

"resource": "https://analysis.windows.net/powerbi/api",

"client_id": "e701f962-2236-434d-8974-19b649b34590",

"username": "w******@exceedgulf.com",

"password": "**********"

}

}

Thanks,

Moiz
Was I able to answer your question? Mark my post as a solution to help others. Kudos if you liked the solution.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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