Hi All,
Am using Angular 10 along with Web API. We are using SAML authentication process and so we are just feeding the credentials to SAML while logging in and the rest is being taken care by SAML. It means that the session is also being created by SAML.
While logging out, we are calling a url being provided by SAML to end the session:
this.document.location.href = String.Format(environment.EndSessionUrl,this.idToken,this.globalVariables.LogoutUrl);
EndSessionUrl : "https://sam.samexternal.net:443/sso/oauth2/connect/endSession?&id_token_hint={0}&post_logout_redirect_uri={1}
Now, while closing the browser, I cannot be able to clear localStorage and end the session.
What I have tried:
I have to perform three things on browser close:
1) set "false" in database column
2) clear localStorage
3) end the session
Here is what I did:
@HostListener('window:beforeunload')
onBeforeUnload(): void {
debugger;
if (localStorage.getItem("LoggedInUserSubId")!=null) {
fetch('http://localhost:60606/api/Auth/updateUserLogInStatus?userSubId=' + localStorage.getItem("LoggedInUserSubId") + '&logInStatus=false', {
keepalive: true,
method: 'POST',
headers: {
'Content-Type': 'application/json; charset=utf-8',
},
})
.then(response => {
localStorage.removeItem("LoggedInUserSubId");
this.document.location.href = String.Format(environment.EndSessionUrl,this.idToken,this.globalVariables.LogoutUrl);
});
}
}
With this code, I can be able to set "false" in database column.
But, the localStorage still remains and session still remains active and when user try to login again, it doesn't ask for login credentials anymore as the session is active.
Please help with some ideas that might work in this scenario.
-- Thanks