Forum Discussion
Embed token refresh for long-lived sessions: how do you do it in a SPA?
Hi jubinsoni
Yes, you are on the right track. For app-owns-data, getting a new embed token from your backend and calling report.setAccessToken() lets you renew it without reloading the report.
Five minutes before expiry is a reasonable starting point. The main change is to schedule the next refresh after each successful renewal, using the new token’s expiration your current timer runs only once.
A few things to watch:
- Recheck expiry when the tab becomes visible or connectivity returns, since background timers can be delayed. Avoid overlapping refresh requests.
- Retry temporary failures with limited, increasing delays rather than immediately reloading. If the user’s application session has expired, prompt them to sign in again.
- If the token expires while offline, obtain a valid token once connectivity returns and try setAccessToken() before considering re-embedding.
For multiple reports, call setAccessToken() on each report instance. You can renew once and reuse that token only if it covers all those reports and the appropriate customer/RLS identity; otherwise, renew their tokens separately.
One important distinction: the SDK’s accessTokenProvider automatic-refresh hook is for user-owns-data, not app-owns-data.
References: Token refresh guidance · Multi-resource embed tokens
Regards,
Microsoft Fabric Community Support