Sign out of Azure Active Directory

I am using angular2 and for authentication and I am using azure active directory authentication.

For logout of active azure license authentication I use 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 doesn't work. Everything I've tried. It actually redirects to the login page, but when I login again, it automatically registers itself without any credentials.

When I clear the history manually, it goes to the login on the azure server.

Please help me.

+3


source to share


2 answers


Using this problem, we solve

window.location.href = " https://login.microsoftonline.com/ {0} / oauth2 / logout? post_logout_redirect_uri =" + "{1}"



{0} is a tendent, that is, b8267886-f0c8-4160-ab6f-6e9343468fdc90

{1} - redirect address after logout, ie. http: // localhost: 5477 / # / login

+3


source


The original code snippet just clears the cache data stored in local storage, which does not clear the AAD IDP from the server session. In ng2, please use the following piece of code to exit the AAD form:

import {AdalService} from 'ng2-adal/core';
class whateverComponent{
    public logOut() {
        this.adalService.logOut();
    }
}

      



And we can refer to the source code to see what it will do when we call the function, AuthenticationContext.prototype.logOut

+1


source







All Articles