public static IUserService Factory(string connString)
        {
            var db = new IdentityDbContext<IdentityUser>(connString);
            var store = new UserStore<IdentityUser>(db);
            var mgr = new UserManager<IdentityUser>(store);
            mgr.PasswordValidator = new PasswordValidator
            {
                RequiredLength = 3
            };
            var userSvc = new AspNetIdentityUserService<IdentityUser, string>(mgr, db);
            return userSvc;

            //var db = new CustomDbContext(connString);
            //var store = new CustomUserStore(db);
            //var mgr = new CustomUserManager(store);
            //var userSvc = new AspNetIdentityUserService<CustomUser, int>(mgr, db);
            //return userSvc;
        }
Пример #2
0
        public static IUserService Factory(string connString)
        {
#if USE_INT_PRIMARYKEY
            connString += "_CustomPK";

            var db    = new IdentityDbContext <CustomUser, CustomRole, int, CustomUserLogin, CustomUserRole, CustomUserClaim>(connString);
            var store = new UserStore <CustomUser, CustomRole, int, CustomUserLogin, CustomUserRole, CustomUserClaim>(db);
            var mgr   = new UserManager <CustomUser, int>(store);
            mgr.PasswordValidator = new PasswordValidator
            {
                RequiredLength = 3
            };
            var userSvc = new AspNetIdentityUserService <CustomUser, int>(mgr, db);
            return(userSvc);
#else
            var db    = new IdentityDbContext <IdentityUser>(connString);
            var store = new UserStore <IdentityUser>(db);
            var mgr   = new UserManager <IdentityUser>(store);
            mgr.PasswordValidator = new PasswordValidator
            {
                RequiredLength = 3
            };
            var userSvc = new AspNetIdentityUserService <IdentityUser, string>(mgr, db);
            return(userSvc);
#endif
        }
Пример #3
0
        public static IdentityServerServiceFactory Configure(this IdentityServerServiceFactory factory,
                                                             string connectionString)
        {
            var serviceOptions = new EntityFrameworkServiceOptions {
                ConnectionString = connectionString, Schema = "AuthServer".ToUpper()
            };

            SetupScopes(InMemoryManager.GetScopes(), serviceOptions);
            SetupUsers(InMemoryManager.GetUsers(), serviceOptions);
            SetupClients(InMemoryManager.GetClients(), serviceOptions);
            factory.RegisterOperationalServices(serviceOptions);
            factory.RegisterConfigurationServices(serviceOptions);
            //factory.Register(new Registration<OperationsDbContext>(resolver=>new OperationsDbContext(serviceOptions.ConnectionString,serviceOptions.Schema)));
            factory.Register(new Registration <Context>(resolver => new Context(connectionString)));
            factory.Register(new Registration <UserStore>());
            factory.Register(new Registration <UserManager>());
            new TokenCleanup(serviceOptions, 1).Start();
            var context = new Context(serviceOptions.ConnectionString);

            var userService =
                new AspNetIdentityUserService <IdentityUser, string>(new UserManager(new UserStore(context)));

            factory.UserService = new Registration <IUserService>(userService);
            return(factory);
        }
Пример #4
0
        public static IUserService Factory(string connString)
        {
            var db    = new IdentityDbContext <AppUser, AppRole, int, AppUserLogin, AppUserRole, AppUserClaim>(connString);
            var store = new UserStore <AppUser, AppRole, int, AppUserLogin, AppUserRole, AppUserClaim>(db);
            var mgr   = new UserManager <AppUser, int>(store);

            mgr.PasswordValidator = new PasswordValidator
            {
                RequiredLength = 3
            };
            var userSvc = new AspNetIdentityUserService <AppUser, int>(mgr, db);

            return(userSvc);
        }
        public static IUserService Factory(string connString)
        {
            var db = new IdentityDbContext<IdentityUser>(connString);
            var store = new UserStore<IdentityUser>(db);
            var mgr = new UserManager<IdentityUser>(store);
            var userSvc = new AspNetIdentityUserService<IdentityUser, string>(mgr, db);
            return userSvc;

            //var db = new CustomDbContext("CustomAspId");
            //var store = new CustomUserStore(db);
            //var mgr = new CustomUserManager(store);
            //var userSvc = new UserService<CustomUser, int>(mgr, db);
            //return userSvc;
        }
