Implementing ISecureDataFormat in Web API 2 AccountController using Autofac

I use ASP.NET Identity 2.2 in the Web API 2 project, but I'm not sure how to connect the dependence ISecureDataFormat<AuthenticationTicket>

on AccountController

using Autofac.

I've tried this:

builder.RegisterType<ISecureDataFormat<AuthenticationTicket>>()
       .As<TicketDataFo‌​rmat>(); 

      

and get the error:

The type "Microsoft.Owin.Security.ISecureDataFormat`1 [Microsoft.Owin.Security.Authenticat ionTicket]" is not assigned to the service "Microsoft.Owin.Security.DataHandler.TicketDataFormat"

None of the questions I've come across seem to work using the latest stable version of ASP.NET Identity.

Any help is greatly appreciated.

0


source to share


1 answer


You have to do oposite. With Autofac, you register a type as a Service.

builder.RegisterType<TicketDataFo‌​rmat>()
       .As<ISecureDataFormat<AuthenticationTicket>>(); 

      



and based on this answer , you also need to register the implementation IDataSerializer<AuthenticationTicket>

and IDataProtector

.

builder.RegisterType<TicketSerializer>()
       .As<IDataSerializer<AuthenticationTicket>>();
builder.Register(c => new DpapiDataProtectionProvider().Create("ASP.NET Identity"))
       .As<IDataProtector>(); 

      

+5


source







All Articles