microsoft / powerbi-client-react

Power BI for React which provides components and services to enabling developers to easily embed Power BI reports into their applications.
MIT License
308 stars 98 forks source link

Token expire issue after 10 min. How to get token without refresh? #77

Closed Sushmasrig closed 2 years ago

Sushmasrig commented 2 years ago

After every 10 min token is getting expired and giving 401, but it is not generating new tokens. But after page refresh, a new token is generated and it is working fine. Is there any way to get a new token without page refresh. If possible any working example is really appreciated.

versions: "powerbi-client-react": "^1.3.5", "react": "^18.0.0", node: v14.18.1 npm version: 6.14.15

function getEmbeddedComponent() {
    return function (embeddedReport) {
        window.report = embeddedReport;
    };
}

         <PowerBIEmbed   
                        embedConfig={{
                            type: 'report',
                            id: reportId,
                            embedUrl: `url here`,
                            accessToken: token,
                            tokenType: models.TokenType.Embed,
                        }}
                        cssClassName={'report-style-class'}
                        getEmbeddedComponent={getEmbeddedComponent()}
                    />
khchan commented 2 years ago

If you have an instance of the report you can follow the example here to add your own token refresh logic.

Sushmasrig commented 2 years ago

I added logic to make token API call after a certain interval of time, which resolved my issue.