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<TicketDataFormat>();
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.
source to share
You have to do oposite. With Autofac, you register a type as a Service.
builder.RegisterType<TicketDataFormat>()
.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>();
source to share