Example #1
0
        public void ConfigureServices(IServiceCollection services)
        {
            var connection        = Configuration["Production:SqliteConnectionString"];
            var folderForKeyStore = Configuration["Production:KeyStoreFolderWhichIsBacked"];

            var cert = new X509Certificate2(Path.Combine(_environment.ApplicationBasePath, "damienbodserver.pfx"), "");

            services.AddDataProtection();
            services.ConfigureDataProtection(configure =>
            {
                configure.SetApplicationName("AspNet5IdentityServerAngularImplicitFlow");
                configure.ProtectKeysWithCertificate(cert);
                // This folder needs to be backed up.
                configure.PersistKeysToFileSystem(new DirectoryInfo(folderForKeyStore));
            });

            services.AddEntityFramework()
            .AddSqlite()
            .AddDbContext <DataEventRecordContext>(options => options.UseSqlite(connection));

            //Add Cors support to the service
            services.AddCors();

            var policy = new Microsoft.AspNet.Cors.Infrastructure.CorsPolicy();

            policy.Headers.Add("*");
            policy.Methods.Add("*");
            policy.Origins.Add("*");
            policy.SupportsCredentials = true;

            services.AddCors(x => x.AddPolicy("corsGlobalPolicy", policy));

            var guestPolicy = new AuthorizationPolicyBuilder()
                              .RequireAuthenticatedUser()
                              .RequireClaim("scope", "dataEventRecords")
                              .Build();

            services.AddAuthorization(options =>
            {
                options.AddPolicy("dataEventRecordsAdmin", policyAdmin =>
                {
                    policyAdmin.RequireClaim("role", "dataEventRecords.admin");
                });
                options.AddPolicy("dataEventRecordsUser", policyUser =>
                {
                    policyUser.RequireClaim("role", "dataEventRecords.user");
                });
            });

            services.AddMvc(options =>
            {
                options.Filters.Add(new AuthorizeFilter(guestPolicy));
            });

            services.AddScoped <IDataEventRecordRepository, DataEventRecordRepository>();
        }
Example #2
0
        public void ConfigureServices(IServiceCollection services)
        {
            //Add Cors support to the service
            services.AddCors();

            var policy = new Microsoft.AspNet.Cors.Infrastructure.CorsPolicy();

            policy.Headers.Add("*");
            policy.Methods.Add("*");
            policy.Origins.Add("*");
            policy.SupportsCredentials = true;

            services.AddCors(x => x.AddPolicy("corsGlobalPolicy", policy));

            services.AddMvc();
        }
        public void ConfigureServices(IServiceCollection services)
        {
            //Add Cors support to the service
            services.AddCors();

            var policy = new Microsoft.AspNet.Cors.Infrastructure.CorsPolicy();

            policy.Headers.Add("*");
            policy.Methods.Add("*");
            policy.Origins.Add("*");
            policy.SupportsCredentials = true;

            services.AddCors(x => x.AddPolicy("corsGlobalPolicy", policy));

            services.AddMvc();
        }
Example #4
0
        public void ConfigureServices(IServiceCollection services)
        {
            // data services
            services.AddEntityFramework()
            .AddSqlServer()
            .AddDbContext <ApiDbContext>(options => {
                options.UseSqlServer(_config["Data:Development:SqlServerConnectionString"]);
            });

            services.AddScoped <Entity.Stores.ProductStore>();
            services.AddScoped <Entity.Stores.CategoryStore>();
            services.AddScoped <Entity.Stores.ColorStore>();
            services.AddScoped <Entity.Stores.OrderStore>();

            // hosting
            services.AddCors(x => {
                var policy = new Microsoft.AspNet.Cors.Infrastructure.CorsPolicy();

                policy.Headers.Add("*");
                policy.Methods.Add("*");
                policy.Origins.Add("*");
                policy.SupportsCredentials = true;

                x.AddPolicy("corsGlobalPolicy", policy);
            });

            services.AddMvc().AddJsonOptions(options => {
                options.SerializerSettings.ContractResolver      = new CamelCasePropertyNamesContractResolver();
                options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
                options.SerializerSettings.DateFormatHandling    = Newtonsoft.Json.DateFormatHandling.IsoDateFormat;
                options.SerializerSettings.DateTimeZoneHandling  = Newtonsoft.Json.DateTimeZoneHandling.Utc;
            });

            // security
            services.Configure <SecurityConfig>(_config.GetSection("Security"));
            services.AddTransient <ClaimsPrincipal>(s => s.GetService <IHttpContextAccessor>().HttpContext.User);
            services.AddSingleton <IAuthorizationHandler, TrustedWebClientHandler>();

            services.AddAuthorization(options =>
                                      options.AddPolicy("TrustedClients", p => p.AddRequirements(new TrustedWebClientRequirement()))
                                      );
        }
        public void ConfigureServices(IServiceCollection services)
        {
            //Add Cors support to the service
            services.AddCors();

            var policy = new Microsoft.AspNet.Cors.Infrastructure.CorsPolicy();

            policy.Headers.Add("*");
            policy.Methods.Add("*");
            policy.Origins.Add("*");
            policy.SupportsCredentials = true;

            services.AddCors(x => x.AddPolicy("corsGlobalPolicy", policy));

            var cert = new X509Certificate2(Path.Combine(_environment.ApplicationBasePath, "damienbodserver.pfx"), "");

            var builder = services.AddIdentityServer(options =>
            {
                options.SigningCertificate = cert;
                options.Endpoints.EnableEndSessionEndpoint = true;
                options.AuthenticationOptions = new AuthenticationOptions
                {
                    EnableSignOutPrompt = false
                };
            });

            builder.Services.AddLogging();
            builder.AddInMemoryClients(Clients.Get());
            builder.AddInMemoryScopes(Scopes.Get());
            builder.AddInMemoryUsers(Users.Get());

            // for the UI
            services
            .AddMvc()
            .AddRazorOptions(razor =>
            {
                razor.ViewLocationExpanders.Add(new CustomViewLocationExpander());
            });
            services.AddTransient <LoginService>();
        }
