// This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddIdentityServer()
     .AddDeveloperSigningCredential()
     .AddInMemoryApiResources(IdentityServerConfig.GetApiResources())
     .AddInMemoryClients(IdentityServerConfig.GetClients())
     .AddInMemoryIdentityResources(IdentityServerConfig.GetIdentityResources())
     .AddProfileService <ProfileService>()
     .AddResourceOwnerValidator <ResourceOwnerPasswordValidator>();
     services.AddControllers();
 }
示例#2
0
        public void ConfigureServices(IServiceCollection services)
        {
            IdentityModelEventSource.ShowPII = true;

            services.AddDbContext <ApplicationDbContext>(
                options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))
                );

            services.AddIdentityServer(options => {
                options.IssuerUri    = Configuration.GetSection("Authorization").GetSection("Issuer").Value;
                options.PublicOrigin = Configuration.GetSection("Authorization").GetSection("Issuer").Value;
            })
            .AddInMemoryCaching()
            .AddClientStore <InMemoryClientStore>()
            .AddResourceStore <InMemoryResourcesStore>()
            .AddInMemoryIdentityResources(IdentityServerConfig.GetIdentityResources())
            .AddInMemoryApiResources(IdentityServerConfig.GetApiResources())
            .AddInMemoryClients(IIdentityServerExtensions.AddInMemoryClientsWithClamis(Configuration.GetSection("IdentityServer:Clients")))
            .AddDeveloperSigningCredential()
            ;

            services.AddAuthentication(options =>
            {
                options.DefaultSignInScheme  = IdentityServerConstants.ExternalCookieAuthenticationScheme;
                options.DefaultSignOutScheme = IdentityServerConstants.SignoutScheme;
            })
            .AddOpenIdConnects(Configuration.GetSection("Authentication"));

            services.AddCors(options => options.AddPolicy("AllowAll", p => p.AllowAnyOrigin()
                                                          .AllowAnyMethod()
                                                          .AllowAnyHeader()));

            services.AddControllersWithViews(o =>
            {
                o.EnableEndpointRouting = false;
            });
            services.AddRazorPages();

            services.AddAutoMapper(typeof(Program));
            services.AddSingleton(AutoMapperConfiguration.Configure().CreateMapper());

            services.AddTransient <IUserRepository, UserRepository>();
            services.AddTransient <IUserService, UserService>();
        }
示例#3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var op = Configuration.GetConnectionString("Default");
            // services.AddDbContext<MyDbContext>(options => options.UseMySql(op));
            var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;

            services.AddControllers();
            services.AddIdentityServer()
            .AddInMemoryIdentityResources(IdentityServerConfig.GetIdentityResources())
            .AddInMemoryApiResources(IdentityServerConfig.GetApis())
            .AddInMemoryClients(IdentityServerConfig.GetClients())
            //.AddTestUsers(IdentityServerConfig.GetUsers())
            .AddConfigurationStore(options => options.ConfigureDbContext = b => b.UseSqlServer(op, sql => sql.MigrationsAssembly(migrationsAssembly)))
            .AddOperationalStore(options =>
            {
                options.ConfigureDbContext   = b => b.UseSqlServer(op, sql => sql.MigrationsAssembly(migrationsAssembly));
                options.EnableTokenCleanup   = true;
                options.TokenCleanupInterval = 30;
            });
        }
示例#4
0
        private void InitializeDatabase(IApplicationBuilder app)
        {
            using (var serviceScope = app.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope())
            {
                serviceScope.ServiceProvider.GetRequiredService <PersistedGrantDbContext>().Database.Migrate();

                var context = serviceScope.ServiceProvider.GetRequiredService <ConfigurationDbContext>();
                context.Database.Migrate();
                if (!context.Clients.Any())
                {
                    foreach (var client in IdentityServerConfig.GetClients())
                    {
                        context.Clients.Add(client.ToEntity());
                    }
                    context.SaveChanges();
                }

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

                if (!context.ApiResources.Any())
                {
                    foreach (var resource in IdentityServerConfig.GetApis())
                    {
                        context.ApiResources.Add(resource.ToEntity());
                    }
                    context.SaveChanges();
                }
            }
        }