예제 #1
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>();
        }