Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
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.
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
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": "**********"
}
}
User | Count |
---|---|
14 | |
2 | |
1 | |
1 | |
1 |
User | Count |
---|---|
16 | |
11 | |
5 | |
4 | |
3 |