Skip to content

Commit

Permalink
feat: add msal 'logoutRedirect' upon JWT expiration for AzureAD (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
rentallect authored Jul 10, 2023
1 parent 86928c6 commit c60a2d4
Showing 1 changed file with 52 additions and 21 deletions.
73 changes: 52 additions & 21 deletions src/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -817,33 +817,14 @@ class ZitiBrowzerRuntime {
// purge the cookie
document.cookie = window.zitiBrowzerRuntime.authTokenName+'=; Max-Age=-99999999;';

// Run the following on a delay so the toast can be read by user, and so that we do not block the SW messaging
setTimeout(function() {

// do the OIDC logout
window.zitiBrowzerRuntime.authClient.logout({
logoutParams: {
returnTo: window.location.origin
}
});

}, 3000);

setTimeout(function() {

zitiBrowzerRuntime.logger.debug(`doIdpLogout: ################ doing root-page page reload now ################`);
window.location.replace('https://' + zitiBrowzerRuntime.zitiConfig.httpAgent.self.host + zitiBrowzerRuntime.zitiConfig.httpAgent.target.path);

}, 5000);
window.zitiBrowzerRuntime.authClient_doLogout();

}

idpAuthHealthEventHandler(idpAuthHealthEvent) {

this.logger.trace(`idpAuthHealthEventHandler() `, idpAuthHealthEvent);

return;//TEMPORARY bypass until Controller fix is released

if (idpAuthHealthEvent.expired) {

// Only initiate reboot once
Expand Down Expand Up @@ -938,6 +919,7 @@ class ZitiBrowzerRuntime {
clientId: `${this.zitiConfig.idp.clientId}`,
authority: `${this.zitiConfig.idp.host}`,
redirectUri: `${window.location.origin}`,
postLogoutRedirectUri: `${window.location.origin}`,
},
cache: {
cacheLocation: "sessionStorage",
Expand Down Expand Up @@ -1080,7 +1062,7 @@ class ZitiBrowzerRuntime {
/**
* AzureAD
*/
else if ( isEqual(this.idp, ZBR_CONSTANTS.AZURE_AD_IDP) ) {
else if ( isEqual(window.zitiBrowzerRuntime.idp, ZBR_CONSTANTS.AZURE_AD_IDP) ) {

return await this.authClient_isAuthenticated_AzureAD();

Expand All @@ -1089,6 +1071,55 @@ class ZitiBrowzerRuntime {
return window.zitiBrowzerRuntime.isAuthenticated;
}

/**
* Force logout from the IdP auth client.
* This will clear local cache of tokens then redirect to the IdP signout page.
*/
authClient_doLogout() {

/**
* Auth0
*/
if ( isEqual(window.zitiBrowzerRuntime.idp, ZBR_CONSTANTS.AUTH0_IDP) ) {

// Run the following on a delay so the toast can be read by user, and so that we do not block the SW messaging
setTimeout(function() {

// do the OIDC logout
window.zitiBrowzerRuntime.authClient.logout({
logoutParams: {
returnTo: window.location.origin
}
});

}, 3000);

}
/**
* AzureAD
*/
else if ( isEqual(window.zitiBrowzerRuntime.idp, ZBR_CONSTANTS.AZURE_AD_IDP) ) {

// Run the following on a delay so the toast can be read by user, and so that we do not block the SW messaging
setTimeout(function() {

window.zitiBrowzerRuntime.authClient.logoutRedirect({});

}, 3000);

}

setTimeout(function() {

zitiBrowzerRuntime.logger.debug(`doIdpLogout: ################ doing root-page page reload now ################`);
window.location.replace('https://' + zitiBrowzerRuntime.zitiConfig.httpAgent.self.host + zitiBrowzerRuntime.zitiConfig.httpAgent.target.path);

}, 5000);

return;
}


async await_azure_ad_accountId() {
return new Promise((resolve, _reject) => {
(async function waitFor_azure_ad_accountId() {
Expand Down

0 comments on commit c60a2d4

Please sign in to comment.