我有一个小的ASP.NET MVC5项目。 我使用以下代码设置Owin:
public class Startup
{
public void Configuration(IAppBuilder app)
{
DataSerializers.Ticket = new CustomTicketSerializer<CustomClaimsIdentity>();
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
ClientId = "xxx",
ClientSecret = "xxx",
Authority = "xxx",
PostLogoutRedirectUri = "xxx",
RedirectUri = "xxx",
TokenValidationParameters = new TokenValidationParameters
{
SaveSigninToken = true
},
Notifications = new OpenIdConnectAuthenticationNotifications
{
AuthenticationFailed = context =>
{
context.HandleResponse();
context.Response.Redirect("/Error?message=" + context.Exception.Message);
return Task.FromResult(0);
}
}
});
}
}
CustomTicketSerializer
会返回CustomClaimsIdentity
个对象,而不是通常的ClaimsIdentity
CustomClaimsIdentity
扩展ClaimsIdentity
如果我检查User
中的HomeController
属性,那么即使我在调试期间验证了ClaimsIdentity
,类型仍为CustomClaimsIdentity
而不是预期的CookieAuthenticationMiddleware
}返回包含类型AuthenticationTicket
的标识的CustomClaimsIdentity
。
似乎Owin管道改变了一些东西,但我不知道在哪里。
有什么想法吗?