Пример #6
0
        public static IUserService Factory(string connString)
        {
            var db      = new IdentityDbContext <IdentityUser>(connString);
            var store   = new UserStore <IdentityUser>(db);
            var mgr     = new UserManager <IdentityUser>(store);
            var userSvc = new AspNetIdentityUserService <IdentityUser, string>(mgr, db);

            return(userSvc);

            //var db = new CustomDbContext("CustomAspId");
            //var store = new CustomUserStore(db);
            //var mgr = new CustomUserManager(store);
            //var userSvc = new UserService<CustomUser, int>(mgr, db);
            //return userSvc;
        }
        public static IUserService Factory(string connString)
        {
            var db    = new IdentityDbContext <IdentityUser>(connString);
            var store = new UserStore <IdentityUser>(db);
            var mgr   = new UserManager <IdentityUser>(store);

            mgr.PasswordValidator = new PasswordValidator
            {
                RequiredLength = 3
            };
            var userSvc = new AspNetIdentityUserService <IdentityUser, string>(mgr, db);

            return(userSvc);

            //var db = new CustomDbContext(connString);
            //var store = new CustomUserStore(db);
            //var mgr = new CustomUserManager(store);
            //var userSvc = new AspNetIdentityUserService<CustomUser, int>(mgr, db);
            //return userSvc;
        }
Пример #8
0
        public void Configuration(IAppBuilder app)
        {
            #region customer login css
            //var viewOPtions = new DefaultViewServiceOptions();
            //viewOPtions.CustomViewDirectory = string.Format(@"{0}\Templates\", AppDomain.CurrentDomain.BaseDirectory);
            //viewOPtions.Stylesheets.Add("/Content/Site.css");
            //options.Factory.ConfigureDefaultViewService(viewOPtions);
            #endregion

            #region Role Scope EF config

            //ASP.Net identity user role... + identity server3 (EF client scope)

            var efOptions = new EntityFrameworkServiceOptions()
            {
                ConnectionString = "AuthServer",
                Schema           = Constants.IdentityServerSchema,
            };

            var factory = new IdentityServerServiceFactory();
            factory.RegisterClientStore(efOptions);
            factory.RegisterScopeStore(efOptions);
            //factory.UseInMemoryUsers(InMemoryUsers.GetAllUsers());
            //factory.UserService = new Registration<IdentityServer3.Core.Services.IUserService>();

            #endregion

            #region User EF config

            //IdentityDbContext identityDbContext = new IdentityDbContext("AuthServer");
            IdentityDbContext identityDbContext = new CustomIdentityDbContext("AuthServer");

            UserManager <IdentityUser> userManager = new UserManager <IdentityUser>(new UserStore <IdentityUser>(identityDbContext));
            RoleManager <IdentityRole> roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(identityDbContext));

            var userService = new AspNetIdentityUserService <IdentityUser, string>(userManager);

            factory.UserService = new Registration <IdentityServer3.Core.Services.IUserService>(userService);
            #endregion

            //factory.RegisterConfigurationServices(efOptions);

            #region Token and Cache config

            factory.RegisterOperationalServices(efOptions);//database store token

            factory.ConfigureClientStoreCache();
            factory.ConfigureScopeStoreCache();
            factory.ConfigureUserServiceCache();

            var clearToken = new TokenCleanup(efOptions, 60);
            clearToken.Start();


            #endregion


            #region IdentityServer config

            var options = new IdentityServerOptions()
            {
                Factory = factory,

                RequireSsl = false,

                AuthenticationOptions = new AuthenticationOptions
                {
                    EnablePostSignOutAutoRedirect = true,
                    IdentityProviders             = IdentityProviderManager.ConfigureIdentityProviders,
                },

                SigningCertificate = new System.Security.Cryptography.X509Certificates.X509Certificate2(string.Format(@"{0}\certificate\server.pfx", AppDomain.CurrentDomain.BaseDirectory), "4022042"),
            };

            #endregion

            //SampleDataProvider.InitClientAndScopeSampleDatas(efOptions);//init some data

            app.ConfigureManagerService();//for Identity Manager Pages

            app.UseIdentityServer(options);
        }