Beispiel #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllersWithViews();

            // services.Configure<AppDbSettings> (Configuration.GetSection ("ConnectionString"));

            appDbSettings = Configuration.GetSection("AuthServer").Get <AppDbSettings> ();
            var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;

            services.AddDbContext <AppIdentityDbContext> (options => options.UseSqlServer(appDbSettings.ConnectionString));

            services.AddIdentity <AppUser, IdentityRole> (options => {
                options.Password.RequireDigit           = false;
                options.Password.RequireLowercase       = false;
                options.Password.RequireNonAlphanumeric = false;
                options.Password.RequireUppercase       = false;
                // options.Password.RequiredUniqueChars = false;
                options.Password.RequiredLength = 4;
            })
            .AddEntityFrameworkStores <AppIdentityDbContext> ()
            .AddDefaultTokenProviders();

            services.AddIdentityServer()
            // .AddOperationalStore (options => {

            //   options.ConfigureDbContext = builder => builder.UseSqlServer (appDbSettings.ConnectionString);
            //   options.EnableTokenCleanup = true;
            //   options.TokenCleanupInterval = 30;
            // })
            .AddInMemoryIdentityResources(Config.IdentityResources)
            .AddInMemoryApiResources(Config.ApiResources)
            .AddInMemoryClients(Config.Clients)
            .AddInMemoryApiScopes(Config.ApiScopes)
            .AddAspNetIdentity <AppUser> ()
            .AddDeveloperSigningCredential();

            // services.AddIdentity<AppUser, IdentityRole> (options => {
            //     options.Password.RequireDigit = false;
            //     options.Password.RequireLowercase = false;
            //     options.Password.RequireNonAlphanumeric = false;
            //     options.Password.RequireUppercase = false;
            //     // options.Password.RequiredUniqueChars = false;
            //     options.Password.RequiredLength = 4;
            //   })
            //   .AddEntityFrameworkStores<AppIdentityDbContext> ()
            //   .AddDefaultTokenProviders ();

            // services.AddIdentityServer (options => {
            //     // options.UserInteraction.LoginUrl = "http://localhost:4200/login";
            //   })
            //   .AddAspNetIdentity<AppUser> ()
            //   .AddConfigurationStore (options => {
            //     options.ConfigureDbContext = b => b.UseSqlServer (appDbSettings.ConnectionString, sql => sql.MigrationsAssembly (migrationsAssembly));
            //   })
            //   .AddOperationalStore (options => {
            //     options.ConfigureDbContext = b => b.UseSqlServer (appDbSettings.ConnectionString, sql => sql.MigrationsAssembly (migrationsAssembly));
            //   })
            //   .AddDeveloperSigningCredential ();

            services.AddCors(options => options.AddPolicy("AllowAll", p => p.AllowAnyOrigin()
                                                          .AllowAnyMethod()
                                                          .AllowAnyHeader()));
        }
Beispiel #2
0
 public Startup(IConfiguration configuration, AppDbSettings appDbSettings)
 {
     this.Configuration = configuration;
     this.appDbSettings = appDbSettings;
 }