在同一个WebForms应用程序中组合Forms auth和OpenIdConnect auth

时间:2017-10-11 11:46:45

标签: asp.net authentication webforms openid-connect identityserver4

我有一个传统的多租户WebForms应用程序,用户使用表单身份验证进行身份验证。我们正在将身份验证系统迁移到IdentityServer4,但不能一次完成所有操作,因此我们希望逐步将其引入我们的租户。这意味着我们需要同时使用Forms Auth和新的OpenIdConnect Auth运行WebForms应用程序。

我的问题是,每当我运行HttpContext.Current.GetOwinContext().Authentication.Challenge()时,我都会被重定向到Login.aspx,因为:

<authentication mode="Forms">
  <forms name="AuthCookieName" loginUrl="~/Login.aspx" timeout="60" protection="All" requireSSL="true" enableCrossAppRedirects="true" />
</authentication>

我想要的是,只要有人导航到/OIDC.aspx,挑战就会将用户重定向到使用OWIN配置的IdentityServer。对于所有其他请求,现有的Forms身份验证配置可以处理身份验证。

这一切都可能吗?

3 个答案:

答案 0 :(得分:0)

HttpContext.Current.GetOwinContext().Authentication.Challenge()将对默认安全方案进行身份验证质询 - 在这种情况下,您的是Forms Auth。您可以传入一个字符串,表示在挑战中使用哪些安全方案,如HttpContext.Current.GetOwinContext().Authentication.Challenge(OpenIdConnectAuthenticationDefaults.AuthenticationType)

答案 1 :(得分:0)

我设法通过在调用身份验证质询时设置Response.SuppressFormsAuthenticationRedirect标志来防止不必要的重定向,例如:

HttpContext.Current.Response.SuppressFormsAuthenticationRedirect = true;
HttpContext.Current.GetOwinContext().Authentication.Challenge(
    new AuthenticationProperties { RedirectUri = "/Home.aspx" });

答案 2 :(得分:0)

OIDC使用回调网址。此网络表单安全性限制了该URL,并重定向到登录页面。使用位置标记允许访问该回叫网址对我来说很有效。

    <authentication mode="Forms">
      <forms loginUrl="default.aspx" name=".CLFORMSAUTH" />
    </authentication>
    <authorization>
      <deny users="?" />
    </authorization>
  </system.web>
  <location path="authorization-code/callback">
    <system.web>
      <authorization>
        <allow users ="*" />
      </authorization>
    </system.web>
  </location>