Пример #1
0
        private static void EnsureSeedData(ConfigurationDbContext context, UserManager <ApplicationUser> userManager)
        {
            if (!context.Clients.Any())
            {
                foreach (var client in IdentityConfig.GetClients().ToList())
                {
                    context.Clients.Add(client.ToEntity());
                }
                context.SaveChanges();
                //
                foreach (var user in IdentityConfig.GetUsers())
                {
                    userManager.CreateAsync(new ApplicationUser {
                        UserName = user.Username
                    }, user.Password);
                }
            }

            if (!context.Scopes.Any())
            {
                foreach (var client in IdentityConfig.GetScopes().ToList())
                {
                    context.Scopes.Add(client.ToEntity());
                }
                context.SaveChanges();
            }
        }
Пример #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // configure identity server with in-memory stores, keys, clients and scopes
            services.AddIdentityServer()
            .AddTemporarySigningCredential()
            .AddInMemoryIdentityResources(IdentityConfig.GetIdentityResources())
            .AddInMemoryApiResources(IdentityConfig.GetApiResources())
            .AddInMemoryClients(IdentityConfig.GetClients())
            .AddTestUsers(IdentityConfig.GetUsers());

            services.AddAuthorization(auth =>
            {
                auth.AddSecurity();
            });

            services.AddSingleton <IUserDataService, UserDataService>();

            services.AddSingleton <IUserRepository, UserRepository>();
            services.AddSingleton <IUserRoleRepository, UserRoleRepository>();

            Action <AccountService.AccountServiceOptions> options = (opt =>
            {
                opt.AppDBConnection = Configuration["ConnectionStrings:DefaultConnection"];
            });

            services.Configure(options);
            services.AddSingleton(resolver => resolver.GetRequiredService <IOptions <AccountService.AccountServiceOptions> >().Value);

            services.AddMvc();
        }
Пример #3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddIdentityServer()
            .AddDeveloperSigningCredential()
            .AddInMemoryIdentityResources(IdentityConfig.GetIdentityResources())
            .AddInMemoryApiResources(IdentityConfig.GetApiResources())
            .AddInMemoryClients(IdentityConfig.GetClient())
            .AddTestUsers(IdentityConfig.GetUsers());

            services.AddMvc();
        }