【问题标题】:Form Authentication vs OWIN UseCookieAuthentication and subdomain SSO表单身份验证与 OWIN UseCookieAuthentication 和子域 SSO
【发布时间】:2016-09-20 15:51:03
【问题描述】:

“传统”的表单认证和owin中间件(带有UseCookieAuthentication)是完全可以互换的吗?

我想创建一个简单的子域 sso(就像许多示例所建议的那样) Sharing authentication between parent and child web applications

我的父应用程序是一个旧的 asp.net webform 应用程序,在 web.config 中配置了表单身份验证

<system.web>
    <authentication mode="Forms">
      <forms loginUrl="~/Account/Login" timeout="2880" name=".ASPXAUTH" protection="Validation" domain="localhost" />
   </authentication>
   <machineKey validationKey="E0230924313583BE9D071B5826165A7C6198A1697AE2F549535F0744FFDC414638882DDC507C7B097EAD5B4FB67819D9520D0A9D05B2D38EAB4AF0B36DAAA39F" decryptionKey="D29E22658319B16CAE17C9CD0269AB15DEAF9068FB6D459C" validation="SHA1" decryption="AES"></machineKey>
</system.web>

和一个子应用程序(在子域中)是一个 asp.net Mvc5(带有 owin UseCookieAuthentication),因此安全性在 Startup.cs 而不是在 web.config 中配置

app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                CookieName = ".ASPXAUTH",
                CookieDomain "localhost"
                Provider = new CookieAuthenticationProvider { OnApplyRedirect = ApplyRedirect }
            });

private static void ApplyRedirect(CookieApplyRedirectContext context)
        {
            Uri absoluteUri;
            if (Uri.TryCreate(context.RedirectUri, UriKind.Absolute, out absoluteUri))
            {
                var path = PathString.FromUriComponent(absoluteUri);
                if (path == context.OwinContext.Request.PathBase + context.Options.LoginPath)
                    context.RedirectUri = "http://localhost/subSiteAuthenticationTest/Account/Login" +
                        new QueryString(
                            context.Options.ReturnUrlParameter,
                            context.Request.Uri.AbsoluteUri);
            }

            context.Response.Redirect(context.RedirectUri);
        }

在子应用程序 web.config 中,我只为父应用程序配置了相同的机器密钥

<system.web>
    <authentication mode="None">
    <machineKey validationKey="E0230924313583BE9D071B5826165A7C6198A1697AE2F549535F0744FFDC414638882DDC507C7B097EAD5B4FB67819D9520D0A9D05B2D38EAB4AF0B36DAAA39F" decryptionKey="D29E22658319B16CAE17C9CD0269AB15DEAF9068FB6D459C" validation="SHA1" decryption="AES"></machineKey>
</system.web>

父级的登录页面用于两个应用程序(为了在 chil 应用程序中使用登录页面的绝对路径,我实现了“OnApplyRedirect”,正如这篇文章所说:Login page on different domain

但这不起作用,我错过了什么吗?

【问题讨论】:

    标签: asp.net cookies single-sign-on owin form-authentication


    【解决方案1】:

    “传统”的表单认证和owin中间件(带有UseCookieAuthentication)是完全可以互换的吗?

    很遗憾,不,它们不可互换。

    但是,您可以在 CookieAuthenticationOptions 中提供自定义 TicketDataFormat。

    这是一个例子。

    SSO for ASP.NET MVC4 and MVC5 web apps shared the same domain

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-19
      相关资源
      最近更新 更多