<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Auto return to loin page when PBI report embeded to html in 1~3 hours in Report Server</title>
    <link>https://community.fabric.microsoft.com/t5/Report-Server/Auto-return-to-loin-page-when-PBI-report-embeded-to-html-in-1-3/m-p/4029532#M35848</link>
    <description>&lt;P&gt;I published my report to premium workspace and embed to html iframe.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;And Open the html, click the login button in powerBI frame, power bi report shown normally, and keep this page shown and not close.&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial black,avant garde"&gt;After 1.5 hours, the power bi report in iframe will auto return to login page&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Is there any solution to avoid powerbi report in iframe auto return to login page and keep report shown forever?&lt;/P&gt;</description>
    <pubDate>Mon, 08 Jul 2024 07:09:06 GMT</pubDate>
    <dc:creator>BigDinosaur</dc:creator>
    <dc:date>2024-07-08T07:09:06Z</dc:date>
    <item>
      <title>Auto return to loin page when PBI report embeded to html in 1~3 hours</title>
      <link>https://community.fabric.microsoft.com/t5/Report-Server/Auto-return-to-loin-page-when-PBI-report-embeded-to-html-in-1-3/m-p/4029532#M35848</link>
      <description>&lt;P&gt;I published my report to premium workspace and embed to html iframe.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;And Open the html, click the login button in powerBI frame, power bi report shown normally, and keep this page shown and not close.&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial black,avant garde"&gt;After 1.5 hours, the power bi report in iframe will auto return to login page&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Is there any solution to avoid powerbi report in iframe auto return to login page and keep report shown forever?&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jul 2024 07:09:06 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Report-Server/Auto-return-to-loin-page-when-PBI-report-embeded-to-html-in-1-3/m-p/4029532#M35848</guid>
      <dc:creator>BigDinosaur</dc:creator>
      <dc:date>2024-07-08T07:09:06Z</dc:date>
    </item>
    <item>
      <title>Re: Auto return to loin page when PBI report embeded to html in 1~3 hours</title>
      <link>https://community.fabric.microsoft.com/t5/Report-Server/Auto-return-to-loin-page-when-PBI-report-embeded-to-html-in-1-3/m-p/4030452#M35857</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="771871" data-lia-user-login="BigDinosaur" class="lia-mention lia-mention-user"&gt;BigDinosaur&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To prevent a Power BI report in an iframe from automatically returning to the login page after a period of inactivity, you need to ensure that the session is kept active. This typically involves periodically refreshing the authentication token or the iframe itself to keep the session active.&lt;/P&gt;&lt;P&gt;You can set up a JavaScript timer to refresh the iframe periodically before the session expires. This method will reload the entire iframe, which may not be ideal if the report is interactive, but it is a simple solution.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;Power BI Report&amp;lt;/title&amp;gt;
    &amp;lt;script type="text/javascript"&amp;gt;
        function refreshIframe() {
            var iframe = document.getElementById("powerBIReport");
            iframe.src=iframe.src;
        }

        // Set the interval to refresh the iframe every hour (3600000 ms)
        setInterval(refreshIframe, 3600000);
    &amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;iframe id="powerBIReport" width="800" height="600" src="YOUR_POWER_BI_EMBED_URL"&amp;gt;&amp;lt;/iframe&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;If you are using the Power BI JavaScript API, you can refresh the authentication token periodically. This approach is more seamless because it keeps the session active without reloading the iframe. Here is an example using the Power BI JavaScript API:&lt;BR /&gt;Initial Token Acquisition: Get the initial embed token.&lt;BR /&gt;Token Refresh Mechanism: Set up a mechanism to refresh the token periodically.&lt;BR /&gt;Here is a basic example using the Power BI JavaScript SDK:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;Power BI Report&amp;lt;/title&amp;gt;
    &amp;lt;script src="https://cdn.jsdelivr.net/npm/powerbi-client@2.12.0/dist/powerbi.js"&amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;script type="text/javascript"&amp;gt;
        var embedUrl = "YOUR_POWER_BI_EMBED_URL";
        var initialToken = "YOUR_INITIAL_EMBED_TOKEN";  // Fetch your initial token from the server
        var embedConfig = {
            type: 'report',
            tokenType: models.TokenType.Embed,
            accessToken: initialToken,
            embedUrl: embedUrl,
            id: 'YOUR_REPORT_ID'
        };

        function embedPowerBIReport() {
            var reportContainer = document.getElementById('reportContainer');
            var report = powerbi.embed(reportContainer, embedConfig);
            
            // Set up a mechanism to refresh the token
            setInterval(function() {
                // Fetch a new token from your server
                fetch('YOUR_TOKEN_REFRESH_ENDPOINT')
                    .then(response =&amp;gt; response.json())
                    .then(data =&amp;gt; {
                        var newToken = data.newToken;
                        report.setAccessToken(newToken);
                    });
            }, 3500000); // Refresh token every ~58 minutes (before the 1-hour expiration)
        }

        window.onload = embedPowerBIReport;
    &amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;div id="reportContainer" style="width: 800px; height: 600px;"&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;Your backend service should handle authentication with Azure AD and generate new tokens upon request&lt;/P&gt;&lt;P&gt;Backend Service (Node.js)&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;const express = require('express');
const axios = require('axios');
const app = express();
const port = 3000;

// Endpoint to refresh the token
app.get('/refresh-token', async (req, res) =&amp;gt; {
    try {
        const tokenResponse = await axios.post('https://login.microsoftonline.com/YOUR_TENANT_ID/oauth2/v2.0/token', {
            grant_type: 'client_credentials',
            client_id: 'YOUR_CLIENT_ID',
            client_secret: 'YOUR_CLIENT_SECRET',
            scope: 'https://analysis.windows.net/powerbi/api/.default'
        });
        
        const newToken = tokenResponse.data.access_token;

        // Generate the embed token with the new access token
        const embedTokenResponse = await axios.post('https://api.powerbi.com/v1.0/myorg/reports/YOUR_REPORT_ID/GenerateToken', {
            accessLevel: 'View'
        }, {
            headers: {
                'Authorization': `Bearer ${newToken}`
            }
        });

        res.json({ newToken: embedTokenResponse.data.token });
    } catch (error) {
        res.status(500).send(error.toString());
    }
});

app.listen(port, () =&amp;gt; {
    console.log(`Server running at http://localhost:${port}`);
});&lt;/LI-CODE&gt;&lt;P&gt;This backend service should be secure and properly authenticated, and your frontend will call it periodically to get new tokens.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;hackcrr&lt;/P&gt;&lt;P&gt;If this post helps, then please consider&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;&lt;STRONG&gt;Accept it as the solution&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/EM&gt;and&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;&lt;STRONG&gt;kudos to this post&lt;/STRONG&gt;&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;to help the other members find it more quickly&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jul 2024 13:56:13 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Report-Server/Auto-return-to-loin-page-when-PBI-report-embeded-to-html-in-1-3/m-p/4030452#M35857</guid>
      <dc:creator>hackcrr</dc:creator>
      <dc:date>2024-07-08T13:56:13Z</dc:date>
    </item>
  </channel>
</rss>

