0
votes

I am trying to generate an embed token for a report by calling below endpoint but it thorws me CORS issue.

Failed to load https://api.powerbi.com/myorg/groups//reports//GenerateToken: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access. The response had HTTP status code 403.

Is there any setting in power bi dashboard or enable CORS and set allowed origins?

2

2 Answers

-1
votes

you shouldn't get cors issue if you called power api in server side code. No setting changes required in powerbi dashboard. Please share code snippet if you can.

-3
votes

CORS is a browser security feature that disallows cross site referencing. Hence there isn't any setting on the PowerBI part to get it fixed. We earlier worked with the REST APIs but faced CORS issue on almost every browser. Using the CORS plugin for Chrome fixed the issue. But can't expect every user to install the client side plugin.

As a work around, we took the WebAPI approach, wherein our client side script hit the WebAPI endpoint, communicated with the PowerBI service to return the report. To overcome the CORS issue this way, add a reference to System.Web.Cors in the WebConfig.cs file found under App_Start folder and add the line config.EnableCors();

In the Controller, decorate the method with EnableCors as shown below and that should resolve your problem:

namespace MyNameSpace.MyControllers
{
    public class MyAPIController : ApiController
    { 
       [HttpPOST]
       [EnableCors(origins: "*", headers: "*", methods: "*")]
       public string getData()
       {
          return "This Works !";
       }
    }
}