asp.net-identityasp.net-identity-2unity-interception

ASP.NET Identity 2 - injecting ISecureDataFormat<>


I'm having same issue described here with no answer, just using Unity.

I'm trying to register ISecureDataFormat<> in the lastest VS2013 (update 2) SPA/Web Api template.

I've tried

container.RegisterType(typeof(ISecureDataFormat<>), typeof(SecureDataFormat<>));
container.RegisterType<ISecureDataFormat<AuthenticationTicket>, SecureDataFormat<AuthenticationTicket>>();
container.RegisterType<ISecureDataFormat<AuthenticationTicket>, TicketDataFormat>();

It "works" but not really because then it complains about the next depenedency in that tree, IDataSerializer... and then the next IDataProtector, for which I found no implementation.


Solution

  • I solved the following error in SimpleInjector with the following mappings

    container.Register<IDataSerializer<AuthenticationTicket>, TicketSerializer>();
    container.Register<IDataProtector>(() => new DpapiDataProtectionProvider().Create("ASP.NET Identity"));
    

    To figure out what serializer was used I noticed that the ISecureDataFormat generic parameter in the AccountsController was a AuthenticationTicket type. In checking the IDataSerializer namespace the TicketSerializer implements IDataSerializer.

    To figure out IDataProtector I again looked in the IDataProtector namespace and found the implementation of the IDataProtectionProvider.