<?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 Re: Sign in screen comes after 60 mins even after fetching new token 10 mins before the expiration t in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Sign-in-screen-comes-after-60-mins-even-after-fetching-new-token/m-p/3679772#M49343</link>
    <description>&lt;P&gt;Hi&amp;nbsp; &lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/684349"&gt;@nkshriva&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you provide me with the code you are currently configuring to refresh the token periodically? If the login page is still popping up even after the AAD token is refreshed, could you try to add an action to refresh the report frontend page every half hour/ or 40 minutes? Make sure the session refreshes and doesn't expire?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;/P&gt;
&lt;P&gt;Liu Yang&lt;/P&gt;
&lt;P&gt;If this post &lt;STRONG&gt;helps&lt;/STRONG&gt;, then please consider &lt;EM&gt;Accept it as the solution&lt;/EM&gt; to help the other members find it more quickly.&lt;/P&gt;</description>
    <pubDate>Mon, 05 Feb 2024 09:10:51 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2024-02-05T09:10:51Z</dc:date>
    <item>
      <title>Sign in screen comes after 60 mins even after fetching new token 10 mins before the expiration time</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Sign-in-screen-comes-after-60-mins-even-after-fetching-new-token/m-p/3674588#M49277</link>
      <description>&lt;P&gt;I am using embedded powerbi report in my react application. I am encountering a problem where in order to avoid the token expiry and sign in screen, I am fetching a new token 10 mins before the expiration time as per the following documentation:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://learn.microsoft.com/en-us/javascript/api/overview/powerbi/refresh-token#refresh-the-access-token-directly" target="_blank" rel="noopener"&gt;https://learn.microsoft.com/en-us/javascript/api/overview/powerbi/refresh-token#refresh-the-access-token-directly&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But even after setting the new token, the page shows the sign-in screen. Can anyone suggest any solution to this?&lt;/P&gt;</description>
      <pubDate>Fri, 02 Feb 2024 04:23:30 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Sign-in-screen-comes-after-60-mins-even-after-fetching-new-token/m-p/3674588#M49277</guid>
      <dc:creator>nkshriva</dc:creator>
      <dc:date>2024-02-02T04:23:30Z</dc:date>
    </item>
    <item>
      <title>Re: Sign in screen comes after 60 mins even after fetching new token 10 mins before the expiration t</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Sign-in-screen-comes-after-60-mins-even-after-fetching-new-token/m-p/3679772#M49343</link>
      <description>&lt;P&gt;Hi&amp;nbsp; &lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/684349"&gt;@nkshriva&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you provide me with the code you are currently configuring to refresh the token periodically? If the login page is still popping up even after the AAD token is refreshed, could you try to add an action to refresh the report frontend page every half hour/ or 40 minutes? Make sure the session refreshes and doesn't expire?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;/P&gt;
&lt;P&gt;Liu Yang&lt;/P&gt;
&lt;P&gt;If this post &lt;STRONG&gt;helps&lt;/STRONG&gt;, then please consider &lt;EM&gt;Accept it as the solution&lt;/EM&gt; to help the other members find it more quickly.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2024 09:10:51 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Sign-in-screen-comes-after-60-mins-even-after-fetching-new-token/m-p/3679772#M49343</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-02-05T09:10:51Z</dc:date>
    </item>
    <item>
      <title>Re: Sign in screen comes after 60 mins even after fetching new token 10 mins before the expiration t</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Sign-in-screen-comes-after-60-mins-even-after-fetching-new-token/m-p/3687792#M49459</link>
      <description>&lt;LI-CODE lang="javascript"&gt;import { PowerBIEmbed } from 'powerbi-client-react';
import { useEffect, useState, useRef } from 'react';
import { useDispatch } from 'react-redux';
import { models } from 'powerbi-client';
import axios from 'services';
import { useLocation } from 'react-router-dom';
import { ButtonGroup, ButtonToolbar } from 'react-bootstrap';
import Button from 'Components/Button';
import TextField from 'Components/TextField';
import Spinner from 'Components/Spinner';
import {
  setSecondaryHeader
} from 'store/slice/headerInfo';