Example #6
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 http://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            var policy = new Microsoft.AspNet.Cors.Infrastructure.CorsPolicy();

            services.AddCors();
            policy.Headers.Add("*");
            policy.Methods.Add("*");
            policy.Origins.Add("*");
            policy.SupportsCredentials = true;
            services.AddCors(x => x.AddPolicy("corsGlobalPolicy", policy));

            var inMemoryManager = new InMemoryManager();

            var builder = services.AddIdentityServer(options =>
            {
                options.SigningCertificate = Certificate.Get();
                options.Endpoints.EnableEndSessionEndpoint = true;
                options.AuthenticationOptions = new AuthenticationOptions
                {
                    EnableSignOutPrompt = false
                };
            });

            builder.AddInMemoryClients(inMemoryManager.GetClients());
            builder.AddInMemoryScopes(inMemoryManager.GetScopes());
            builder.AddInMemoryUsers(inMemoryManager.GetUsers());



            // for the UI
            services
            .AddMvc()
            .AddRazorOptions(razor =>
            {
                razor.ViewLocationExpanders.Add(new CustomViewLocationExpander());
            });
            services.AddTransient <LoginService>();
        }
        public void ConfigureServices(IServiceCollection services)
        {
            var connection = Configuration["Production:SqliteConnectionString"];

            services.AddEntityFramework()
                .AddSqlite()
                .AddDbContext<DataEventRecordContext>(options => options.UseSqlite(connection));

            //Add Cors support to the service
            services.AddCors();

            var policy = new Microsoft.AspNet.Cors.Infrastructure.CorsPolicy();

            policy.Headers.Add("*");
            policy.Methods.Add("*");
            policy.Origins.Add("*");
            policy.SupportsCredentials = true;

            services.AddCors(x => x.AddPolicy("corsGlobalPolicy", policy));

            services.AddMvc();
            services.AddScoped<IDataEventRecordRepository, DataEventRecordRepository>();
        }
Example #8
0
        public void ConfigureServices(IServiceCollection services)
        {
            var connection = Configuration["Production:SqliteConnectionString"];

            services.AddEntityFramework()
            .AddSqlite()
            .AddDbContext <DataEventRecordContext>(options => options.UseSqlite(connection));

            //Add Cors support to the service
            services.AddCors();

            var policy = new Microsoft.AspNet.Cors.Infrastructure.CorsPolicy();

            policy.Headers.Add("*");
            policy.Methods.Add("*");
            policy.Origins.Add("*");
            policy.SupportsCredentials = true;

            services.AddCors(x => x.AddPolicy("corsGlobalPolicy", policy));

            services.AddMvc();
            services.AddScoped <IDataEventRecordRepository, DataEventRecordRepository>();
        }
Example #9
0
        public void ConfigureServices(IServiceCollection services)
        {
            //Add Cors support to the service
            services.AddCors();

            var policy = new Microsoft.AspNet.Cors.Infrastructure.CorsPolicy();

            policy.Headers.Add("*");
            policy.Methods.Add("*");
            policy.Origins.Add("*");
            policy.SupportsCredentials = true;

            services.AddCors(x => x.AddPolicy("corsGlobalPolicy", policy));

            var securedFilesPolicy = new AuthorizationPolicyBuilder()
                                     .RequireAuthenticatedUser()
                                     .RequireClaim("scope", "securedFiles")
                                     .Build();

            services.AddAuthorization(options =>
            {
                options.AddPolicy("securedFilesUser", policyUser =>
                {
                    policyUser.RequireClaim("role", "securedFiles.user");
                });
            });

            services.AddMvc(options =>
            {
                options.Filters.Add(new AuthorizeFilter(securedFilesPolicy));
            });

            services.AddMvc();

            services.AddTransient <ISecuredFileProvider, SecuredFileProvider>();
            services.AddSingleton <UseOnceAccessIdService>();
        }