Skip to content

Instantly share code, notes, and snippets.

@bradyclifford
Last active March 9, 2022 23:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bradyclifford/efac5438c1a6c1c9834db4a63940371e to your computer and use it in GitHub Desktop.
Save bradyclifford/efac5438c1a6c1c9834db4a63940371e to your computer and use it in GitHub Desktop.
Session Keep alive on 3rd Party
// 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