OWIN - 使用Cookie身份验证和联合身份验证来保护同一网站

时间:2014-07-23 00:27:42

标签: owin adfs federated-identity katana

我有一个网站,其中用户是需要提供用户名/密码的外部用户或我们网络中的内部用户(AD)。我尝试将OWIN Cookie身份验证(NuGet Microsoft.Owin.Security.Cookies)和OWIN联合身份验证与ADFS(NuGet Microsoft.Owin.Security.WsFederation)混合和匹配。我试过这个:

    public void ConfigureAuth(IAppBuilder app)
    {
        app.SetDefaultSignInAsAuthenticationType(DefaultAuthenticationTypes.ApplicationCookie);

        app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
            LoginPath = new PathString("/Login"),

            Provider = new CookieAuthenticationProvider
            {
                OnApplyRedirect = ctx =>
                {
                    // Apply the redirect if UseADFSFlag is not found in the Query String
                    if (String.IsNullOrWhiteSpace(ctx.Request.Query.Get("UseADFS")))
                    {
                        ctx.Response.Redirect(ctx.RedirectUri);
                    }
                }
            }
        });

        app.UseWsFederationAuthentication(
            new WsFederationAuthenticationOptions
            {
                MetadataAddress = ConfigurationManager.AppSettings["adsfs.MetadataAddress"],
                Wtrealm = ConfigurationManager.AppSettings["adsfs.Wtrealm"],
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie
            });
    }

CookieAuthenticateion首先发生。如果不是QueryString参数" UseADFS"正常重定向到登录页面。否则继续前进。 我希望FederationAuthentication仅在UseADFS参数存在时接管,但是从不发生Login重定向,并且无论参数UseADFS是否存在,联合身份验证始终都会运行。

有没有办法让这项工作?

0 个答案:

没有答案