Created
October 5, 2018 09:55
-
-
Save krishnaanaril/0b4e331b9c61127ff37210fae9e47d81 to your computer and use it in GitHub Desktop.
Power BI embed token expiration listener method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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