Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Active directory Logout

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.

like image 724
pushp Avatar asked Mar 10 '23 09:03

pushp


2 Answers

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

like image 73
pushp Avatar answered Mar 11 '23 22:03

pushp


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

like image 24
Gary Liu Avatar answered Mar 11 '23 21:03

Gary Liu