示例#1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();


            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlite("Data Source=C:\\Users\\jason\\IdentityServer4_Test.db"));


            //services.AddDefaultIdentity<ApplicationUser>()
            //                .AddDefaultUI(UIFramework.Bootstrap4)
            //                .AddEntityFrameworkStores<ApplicationDbContext>();

            services.AddIdentity <ApplicationUser, IdentityRole>()
            .AddEntityFrameworkStores <ApplicationDbContext>()
            .AddDefaultUI(UIFramework.Bootstrap4)
            .AddDefaultTokenProviders();


            var builder = services.AddIdentityServer()
                          .AddInMemoryIdentityResources(Config.GetIdentityResources())
                          .AddInMemoryApiResources(Config.GetApis())
                          .AddInMemoryClients(Config.GetClients())
                          //.AddTestUsers(Config.GetUsers());
                          .AddAspNetIdentity <ApplicationUser>();


            if (Environment.IsDevelopment())
            {
                builder.AddDeveloperSigningCredential();
            }
            else
            {
                throw new Exception("need to configure key material");
            }
        }