OWIN通过ADFS使用Forms身份验证和WSFederated身份验证

时间:2016-12-01 11:10:30

标签: asp.net-mvc-4 owin forms-authentication adfs katana

我正在尝试实施此解决方案,其中内部组织用户将通过登录表单(但使用Windows凭据)登录,该帖子发布到ADFS并获取声明。还允许外部用户(在后端创建并插入到sql server数据库中),其信息包含与ADFS相同的声明。类似下面的多种登录提供程序系统,当我在左边输入用户名和密码时,它会针对SQL Server进行验证,但点击窗口会重定向到登录到adfs。  Multiple Login

现在我得到了如下代码,但默认情况下它会尝试重定向到adfs网址,而不是显示登录屏幕。

[assembly: OwinStartup(typeof(App_Start.Startup))]
namespace App_Start
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {

            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                //interactive logon process
                AuthenticationMode = Microsoft.Owin.Security.AuthenticationMode.Active,
                //name of the authentication type
                AuthenticationType = CookieAuthenticationDefaults.AuthenticationType,
                //Login path should be below
                LoginPath = new PathString("/Home/Login"),
                //TODO: Enable this to always send and receive cookies in SSL when in production
                CookieSecure = CookieSecureOption.Always,
                //enable sliding expiration
                SlidingExpiration = true,
                //Cookie expires in 4 hours
                ExpireTimeSpan = TimeSpan.FromTicks(DateTime.Now.AddHours(4).Ticks)
            });


            app.UseWsFederationAuthentication(new WsFederationAuthenticationOptions
             {
                 MetadataAddress = ConfigurationManager.AppSettings["federationUri"],
                 Wtrealm = ConfigurationManager.AppSettings["realm"]
             });

            //This will set ADFS as the default authentication provider 
            app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
        }
    }
}

0 个答案:

没有答案