2017-04-10 148 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。 –