Example #1
0
        public virtual void Configuration(IAppBuilder app)
        {
            app.CreatePerOwinContext <MyUserStore>(() => new MyUserStore());
            app.CreatePerOwinContext <MyUserManager>((opt, ctx) =>
            {
                var manager = new MyUserManager(ctx.Get <MyUserStore>());
                var dataProtectionProvider = opt.DataProtectionProvider;
                if (dataProtectionProvider != null)
                {
                    manager.UserTokenProvider = new DataProtectorTokenProvider <MyUser>(
                        dataProtectionProvider.Create());
                    //dataProtectionProvider.Create("ASP.NET Identity"/*optional; by default it includes application name and Microsoft.Owin.Security.IDataProtector as purposes; everything is additional*/));
                }
                return(manager);
            });
            app.CreatePerOwinContext <MySignInManager>((opt, ctx) =>
                                                       new MySignInManager(ctx.GetUserManager <MyUserManager>(), ctx.Authentication)
                                                       );

            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath          = new PathString("/Account/Login"),
                Provider           = new CookieAuthenticationProvider
                {
                    // Enables the application to validate the security stamp when the user logs in.
                    // This is a security feature which is used when you change a password or add an external login to your account.
                    OnValidateIdentity = SecurityStampValidator.OnValidateIdentity <MyUserManager, MyUser>(
                        validateInterval: TimeSpan.FromMinutes(20),
                        regenerateIdentity: (manager, user) => manager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie))
                }
            });

            app.CreatePerOwinContext <Middleware>(() => new Middleware(new List <MyAppRoute>
            {
                // Your routes
                new MyAppRoute("Person", typeof(PersonController)),
                new MyAppRoute("Account", typeof(AccountController))
            }));

            app.Run(ctx =>
            {
                var middleware = ctx.Get <Middleware>();
                return(middleware.Invoke(ctx.Environment));
            });
        }
Example #2
0
 public MySignInManager(MyUserManager userManager, IAuthenticationManager authenticationManager) :
     base(userManager, authenticationManager)
 {
 }