【问题标题】:Azure Active directory LogoutAzure 活动目录注销
【发布时间】:2017-04-11 15:37:01
【问题描述】:

我正在使用 angular2 和身份验证,我正在使用 azure 活动目录身份验证。

对于从 Azure 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 服务器。

请帮助我。

【问题讨论】:

    标签: angular azure-active-directory


    【解决方案1】:

    用这个解决了我的问题

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

    {0} 是有倾向性的,即 b8267886-f0c8-4160-ab6f-6e9343468fdc90

    {1} 是注销后的重定向网址,即http://localhost:5477/#/login

    【讨论】:

    • 我知道这是个老话题了。您提出的解决方案可能有效,但最干净的方法是@Gary Liu - MSFT 写的,所以这应该是答案。
    【解决方案2】:

    您的原始代码 sn-p 只是清除了保存在本地存储中的缓存数据,这并没有清除 AAD IDP 上的服务器会话。在ng2中,请使用以下代码sn-p退出AAD:

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

    而且我们可以直接看源代码,看看我们调用函数时会做什么,AuthenticationContext.prototype.logOut

    【讨论】:

    • 如果有帮助,您可以将其标记为答案,这可能对可能面临相同问题的其他社区有所帮助。
    猜你喜欢
    • 2018-02-24
    • 2015-01-23
    • 1970-01-01
    • 2019-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-28
    相关资源
    最近更新 更多