Skip to content

undefinedfunction/FormsAuthentication

 
 

Repository files navigation

FormsAuthentication

Enable ASP.NET Core 2 cookies to read old ASP.NET Forms Authentication cookies by implementing a custom ISecureDataFormat.

NuGet: NuGet Shield

Usage:

var section = Configuration.GetSection("FormsAuthentication");

var faOptions = new FormsAuthenticationOptions()
{
    DecryptionKey = section.GetValue<string>("DecryptionKey"),
    ValidationKey = section.GetValue<string>("ValidationKey"),
    EncryptionMethod = section.GetValue<EncryptionMethod>("EncryptionMethod"),
    ValidationMethod = section.GetValue<ValidationMethod>("ValidationMethod"),
};

services
    .AddAuthentication(options =>
    {
        options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
        options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
        options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
    })
    .AddCookie(options =>
    {
        options.Cookie.Name = section.GetValue<string>("CookieName");
        options.AccessDeniedPath = "/Login/Upgrade/";
        options.LoginPath = "/Login/";
        options.ReturnUrlParameter = "returnurl";
        options.TicketDataFormat = new FormsAuthenticationDataFormat<AuthenticationTicket>(
            faOptions,
            FormsAuthHelper.ConvertCookieToTicket,
            FormsAuthHelper.ConvertTicketToCookie
            );
    });

The FormsAuthHelper.ConvertCookieToTicket and FormsAuthHelper.ConvertTicketToCookie helper methods convert an ASP.NET Core AuthenticationTicket to a FormsAuthenticationCookie and vise versa. This class contains the same data as a old ASPNET Cookie.

About

Enable ASP.NET Core 2 cookies to read old ASP.NET Forms Authentication cookies

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%