UserCookieAuthentication in Mono 3.4.1

When I add the line below to my launch class, I get an exception below. This is exo self-service powered by mono (Ubuntu). It works great in windows. I narrowed it down to a call to UseCookieAuthentication. I can create instances without any problems. Any idea what is going on here? I have aspnet Identity working and EF6 / MySql.

app.UseCookieAuthentication(new CookieAuthenticationOptions()); 

Unhandled exception: System.Reflection.TargetInvocationException: The exception was thrown by the target of the call. ---> System.TypeLoadException: Failed to load type "Microsoft.Owin.Security.DataProtection.DpapiDataProtector" from the assembly "Microsoft.Owin.Security, Version = 2.1.0.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35". at Microsoft.Owin.Security.DataProtection.AppBuilderExtensions.CreateDataProtector (Owin.IAppBuilder, line []) <0x00052> at Microsoft.Owin.Security.Cookies.CookieAuthenticationMiddleware..ctor (Microsoft.Owin.OwinMiddleware, Owin.IABB. Owin.Security.Cookies.CookieAuthenticationOptions) <0x00223> at (dynamic wrapper method) object.lambda_method (System.Runtime.CompilerServices.Closure, Microsoft.Owin.OwinMiddleware, Owin.IAppBuilder, Microsoft.Owin.Security.Cuthent.Oook <0x00048> at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke (System.Reflection.MonoMethod, object, object [], System.Exception &) <0x00067> in System.Reflection.MonoMethod.Invoke (object , System.Reflection.BindingFlags, System.Reflection.Binder, object [], System.Globalization.CultureInfo) <0x000d7>

--- The end of the internal check of the exception stack --- in System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object [] parameters, System.Globalization.CultureInfo culture) [ 0x00000] at: 0 in System.Reflection.MethodBase.Invoke (parameters of System.Object obj, System.Object []) [0x00000] at: 0 in System.Delegate.DynamicInvokeImpl (System.Object [] args) [0x00000] in : 0 at System.MulticastDelegate.DynamicInvokeImpl (System.Object [] args) [0x00000] at: 0 at System.Delegate.DynamicInvoke (System.Object [] args) [0x00000] at: 0 at Microsoft.Owin.Builder.AppBuilder .BuildInternal (signature System.Type) [0x00000] at: 0 at Microsoft.Owin.Builder.AppBuilder.Build (System.Type returnType) [0x00000] at: 0 at Microsoft.Owin.Hosting.ServerFactory.ServerFactoryAdapter.Create (creator IAppBuilder) [0x00000] at: 0 at Microsoft.Owin.Hosting.Engine.HostingEngine.StartServer (Microsoft.O win.Hosting.Engine.StartContext context) [0x00000] at: 0 in Microsoft.Owin.Hosting.Engine.HostingEngine.Start (Microsoft.Owin.Hosting.Engine.StartContext context) [0x00000] at: 0 in Microsoft.Owin. Hosting.Starter.DirectHostingStarter.Start (Microsoft.Owin.Hosting.StartOptions options) [0x00000] at: 0 in Microsoft.Owin.Hosting.Starter.HostingStarter.Start (Microsoft.Owin.Hosting.StartOptions options) [0x00000] in: 0 at Microsoft.Owin.Hosting.WebApp.StartImplementation (IServiceProvider services, Microsoft.Owin.Hosting.StartOptions options) [0x00000] at: 0 at Microsoft.Owin.Hosting.WebApp.Start (Microsoft.Owin.Hosting.StartOptions options) [0x00000] at: 0 at Microsoft.Owin.Hosting.WebApp.Start [Startup] (options Microsoft.Owin.Hosting.StartOptions) [0x00000] at: 0 at Microsoft.Owin.Hosting.WebApp.Start [Startup] (URL Address System.String) [0x00000] at: 0 in HelloWorldNancy.Program.Main (System.String [] args) [0x00000] at: 0 [ERROR] FATAL UNHANDLED EXCEPT ION: System.Reflection.TargetInvocationException: The exception was thrown by the target of the call. ---> System.TypeLoadException: Failed to load type "Microsoft.Owin.Security.DataProtection.DpapiDataProtector" from the assembly "Microsoft.Owin.Security, Version = 2.1.0.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35". at Microsoft.Owin.Security.DataProtection.AppBuilderExtensions.CreateDataProtector (Owin.IAppBuilder, line []) <0x00052> at Microsoft.Owin.Security.Cookies.CookieAuthenticationMiddleware..ctor (Microsoft.Owin.OwinMiddleware, Owin.IABB. Owin.Security.Cookies.CookieAuthenticationOptions) <0x00223> at (dynamic wrapper method) object.lambda_method (System.Runtime.CompilerServices.Closure, Microsoft.Owin.OwinMiddleware, Owin.IAppBuilder, Microsoft.Owin.Security.Cuthent.Oook <0x00048> at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke (System.Reflection.MonoMethod, object, object [], System.Exception &) <0x00067> in System.Reflection.MonoMethod.Invoke (object , System.Reflection.BindingFlags, System.Reflection.Binder, object [], System.Globalization.CultureInfo) <0x000d7>

--- The end of the internal check of the exception stack --- in System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object [] parameters, System.Globalization.CultureInfo culture) [ 0x00000] at: 0 in System.Reflection.MethodBase.Invoke (parameters of System.Object obj, System.Object []) [0x00000] at: 0 in System.Delegate.DynamicInvokeImpl (System.Object [] args) [0x00000] in : 0 at System.MulticastDelegate.DynamicInvokeImpl (System.Object [] args) [0x00000] at: 0 at System.Delegate.DynamicInvoke (System.Object [] args) [0x00000] at: 0 at Microsoft.Owin.Builder.AppBuilder .BuildInternal (signature System.Type) [0x00000] at: 0 at Microsoft.Owin.Builder.AppBuilder.Build (System.Type returnType) [0x00000] at: 0 at Microsoft.Owin.Hosting.ServerFactory.ServerFactoryAdapter.Create (creator IAppBuilder) [0x00000] at: 0 at Microsoft.Owin.Hosting.Engine.HostingEngine.StartServer (Microsoft.O win.Hosting.Engine.StartContext context) [0x00000] at: 0 in Microsoft.Owin.Hosting.Engine.HostingEngine.Start (Microsoft.Owin.Hosting.Engine.StartContext context) [0x00000] at: 0 in Microsoft.Owin. Hosting.Starter.DirectHostingStarter.Start (Microsoft.Owin.Hosting.StartOptions options) [0x00000] at: 0 in Microsoft.Owin.Hosting.Starter.HostingStarter.Start (Microsoft.Owin.Hosting.StartOptions options) [0x00000] in: 0 at Microsoft.Owin.Hosting.WebApp.StartImplementation (IServiceProvider services, Microsoft.Owin.Hosting.StartOptions options) [0x00000] at: 0 at Microsoft.Owin.Hosting.WebApp.Start (Microsoft.Owin.Hosting.StartOptions options) [0x00000] at: 0 at Microsoft.Owin.Hosting.WebApp.Start [Startup] (options Microsoft.Owin.Hosting.StartOptions) [0x00000] at: 0 at Microsoft.Owin.Hosting.WebApp.Start [Startup] (URL System.String) [0x00000] at: 0 at HelloWorldNancy.Program.Main (System.String [] args) [0x00000] at: 0

+8
mono asp.net-identity owin
source share
1 answer

Well, this is because OWIN uses the DpapiDataProtector by default, and DPAPI uses the Window API (Data Protection API) and does not work in mono. Fortunately, you can override the default value in your cookie settings. The following is an example where AesDataProtectorProvider is the custom IDataProtector I found here: Using Oauth tickets through multiple services?

  app.UseCookieAuthentication(new CookieAuthenticationOptions { TicketDataFormat = new SecureDataFormat<AuthenticationTicket>(DataSerializers.Ticket, new AesDataProtectorProvider("testing"), TextEncodings.Base64) }); 

With this code, my project starts up again in Mono.

UPDATE:

You can also have a custom IDataProtectionProvider and all using owin with this:

 app.SetDataProtectionProvider(new CustomIDataProtectionProvider()); 
+14
source share

All Articles