Exemple #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            #region ²âÊÔIdentityServer4
            var builder = services.AddIdentityServer(options =>
            {
                options.Events.RaiseErrorEvents       = true;
                options.Events.RaiseInformationEvents = true;
                options.Events.RaiseFailureEvents     = true;
                options.Events.RaiseSuccessEvents     = true;
            })
                          // in-memory, code config
                          .AddTestUsers(InMemoryConfiguration.Users().ToList())
                          .AddInMemoryApiResources(InMemoryConfiguration.GetApiResources())
                          .AddInMemoryClients(InMemoryConfiguration.GetClients())
                          .AddInMemoryIdentityResources(InMemoryConfiguration.GetIdentityResources());


            builder.AddDeveloperSigningCredential();

            if (Environment.IsDevelopment())
            {
                builder.AddDeveloperSigningCredential();
            }
            else
            {
                throw new Exception("need to configure key material");
            }
            #endregion
            services.AddRazorPages();
        }
Exemple #2
0
        private static void Seed(IServiceScope serviceScope)
        {
            var context = serviceScope
                          .ServiceProvider
                          .GetRequiredService <ConfigurationDbContext>();

            if (!context.Clients.Any())
            {
                foreach (var client in InMemoryConfiguration.GetClients())
                {
                    context.Clients.Add(client.ToEntity());
                }
                context.SaveChanges();
            }

            if (!context.IdentityResources.Any())
            {
                foreach (var resource in InMemoryConfiguration.GetIdentityResources())
                {
                    context.IdentityResources.Add(resource.ToEntity());
                }
                context.SaveChanges();
            }

            if (!context.ApiResources.Any())
            {
                foreach (var resource in InMemoryConfiguration.GetApiResources())
                {
                    context.ApiResources.Add(resource.ToEntity());
                }
                context.SaveChanges();
            }
        }
        // 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)
        {
            /*
             * 对于Token签名需要一对公钥和私钥,
             * 不过IdentityServer为开发者提供了一个AddDeveloperSigningCredential()方法,它会帮我们搞定这个事,并默认存到硬盘中。
             * 当切换到生产环境时,还是得使用正儿八经的证书,更换为使用AddSigningCredential()方法
             */

            // var basePath = PlatformServices.Default.Application.ApplicationBasePath;
            var basePath = AppContext.BaseDirectory;

            InMemoryConfiguration.Configuration = this.Configuration;

            services.AddIdentityServer()
            // .AddDeveloperSigningCredential()
            .AddSigningCredential(new X509Certificate2(Path.Combine(basePath,
                                                                    Configuration["Certificates:CerPath"]),
                                                       Configuration["Certificates:Password"]))
            .AddTestUsers(InMemoryConfiguration.GetUsers().ToList())
            .AddInMemoryClients(InMemoryConfiguration.GetClients())
            .AddInMemoryApiResources(InMemoryConfiguration.GetApiResources());

            // for QuickStart-UI
            services.AddMvc();
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            //var basePath = PlatformServices.Default.Application.ApplicationBasePath;
            //InMemoryConfiguration.Configuration = this.Configuration;

            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });


            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            services.AddIdentityServer()
            .AddDeveloperSigningCredential()     //开发测试密钥
                                                 //.AddSigningCredential(new X509Certificate2(Path.Combine(basePath,
                                                 //Configuration["Certificates:CerPath"]),
                                                 //Configuration["Certificates:Password"]))
            .AddInMemoryIdentityResources(InMemoryConfiguration.GetIdentityResources())
            .AddTestUsers(InMemoryConfiguration.GetUsers().ToList())
            .AddInMemoryClients(InMemoryConfiguration.GetClients())
            .AddInMemoryApiResources(InMemoryConfiguration.GetApiResources());
        }
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
     services.AddIdentityServer()
     .AddDeveloperSigningCredential()
     .AddTestUsers(InMemoryConfiguration.GetUsers().ToList())
     .AddInMemoryClients(InMemoryConfiguration.GetClients())
     .AddInMemoryApiResources(InMemoryConfiguration.GetApiResources());
 }
        // 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)
        {
            //var basePath = PlatformServices.Default.Application.ApplicationBasePath;
            //InMemoryConfiguration.Configuration = this.Configuration;

            services.AddIdentityServer()
            .AddDeveloperSigningCredential()
            //.AddSigningCredential(new X509Certificate2(Path.Combine(basePath,Configuration["Certificates:CerPath"]),Configuration["Certificates:Password"]))
            .AddTestUsers(InMemoryConfiguration.GetUsers().ToList())
            .AddInMemoryClients(InMemoryConfiguration.GetClients())
            .AddInMemoryApiResources(InMemoryConfiguration.GetApiResources());
        }
