title: Implementing a custom FormsAuthenticationProvider using Owin, Katana, and Nancy
body: <p>I am working on implementing a custom <code>FormsAuthenticationProvider</code> and I'm getting a middleware conversion error.</p>
  
  <pre><code>No conversion available between System.Func`2[System.Collections.Generic.IDictionary`2
  [System.String,System.Object],System.Threading.Tasks.Task] and Microsoft.Owin.OwinMiddleware
  Parameter name: signature
  </code></pre>
  
  <p>My stack includes </p>
  
  <ul>
  <li>Owin</li>
  <li>Katana</li>
  <li>Nancy</li>
  </ul>
  
  <p><em>My specific question would be any advice on where to look for an example on how to implement a custom <code>FormsAuthenticationProvider</code>? Unless someone can spot my problem.</em></p>
  
  <p>My implementation looks like:</p>
  
  <p><strong>Startup.cs</strong></p>
  
  <pre><code>app.UseFormsAuthentication(new FormsAuthenticationOptions
              {
                  LoginPath = "/login",
                  LogoutPath = "/logout",
                  CookieHttpOnly = true,
                  AuthenticationType = Constants.ChainLinkAuthType,
                  CookieName = "chainlink.id",
                  ExpireTimeSpan = TimeSpan.FromDays(30),
                  Provider = kernel.Get&lt;IFormsAuthenticationProvider&gt;()
              });
  </code></pre>
  
  <p>If I remove the <code>app.UseFormsAuthentication(...)</code> the application runs without error.</p>
  
  <p><strong>Full Stack Trace</strong></p>
  
  <pre><code>[ArgumentException: No conversion available between System.Func`2[System.Collections.Generic.IDictionary`2[System.String,System.Object],System.Threading.Tasks.Task] and Microsoft.Owin.OwinMiddleware
  Parameter name: signature]
     Owin.Builder.AppBuilder.Convert(Type signature, Object app) +328
     Owin.Builder.AppBuilder.BuildInternal(Type signature) +336
     Owin.Builder.AppBuilder.Build(Type returnType) +42
     Microsoft.Owin.Host.SystemWeb.OwinAppContext.Initialize(Action`1 startup) +650
     Microsoft.Owin.Host.SystemWeb.OwinBuilder.Build(Action`1 startup) +86
     Microsoft.Owin.Host.SystemWeb.OwinBuilder.Build() +185
     System.Lazy`1.CreateValue() +416
     System.Lazy`1.LazyInitValue() +152
     System.Lazy`1.get_Value() +75
     Microsoft.Owin.Host.SystemWeb.OwinApplication.get_Instance() +35
     Microsoft.Owin.Host.SystemWeb.OwinHttpModule.Init(HttpApplication context) +106
     System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +418
     System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
     System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +336
     System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296
  
  [HttpException (0x80004005): No conversion available between     System.Func`2[System.Collections.Generic.IDictionary`2[System.String,System.Object],System.Threading.Tasks.Task] and Microsoft.Owin.OwinMiddleware
  Parameter name: signature]
     System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9874568
     System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
     System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr,  HttpContext context) +254
  </code></pre>
  
  <p><strong>Executable Source Code</strong> (Just F5 it and you'll get the error immediately)</p>
  
  <p><a href="https://github.com/cnwilkin/ChainLink/tree/spike" rel="nofollow">https://github.com/cnwilkin/ChainLink/tree/spike</a></p>