I am using angular2 and for authentication and I am using azure active directory authentication.
For Logout from azure active directory authentication I am using below code:
localStorage.removeItem('user');
localStorage.removeItem('useremail');
window.localStorage.removeItem("id_token");
window.localStorage.removeItem("access_token");
window.localStorage.clear();
let link = ['/login'];
this._router.navigate(link);
But it is not working. Everything I have tried. It actually redirect to login page but when again I do login it automatically login without any credential.
When I clear history manually it goes to login in azure server.
Please help me.
By using this my problem is solved
window.location.href = "https://login.microsoftonline.com/{0}/oauth2/logout?post_logout_redirect_uri=" + "{1}"
{0} is tendentid i.e. b8267886-f0c8-4160-ab6f-6e9343468fdc90
{1} is redirect url after logout i.e. http://localhost:5477/#/login
Your original code snippet just clear your cache data saved in local storage, which didn't clean the server session on AAD IDP. In ng2, please use following code snippet to logout form AAD:
import {AdalService} from 'ng2-adal/core';
class whateverComponent{
public logOut() {
this.adalService.logOut();
}
}
And we can direct to the source code to see what it will do when we call the function, AuthenticationContext.prototype.logOut
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With