Exemple #7
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var basePath = PlatformServices.Default.Application.ApplicationBasePath;

            InMemoryConfiguration.Configuration = this.Configuration;

            services.AddIdentityServer()
            //.AddDeveloperSigningCredential()
            .AddSigningCredential(new X509Certificate2(Path.Combine(basePath,
                                                                    Configuration["Certificates:CerPath"]),
                                                       Configuration["Certificates:Password"]))
            .AddInMemoryIdentityResources(InMemoryConfiguration.GetIdentityResources())
            .AddTestUsers(InMemoryConfiguration.GetUsers().ToList())
            .AddInMemoryClients(InMemoryConfiguration.GetClients())
            .AddInMemoryApiResources(InMemoryConfiguration.GetApiResources());
            // for QuickStart-UI
            services.AddMvc();
            //services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
        }
Exemple #8
0
        public void MigrateInMemoryDataToSqlServer(IApplicationBuilder app)
        {
            using (var scope = app.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope())
            {
                scope.ServiceProvider.GetRequiredService <PersistedGrantDbContext>().Database.Migrate();

                var context = scope.ServiceProvider.GetRequiredService <ConfigurationDbContext>();

                context.Database.Migrate();

                if (!context.Clients.Any())
                {
                    foreach (var client in InMemoryConfiguration.GetClients())
                    {
                        context.Clients.Add(client.ToEntity());
                    }

                    context.SaveChanges();
                }

                if (!context.IdentityResources.Any())
                {
                    foreach (var resource in InMemoryConfiguration.GetIdentityResources())
                    {
                        context.IdentityResources.Add(resource.ToEntity());
                    }

                    context.SaveChanges();
                }

                if (!context.ApiResources.Any())
                {
                    foreach (var resource in InMemoryConfiguration.GetApiResources())
                    {
                        context.ApiResources.Add(resource.ToEntity());
                    }

                    context.SaveChanges();
                }
            }
        }
Exemple #9
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSingleton(new GetTableData(Environment.ContentRootPath));
            services.AddSingleton(new Appsettings(Environment.ContentRootPath));


            services.AddSingleton <IUserService, UserService>();
            services.AddSingleton <IRoleService, RoleService>();
            services.AddSingleton <IUserRoleService, UserRoleService>();

            #region ²âÊÔIdentityServer4
            var builder = services.AddIdentityServer(options =>
            {
                options.Events.RaiseErrorEvents       = true;
                options.Events.RaiseInformationEvents = true;
                options.Events.RaiseFailureEvents     = true;
                options.Events.RaiseSuccessEvents     = true;
            })
                          // in-memory, code config
                          .AddTestUsers(InMemoryConfiguration.Users().ToList())
                          .AddInMemoryApiResources(InMemoryConfiguration.GetApiResources())
                          .AddInMemoryClients(InMemoryConfiguration.GetClients())
                          .AddInMemoryIdentityResources(InMemoryConfiguration.GetIdentityResources());
            //.AddResourceOwnerValidator<ResourceOwnerPasswordValidator>()
            //.AddProfileService<CustomProfileService>();


            builder.AddDeveloperSigningCredential();

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