2017-04-10 149 views
3

我正在使用angular2并进行身份验证,并且正在使用azure Active Directory身份验证。Azure Active Directory注销

对于注销从蔚蓝的Active Directory身份验证我使用下面的代码:

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); 

但它无法正常工作。我所尝试过的一切。它实际上重定向到登录页面,但是当我再次登录时,它会自动登录而没有任何凭据。

当我手动清除历史记录时,它会在azure服务器上登录。

请帮帮我。

回答

3

通过使用此我的问题解决

window.location.href = “https://login.microsoftonline.com/ {0} /的oauth2 /注销?post_logout_redirect_uri =” + “{1}”

{0}是tendentid即b8267886-f0c8-4160-ab6f-6e9343468fdc90

{1}注销即http://localhost:5477/#/login

+0

我知道这是一个老话题。你提出的解决方案可能会起作用,但最简洁的方式就是@Gary Liu - MSFT写道,所以这应该是答案。 – dave0688

1

您的原始代码片段只是清除保存在本地存储器中的缓存数据,这些数据并未清理AAD IDP上的服务器会话。在NG2,请用下面的代码片段注销形式AAD:

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

而且我们可以直接的源代码,看看当我们调用该函数会做,AuthenticationContext.prototype.logOut

+0

如果有帮助,你可以将其标记为答案,可以帮助谁可能面临同样问题的其他社区后重定向的URL。 –