Skip to content

Instantly share code, notes, and snippets.

@krishnaanaril
Created October 5, 2018 09:55
Show Gist options
  • Save krishnaanaril/0b4e331b9c61127ff37210fae9e47d81 to your computer and use it in GitHub Desktop.
Save krishnaanaril/0b4e331b9c61127ff37210fae9e47d81 to your computer and use it in GitHub Desktop.
Power BI embed token expiration listener method
setTokenExpirationListener(tokenExpiration,
minutesToRefresh = 2){
// get current time
var currentTime = Date.now();
var expiration = Date.parse(tokenExpiration);
var safetyInterval = minutesToRefresh * 60 * 1000;
// time until token refresh in milliseconds
var timeout = expiration - currentTime - safetyInterval;
// if token already expired, generate new token and set the access token
if (timeout <= 0) {
console.log("Updating Report Embed Token");
this.updateToken();
}
// set timeout so minutesToRefresh minutes before token expires, token will be updated
else {
console.log("Report Embed Token will be updated in " + timeout + " milliseconds.");
setTimeout(()=>{
this.updateToken();
}, timeout);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment