Forum Discussion

chares_has's avatar
chares_has
New Member
8 years ago
Solved

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-authentication-token-oauth

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.




  • Eric_Zhang's avatar
    Eric_Zhang
    8 years ago

    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.

3 Replies

  • Eric_Zhang's avatar
    Eric_Zhang
    Microsoft 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-authentication-token-oauth

    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.

    • chares_has's avatar
      chares_has
      New Member

      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

      • Eric_Zhang's avatar
        Eric_Zhang
        Microsoft Employee

        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.