How should I Register a custom UserAccount with MembershipReboot.Owin?

664 Views Asked by At

Has any one made a multitenant example with a custom useraccount using membershipreboot.owin ?

I Have a hard time figuring out how I should configure the membership middleware when using a custom account. Its not covered by the default examples. And I guess i'm not experienced enough with funky Funcs. Any help would be appreciated.

Thx.

The OwinExtentionMethods looks like :

     public static class MembershipRebootOwinExtensions
     {
        public static void UseMembershipReboot<TAccount>(
        this IAppBuilder app,
        Func<IDictionary<string, object>, UserAccountService<TAccount>>            userAccountServiceFactory,
        Func<IDictionary<string, object>, AuthenticationService<TAccount>> authenticationServiceFactory = null
        )
        where TAccount : UserAccount
        {
            app.Use<MembershipRebootMiddleware<TAccount>>(userAccountServiceFactory, authenticationServiceFactory);
            app.UseMembershipReboot();
        }

    public static void UseMembershipReboot<TAccount>(
        this IAppBuilder app,
        CookieAuthenticationOptions cookieOptions,
        Func<IDictionary<string, object>, UserAccountService<TAccount>> userAccountServiceFactory,
        Func<IDictionary<string, object>, AuthenticationService<TAccount>> authenticationServiceFactory = null
        )
        where TAccount : UserAccount
        {
            app.Use<MembershipRebootMiddleware<TAccount>>(userAccountServiceFactory, authenticationServiceFactory);
            app.UseMembershipReboot(cookieOptions);
        }

How would I fill in the two func's ?

    Func<IDictionary<string, object>, UserAccountService<TAccount>>

and

    Func<IDictionary<string, object>, AuthenticationService<TAccount>> 
2

There are 2 best solutions below

3
On

The custom user account sample has an example of using the generics:

https://github.com/brockallen/BrockAllen.MembershipReboot/tree/master/samples/CustomUserAccount

0
On

Simply obtain the current context of owin as

var owin = ctx.Resolve<IOwinContext>();

Then register your custom useraccount as

var owinAuth = new OwinAuthenticationService<CustomUserAccount>(AuthenticationTypes.Negotiate, ctx.Resolve<UserAccountService<CustomUserAccount>>(), owin.Environment);

I hope it's not too late.