Owin身份验证管道中的自定义ClaimsIdentity

时间:2018-03-25 09:04:11

标签: c# authentication owin wif

我有一个小的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管道改变了一些东西,但我不知道在哪里。 有什么想法吗?

0 个答案:

没有答案