C# ASP.NET身份Cookie能否与表单身份验证向后兼容?

C# ASP.NET身份Cookie能否与表单身份验证向后兼容?,c#,asp.net,cookies,asp.net-identity,forms-authentication,C#,Asp.net,Cookies,Asp.net Identity,Forms Authentication,我有许多现有的ASP.NET MVC web应用程序,它们都使用ASP.NET成员身份和表单身份验证,而不使用OWIN,但我希望在.NET Core 1.1中使用IdentityServer 4 for auth开发新的应用程序。我有一个使用自定义用户存储实现的IdentityServer,因此来自旧ASP.NET成员数据库的现有用户可以登录到我的IdentityServer(有关详细信息,请参阅StackOverflow问题),但是使用表单身份验证的旧应用程序无法识别由ASP.NET Iden

我有许多现有的ASP.NET MVC web应用程序,它们都使用ASP.NET成员身份和表单身份验证,而不使用OWIN,但我希望在.NET Core 1.1中使用IdentityServer 4 for auth开发新的应用程序。我有一个使用自定义用户存储实现的IdentityServer,因此来自旧ASP.NET成员数据库的现有用户可以登录到我的IdentityServer(有关详细信息,请参阅StackOverflow问题),但是使用表单身份验证的旧应用程序无法识别由ASP.NET Identity创建的身份验证cookie

我希望使用ASP.NET身份在旧的窗体身份验证应用程序和新的应用程序之间进行单点登录,最好对旧的应用程序进行尽可能少的更改。有没有一种方法可以使ASP.NET Identity生成身份验证cookie,使表单身份验证能够理解

我认为在这两种情况下,cookie的内容都是序列化和加密的
ClaimsPrincipal
,因此我的大绊脚石似乎是让Forms Authentication应用程序和ASP.NET Identity应用程序在加密/解密cookie时位于同一页面上。由于Forms Authentication使用web.config文件中的
元素对cookie进行加密,而.NET Core中的ASP.NET Identity使用DPAPI,因此我必须找出如何弥合这一差距。也许是这样的

Startup.cs

public void ConfigureServices(IServiceCollection services)
{
    ...

    services.Configure<IdentityOptions>(options =>
    {
        ...

        options.Cookies.ApplicationCookie.DataProtectionProvider = 
            new FormsAuthenticationDataProtector();

        ...
    });
}
public class FormsAuthenticationDataProtector : IDataProtector
{
    public IDataProtector CreateProtector(string purpose)
    {
        return this;
    }

    public byte[] Protect(byte[] plaintext)
    {
        // TODO: Mimic the Forms Authentication encryption algorithm.
    }

    public byte[] Unprotect(byte[] protectedData)
    {
        // TODO: Mimic the Forms Authentication decryption algorithm.
    }
}
但是我不知道
Protect()
Unprotect()
方法的主体应该是什么。

我在GitHub上使用了两个ASP.NET Identity and Identity Server dev,它们确实很有帮助。对于我提出的在表单身份验证和ASP.NET身份验证之间共享cookie的问题,简短的回答是“你疯了!”幸运的是,有最少的替代方案

布罗克·艾伦指给我看。对我来说,我认为这将起到关键作用。在没有OWIN或ASP.NET标识的旧MVC应用程序中实现OpenID Connect其实并不难