【问题标题】:MVC 5 using Azure AD cannot logout使用 Azure AD 的 MVC 5 无法注销
【发布时间】:2019-03-01 01:50:09
【问题描述】:

我正在使用 MVC5,使用 OpenIdConnect 对 Azure AD 进行身份验证。

我的应用程序在 4 个不同的 Azure AD 应用程序注册下运行; localhost、DEV 版本、UAT 版本和生产版本。

UAT 和生产在 Azure 上同一 Web 服务的不同部署槽下运行。

除了 Azure 中的 UAT 部署槽中的注销功能外,一切都运行良好。当我单击“注销”时,它会将我带到 Microsoft 注销“您已退出您的帐户”。在我导航回 URL 后,它会让我重新登录(我也单击了“不要让我保持登录状态”)。

关于为什么这可能发生在单一环境中的任何想法?除了 URL 和唯一标识符之外,Azure AD 应用注册清单几乎相同。

我正在使用“UseKentorOwinCookieSaver”包。

退出方式:

    public void SignOut()
    {
        HttpContext.GetOwinContext().Authentication.SignOut(
            OpenIdConnectAuthenticationDefaults.AuthenticationType, CookieAuthenticationDefaults.AuthenticationType
            );
    }

Startup.cs:

    public void ConfigureAuth(IAppBuilder app)
    {            app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

        app.UseKentorOwinCookieSaver();

        app.UseCookieAuthentication(new CookieAuthenticationOptions());

        app.UseOpenIdConnectAuthentication(
            new OpenIdConnectAuthenticationOptions
            {
                ClientId = clientId,
                Authority = authority,
                PostLogoutRedirectUri = postLogoutRedirectUri,
                Notifications = new OpenIdConnectAuthenticationNotifications
                {
                    AuthenticationFailed = context =>
                    {
                        context.HandleResponse();
                        context.Response.Redirect("/Error/message=" + context.Exception.Message);
                        return Task.FromResult(0);
                    },
                    SecurityTokenValidated = context =>
                    {
                        OnAuth();
                        return Task.FromResult(0);
                    }
                },                     
                AuthenticationMode = AuthenticationMode.Passive
            }
        );

        app.Use((context, next) =>
        {
            // The function to call...
            OnAuth();
            return next.Invoke();
        });

    }

【问题讨论】:

    标签: asp.net-mvc azure authentication azure-active-directory


    【解决方案1】:

    您的用户凭据可能已被缓存。这是 Chrome 和 IE 的默认行为,其中一些也是 Microsoft 设计的。您的目标是单点注销需要在每个应用程序上进行自定义编码。尝试以隐身模式从其他浏览器登录,看看您是否仍然遇到此问题。

    此线程为您的情况提供了一些解决方法。 https://social.msdn.microsoft.com/Forums/azure/en-US/97199b97-a3f1-42ab-b5dc-103d3bc3cb53/azure-ad-single-sign-on-auto-sign-in-with-windows-credentials?forum=WindowsAzureAD

    【讨论】:

    • 感谢您的回答,但这不是问题所在。无论浏览器,甚至不同的计算机,我都有同样的问题。问题是第 3 方在我自己的网络之外进行测试的问题。
    猜你喜欢
    • 1970-01-01
    • 2021-09-18
    • 2015-05-31
    • 2014-08-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-27
    • 1970-01-01
    • 2017-06-24
    相关资源
    最近更新 更多