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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
chares_has
New Member

PowerBI Embedded Token with PHP application

Hello everyone,

I'm actually trying to integrate PowerBi report into a Symfony application. 
Now what I do is create a script to get an embedded Token:


public function __construct($azureKey, $workSpaceCollectionName, $workSpaceCollectionId, $reportId)
    {
        $this->key = $azureKey;
        $this->payload = [
            'ver' => '0.2.0',
            'type' => 'embed',
            'wcn' => $workSpaceCollectionName,
            'wid' => $workSpaceCollectionId,
            'rid' => $reportId,
            'iss' => 'PowerBISDK',
            'aud' => 'https://analysis.windows.net/powerbi/api',
            'exp' => time() + 60 * 60,
            'nbf' => time(),
        ];
    }

    public function getToken()
    {
        return JWT::encode($this->payload, $this->key);
    }


Based on documentation:
https://docs.microsoft.com/en-us/azure/power-bi-embedded/power-bi-embedded-iframe
https://stackoverflow.com/questions/36694170/power-bi-embedded-from-php-obtain-an-azure-authenticati...

And then in the view is use this JS script:

<script>
        var accessToken = $('#accessToken').data('token');
        var reportToken = $('#reportToken').data('token');

        // Read embed URL from Model
        var embedUrl = "https://embedded.powerbi.com/appTokenReportEmbed?reportId=" + reportToken;


        var embedReportId = reportToken;

        var models = window['powerbi-client'].models;

        var config = {
            type: 'report',
            accessToken: accessToken,
            embedUrl: embedUrl,
            id: embedReportId,
            settings: {
                filterPaneEnabled: false,
                navContentPaneEnabled: false
            }
        };

        // Get a reference to the embedded report HTML element
        var reportContainer = $('#reportContainer')[0];

        // Embed the report and display it within the div container.
        var report = powerbi.embed(reportContainer, config);
    </script>


But actually the system return me :
GET https://wabi-us-east2-redirect.analysis.windows.net/metadata/cluster 403 (Forbidden)

The problem is porbably with the token and especially the AzureKey. As the powerBi is now deprecated in the AzurePortal, and or not accessible for new user, i can't access it. So I have created an application in azure active directory, and link powerBi in it, and setup correct permission.
Then i have generated a key for this application, and i'm using this key to generate access token. But as you can see is not working.
So don't really know what i'm doing wrong right now? 

Does anyone have an idea? 
Thx by advance.




1 ACCEPTED SOLUTION


@chares_has wrote:

AS I said, I can't access workspace collection, and anyway this method is deprecated and will be shutdown. So it doesn't make sense for our company. My question is, how we can have a proper key to embedded Microsoft Bi report in that case

Thx a lot


@chares_has

Getting access key in Azure portal is the only approach to get the proper "key" in that being deprecated Power BI Embedded. If you don't like it, you can consider the replacement Embedding with non-Power BI users (app owns data), just follow the tutorial. Note that in latter case, Premium license is required.

View solution in original post

3 REPLIES 3
Eric_Zhang
Employee
Employee


@chares_has wrote:

Hello everyone,

I'm actually trying to integrate PowerBi report into a Symfony application. 
Now what I do is create a script to get an embedded Token:


public function __construct($azureKey, $workSpaceCollectionName, $workSpaceCollectionId, $reportId)
    {
        $this->key = $azureKey;
        $this->payload = [
            'ver' => '0.2.0',
            'type' => 'embed',
            'wcn' => $workSpaceCollectionName,
            'wid' => $workSpaceCollectionId,
            'rid' => $reportId,
            'iss' => 'PowerBISDK',
            'aud' => 'https://analysis.windows.net/powerbi/api',
            'exp' => time() + 60 * 60,
            'nbf' => time(),
        ];
    }

    public function getToken()
    {
        return JWT::encode($this->payload, $this->key);
    }


Based on documentation:
https://docs.microsoft.com/en-us/azure/power-bi-embedded/power-bi-embedded-iframe
https://stackoverflow.com/questions/36694170/power-bi-embedded-from-php-obtain-an-azure-authenticati...

And then in the view is use this JS script:

<script>
        var accessToken = $('#accessToken').data('token');
        var reportToken = $('#reportToken').data('token');

        // Read embed URL from Model
        var embedUrl = "https://embedded.powerbi.com/appTokenReportEmbed?reportId=" + reportToken;


        var embedReportId = reportToken;

        var models = window['powerbi-client'].models;

        var config = {
            type: 'report',
            accessToken: accessToken,
            embedUrl: embedUrl,
            id: embedReportId,
            settings: {
                filterPaneEnabled: false,
                navContentPaneEnabled: false
            }
        };

        // Get a reference to the embedded report HTML element
        var reportContainer = $('#reportContainer')[0];

        // Embed the report and display it within the div container.
        var report = powerbi.embed(reportContainer, config);
    </script>


But actually the system return me :
GET https://wabi-us-east2-redirect.analysis.windows.net/metadata/cluster 403 (Forbidden)

The problem is porbably with the token and especially the AzureKey. As the powerBi is now deprecated in the AzurePortal, and or not accessible for new user, i can't access it. So I have created an application in azure active directory, and link powerBi in it, and setup correct permission.
Then i have generated a key for this application, and i'm using this key to generate access token. But as you can see is not working.
So don't really know what i'm doing wrong right now? 

Does anyone have an idea? 
Thx by advance.


@chares_has

The accesstoken for embedding has nothing to do with any Azure AD application. What is the "$this->key = $azureKey;" in your case? It shall be the accesskey of Power BI Workspace Collection, you can get it from Azure portal. The Power BI Workspace collection can't be created from Azure portal for new users, however if you already have an exsiting one, you can still access it.

Capture.PNG

AS I said, I can't access workspace collection, and anyway this method is deprecated and will be shutdown. So it doesn't make sense for our company. My question is, how we can have a proper key to embedded Microsoft Bi report in that case ? 

Thx a lot


@chares_has wrote:

AS I said, I can't access workspace collection, and anyway this method is deprecated and will be shutdown. So it doesn't make sense for our company. My question is, how we can have a proper key to embedded Microsoft Bi report in that case

Thx a lot


@chares_has

Getting access key in Azure portal is the only approach to get the proper "key" in that being deprecated Power BI Embedded. If you don't like it, you can consider the replacement Embedding with non-Power BI users (app owns data), just follow the tutorial. Note that in latter case, Premium license is required.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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