const ReportOne = () =&amp;gt; {
  const [report, setReport] = useState(null);
  const [config, setConfig] = useState({
    type: 'report',
    embedUrl: undefined,
    accessToken: undefined
  });
  const expirationTokenRef = useRef({});
  const reportRef = useRef({});
  const [edit, setEdit] = useState(false);
  const [name, setName] = useState('');
  const location = useLocation();
  const [isEmbedded, setIsEmbedded] = useState(false);
  const [isLoading, setIsLoading] = useState(true);
  // const [tokenExpiration, setTokenExpiration] = useState(null);
  const dispatch = useDispatch();

  useEffect(() =&amp;gt; {
    console.log(location);
    setIsLoading(true);
    if (!location) return;
    dispatch(setSecondaryHeader({
      path: 'Reports_View Reports',
      route: '/reports/view_reports',
      section: 'Reports',
      subSection: 'View Reports'
    }));
    let postfix;
    if (location.pathname.includes('paginated')) {
      postfix = location.pathname.split('paginated/')[1];
    } else {
      // postfix = location.pathname.split('report/')[1];
      postfix = location.pathname.split('nonpaginated/')[1];
    }
    // const postfix = location.pathname.split('report/')[1];

    (async () =&amp;gt; {
      const res = await axios.get(`pbi/report_embed_config?report_id=${postfix}`);
      console.log('expiration token', res.data?.expiration);
      const newConfig = {
        embedUrl: res.data?.report_details?.embed_url,
        accessToken: res.data?.token
      };
      if (location.pathname.includes('paginated')) {
        newConfig.uniqueId = res.data?.report_details?.report_id;
      } else {
        newConfig.id = res.data?.report_details?.report_id;
      }
      expirationTokenRef.current = res.data?.expiration;
      setConfig(newConfig);
      setIsEmbedded(true);
      setIsLoading(false);
    })();
  }, [location]);

  console.log(config);

  const updateToken = async reportId =&amp;gt; {
    console.log('inside update token');
    // Generate a new embed token or refresh the user Azure AD access token
    const newAccessToken = await axios.get(`pbi/report_embed_config?report_id=${reportId}`);

    // Update the new token expiration time
    // setTokenExpiration(newAccessToken.data?.expiration);
    expirationTokenRef.current = newAccessToken.data?.expiration;

    // Set the new access token
    await reportRef.current.setAccessToken(newAccessToken.data?.token);
  };

  const checkTokenAndUpdate = reportId =&amp;gt; {
    // Get the current time
    const currentTime = Date.now();
    const expiration = Date.parse(expirationTokenRef.current);

    // Time until token expiration in milliseconds
    const timeUntilExpiration = expiration - currentTime;
    const timeToUpdate = 10 * 60 * 1000;

    console.log(currentTime, expirationTokenRef.current, expiration, timeUntilExpiration, timeToUpdate);

    // Update the token if it is about to expired
    if (timeUntilExpiration &amp;lt;= timeToUpdate) {
      console.log(currentTime, expiration, timeUntilExpiration, timeToUpdate);
      let postfix;
      if (location.pathname.includes('paginated')) {
        postfix = location.pathname.split('paginated/')[1];
      } else {
        // postfix = location.pathname.split('report/')[1];
        postfix = location.pathname.split('nonpaginated/')[1];
      }
      console.log('Updating report access token');
      updateToken(postfix);
    }
  };

  useEffect(() =&amp;gt; {
    if (!report) return;
    if (edit) {
      report.switchMode('edit');
    } else {
      report.switchMode('view');
    }
  }, [edit, report]);

  useEffect(() =&amp;gt; {
    let postfix;
    if (location.pathname.includes('paginated')) {
      postfix = location.pathname.split('paginated/')[1];
    } else {
      // postfix = location.pathname.split('report/')[1];
      postfix = location.pathname.split('nonpaginated/')[1];
    }
    document.addEventListener('visibilitychange', function () {
      // Check the access token when the tab is visible
      console.log('visibilitychange');
      if (!document.hidden) {
        checkTokenAndUpdate(postfix);
      }
    });

    const tokenTimer = setInterval(() =&amp;gt; {
      checkTokenAndUpdate(postfix);
    }, 60000);

    return () =&amp;gt; {
      clearInterval(tokenTimer);
    };
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, []);

  return (
    &amp;lt;&amp;gt;
      {isLoading &amp;amp;&amp;amp; &amp;lt;Spinner type='content' /&amp;gt;}
      {!isLoading &amp;amp;&amp;amp;
        &amp;lt;div&amp;gt;
          &amp;lt;ButtonToolbar
            className='justify-content-between'
            style={{ margin: 8 }}&amp;gt;
            &amp;lt;ButtonGroup className='me-2'&amp;gt;
              &amp;lt;Button
                variant='primary'
                style={{
                  display: 'none'
                }}
                onClick={() =&amp;gt; setEdit(prev =&amp;gt; !prev)}&amp;gt;
                {edit ? 'View' : 'Edit'}
              &amp;lt;/Button&amp;gt;
            &amp;lt;/ButtonGroup&amp;gt;
            {edit &amp;amp;&amp;amp;
            &amp;lt;ButtonToolbar&amp;gt;
              &amp;lt;ButtonGroup className='me-2'&amp;gt;
                &amp;lt;Button
                  style={{ display: 'none' }}
                  variant='primary'
                  onClick={() =&amp;gt; report.save()}&amp;gt;
                  Save
                &amp;lt;/Button&amp;gt;
              &amp;lt;/ButtonGroup&amp;gt;
              &amp;lt;ButtonGroup className='me-2'&amp;gt;
                &amp;lt;TextField
                  className='me-2'
                  value={name}
                  onChange={e =&amp;gt; setName(e.target.value)} /&amp;gt;
              &amp;lt;/ButtonGroup&amp;gt;
              &amp;lt;ButtonGroup className='me-2'&amp;gt;
                &amp;lt;Button
                  variant='primary'
                  disabled
                  onClick={() =&amp;gt; {
                    report.saveAs({
                      name
                    });
                    setName('');
                  }}&amp;gt;
                  Save As
                &amp;lt;/Button&amp;gt;
              &amp;lt;/ButtonGroup&amp;gt;
            &amp;lt;/ButtonToolbar&amp;gt;}
          &amp;lt;/ButtonToolbar&amp;gt;
          {isEmbedded ? &amp;lt;PowerBIEmbed
            embedConfig={{
              ...config,
              type: 'report', // Supported types: report, dashboard, tile, visual, qna, paginated report and create
              tokenType: models.TokenType.Embed, // Use models.TokenType.Aad for SaaS embed
              settings: {
                panes: {
                  filters: {
                    expanded: false,
                    visible: false
                  }
                },
                background: models.BackgroundType.Transparent
              },
              permissions: models.Permissions.All
            // viewMode: models.viewMode.Edit
            }}
            cssClassName='reportClass'
            getEmbeddedComponent={embeddedReport =&amp;gt; {
              setReport(embeddedReport);
              reportRef.current = embeddedReport;
            }}
          /&amp;gt; : null}
        &amp;lt;/div&amp;gt;}
    &amp;lt;/&amp;gt;
  );
};

export default ReportOne;&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 08 Feb 2024 09:14:45 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Sign-in-screen-comes-after-60-mins-even-after-fetching-new-token/m-p/3687792#M49459</guid>
      <dc:creator>nkshriva</dc:creator>
      <dc:date>2024-02-08T09:14:45Z</dc:date>
    </item>
    <item>
      <title>Re: Sign in screen comes after 60 mins even after fetching new token 10 mins before the expiration t</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Sign-in-screen-comes-after-60-mins-even-after-fetching-new-token/m-p/3687795#M49460</link>
      <description>&lt;P&gt;This is the code which I am using to use embeded powerbi report.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2024 09:15:46 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Sign-in-screen-comes-after-60-mins-even-after-fetching-new-token/m-p/3687795#M49460</guid>
      <dc:creator>nkshriva</dc:creator>
      <dc:date>2024-02-08T09:15:46Z</dc:date>
    </item>
    <item>
      <title>Re: Sign in screen comes after 60 mins even after fetching new token 10 mins before the expiration t</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Sign-in-screen-comes-after-60-mins-even-after-fetching-new-token/m-p/3745576#M50120</link>
      <description>&lt;P&gt;@Anonymous&amp;nbsp;Can you please help? I am stuck on this issue&lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2024 09:21:18 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Sign-in-screen-comes-after-60-mins-even-after-fetching-new-token/m-p/3745576#M50120</guid>
      <dc:creator>nkshriva</dc:creator>
      <dc:date>2024-03-06T09:21:18Z</dc:date>
    </item>
    <item>
      <title>Re: Sign in screen comes after 60 mins even after fetching new token 10 mins before the expiration t</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Sign-in-screen-comes-after-60-mins-even-after-fetching-new-token/m-p/3745586#M50121</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;SPAN&gt;Make sure the session refreshes and doesn't expire?&lt;/SPAN&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="nkshriva_0-1709717068442.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1055073iC2EF4CDE74125D6E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="nkshriva_0-1709717068442.png" alt="nkshriva_0-1709717068442.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;How to ensure the session is not expired in 10 mins of tab inactivity? I noticed if the tab is inactive for 10 mins, the session expires automatically and I have to click Refresh button.&lt;/P&gt;&lt;P&gt;&amp;nbsp;@Anonymous&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2024 09:24:55 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Sign-in-screen-comes-after-60-mins-even-after-fetching-new-token/m-p/3745586#M50121</guid>
      <dc:creator>nkshriva</dc:creator>
      <dc:date>2024-03-06T09:24:55Z</dc:date>
    </item>
  </channel>
</rss>

