Last active
March 9, 2022 23:09
-
-
Save bradyclifford/efac5438c1a6c1c9834db4a63940371e to your computer and use it in GitHub Desktop.
Session Keep alive on 3rd Party
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
// Function runs on an interval as the user is using the 3rd party site | |
function() { | |
return function() { | |
var xhr = new XMLHttpRequest(); | |
xhr.onreadystatechange = function() { | |
console.debug('Refresh token response', xhr); | |
if (xhr.status >= 200 && xhr.status < 300) return; | |
console.warn('Failed to refresh of token'); | |
}; | |
/** | |
* Refreshes cookie token | |
* @param {url} string containing the URL of the Account Management Session refresh endpoint | |
*/ | |
function refreshToken(url) { | |
if (!url) throw new Exception('[WTW:IM] token refresh Url missing'); | |
xhr.open('GET', url); | |
xhr.setRequestHeader('Content-Type', 'application/json'); | |
xhr.withCredentials = true; | |
xhr.send(); | |
} | |
refreshToken('https://app.viabenefits.com/account/session-refresh'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment