title: sharing asp.net 4 forms authentication cookie with asp.net core 2.0
body: <p>We have multiple applications setup in IIS with one application handling the login for all applications. This application is an asp.net 4 site and uses a forms authentication cookie.</p>
  
  <pre><code>&lt;authentication mode="Forms"&gt;
    &lt;forms loginUrl="~/Account/LogOn" protection="All" cookieless="UseCookies" path="/" name="CookieName" /&gt;
  &lt;/authentication&gt;
  </code></pre>
  
  <p>We can successfully use this cookie to login to asp.net 4.5 apps using owin.</p>
  
  <pre><code>app.UseCookieAuthentication(new CookieAuthenticationOptions
          {
              TicketDataFormat = new SharedTicketDataFormat(),
              CookieName = "CookieName",
              AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
              LoginPath = new PathString("/Account/Login"),
              Provider = new CookieAuthenticationProvider
              {
                  OnValidateIdentity =
                      SecurityStampValidator.OnValidateIdentity&lt;ApplicationUserManager, ApplicationUser&gt;(
                          validateInterval: TimeSpan.FromMinutes(30),
                          regenerateIdentity: (manager, user) =&gt; user.GenerateUserIdentityAsync(manager))
              }
          });
  
  
  public class SharedTicketDataFormat : ISecureDataFormat&lt;AuthenticationTicket&gt;
  {
      public string Protect(AuthenticationTicket data)
      {
          return FormsAuthentication.Encrypt(new FormsAuthenticationTicket(data.Identity.Name, false, -1));
      }
      public AuthenticationTicket Unprotect(string protectedText)
      {
          var ticket = FormsAuthentication.Decrypt(protectedText);
          var identity = new FormsIdentity(ticket);
          return new AuthenticationTicket(identity, new AuthenticationProperties());
      }
  }
  </code></pre>
  
  <p>In asp.net core 2.0 I do not know to to wire up the app to use the shared cookie</p>
  
  <p>In Startup.cs
  Configure</p>
  
  <pre><code>app.UseAuthentication();
  </code></pre>
  
  <p>ConfigureServices</p>
  
  <pre><code>services.AddAuthentication(options =&gt;
          {
              options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
              options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
          })
          .AddCookie(options =&gt;
          {
              options.Cookie.Name = "CookieName";
          });
  </code></pre>