【问题标题】:How can we block the redirection to the home screen from the Azure ad logout screen?我们如何阻止从 Azure 广告注销屏幕重定向到主屏幕?
【发布时间】:2022-08-02 20:51:34
【问题描述】:

应用程序注销后,后退按钮单击会将用户重定向回应用程序的主屏幕. 我们如何阻止从 Azure 广告注销屏幕重定向到主屏幕?

  • 应用程序:.NET MVC 5
  • 框架:4.6.1

请在下面找到退出功能:

public void SignOut()
        {
            HttpContext.GetOwinContext().Authentication.SignOut(OpenIdConnectAuthenticationDefaults.AuthenticationType, CookieAuthenticationDefaults.AuthenticationType);
          
            if (Request.Cookies[\"MyCookie\"] != null)
            {
                var c = new HttpCookie(\"MyCookie\");
                c.Expires = DateTime.Now.AddDays(-1);
                Response.Cookies.Add(c);
            }
            if (HttpContext.Request.Cookies[\".AspNet.ApplicationCookie\"] != null)
            {
                var c = new HttpCookie(\".AspNet.ApplicationCookie\");
                c.Expires = DateTime.Now.AddDays(-1);
                Response.Cookies.Add(c);
            }

            if (HttpContext.Request.Cookies[\"__RequestVerificationToken\"] != null)
            {
                var c = new HttpCookie(\"__RequestVerificationToken\");
                c.Expires = DateTime.Now.AddDays(-1);
                Response.Cookies.Add(c);
            }
            EndSession();
            Session.Abandon();
            AppSession.Clear();
        }


public void EndSession()
        {
            Request.GetOwinContext().Authentication.SignOut();
            Request.GetOwinContext().Authentication.SignOut(Microsoft.AspNet.Identity.DefaultAuthenticationTypes.ApplicationCookie);
            this.HttpContext.GetOwinContext().Authentication.SignOut(CookieAuthenticationDefaults.AuthenticationType);
        }

    标签: azure azure-active-directory owin openid


    【解决方案1】:

    请尝试在您的 appSettings 中添加 PostLogoutRedirectURI,这样当您发布应用程序时,PostLogoutRedirectURI 和 ReplyURL 必须匹配,才能对用户进行身份验证。并在 azure 广告门户的身份验证页面中添加高级设置部分的注销 URL https://<baseurl>/signout-oidc 字段。

    前任:

    • 在启动时提供 postredirect url。

    启动.cs

     app.UseOpenIdConnectAuthentication(
                    new OpenIdConnectAuthenticationOptions
                    {
                        ClientId = clientId,
                        Authority = authority,
                        PostLogoutRedirectUri = postLogoutRedirectUri,
                        RedirectUri = "https://localhost:44320/Home/About",
                  ...
        }
    

    • 随之尝试明确地让控制器触发SignOut 行动从浏览器中清除会话 cookie, • 最后回调注销 URL,默认显示注销的视图页面

    来自AccountController -AzureAD. GitHub的代码

    [HttpGet("{scheme}")]
            public IActionResult SignOut(
                [FromRoute] string scheme)
            {
                if (AppServicesAuthenticationInformation.IsAppServicesAadAuthenticationEnabled)
                {
                    return LocalRedirect(AppServicesAuthenticationInformation.LogoutUrl);
                }
                else
                {
                    scheme ??= OpenIdConnectDefaults.AuthenticationScheme;
                    var callbackUrl = Url.Page("/Account/SignedOut", pageHandler: null, values: null, protocol: Request.Scheme);
                    return SignOut(
                         new AuthenticationProperties
                         {
                             RedirectUri = callbackUrl,
                         },
                         CookieAuthenticationDefaults.AuthenticationScheme,
                         scheme);
                }
            }
    

    参考:

    Reply URLs vs PostLogoutRedirectURIs in Azure Active Directory (AAD) | by Marilee Turscak | Medium

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-15
      • 1970-01-01
      • 1970-01-01
      • 2011-07-10
      • 2014-03-12
      • 1970-01-01
      相关资源
      最近更新 更多