我有一个工作正常的IdentityServer2身份验证服务器。我正在创建一个新的.NETMVC应用程序,并遵循这篇文章(http://www.cloudidentity.com/blog/2014/02/20/ws-federation-in-microsoft-owin-componentsa-quick-start/)以建立具有IDS2的MS OWIN。我可以到达登录屏幕,但登录后,用户会被送回呼叫网站,并陷入无休止的循环中。
Startup.Auth.cs
using Microsoft.Owin.Security;
using Microsoft.Owin.Security.Cookies;
using Microsoft.Owin.Security.WsFederation;
using Owin;
namespace AZBarMail
{
public partial class Startup
{
public void ConfigureAuth(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(
new CookieAuthenticationOptions
{
AuthenticationType =
WsFederationAuthenticationDefaults.AuthenticationType
});
app.UseWsFederationAuthentication(
new WsFederationAuthenticationOptions
{
MetadataAddress = "https://auth.azbar.org/federationmetadata/2007-06/federationmetadata.xml",
Wtrealm = "https://localhost:44310/",
});
}
}
}
web.config 的部分
<system.web>
<authentication mode="None" />
<compilation debug="true" targetFramework="4.6.1" />
<httpRuntime targetFramework="4.6.1" />
</system.web>
启动.cs
using Microsoft.Owin;
using Owin;
[assembly: OwinStartup(typeof(AZBarMail.Startup))]
namespace AZBarMail
{
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
ConfigureAuth(app);
}
}
}
重定向IDS2 中的URL
https://localhost:44310/
将用户重定向到/account/login。
app.UseCookieAuthentication(new CookieAuthenticationOptions()
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/account/Login"),
CookieName = CookieAuthenticationDefaults.CookiePrefix + "SampleClient",
ReturnUrlParameter = CookieAuthenticationDefaults.ReturnUrlParameter,
LogoutPath = new PathString("/account/Logout")
});
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
从/account/login,重定向到外部提供程序。
外部提供者将在其域上创建一个cookie,您将在收到外部提供者的响应后在域上创建cookie。
问题最终解决。cookie类型/设置似乎有问题。