コード例 #1
0
        public void ConfigureServices(IServiceCollection services)
        {
            DalServices.AddServices(services);
            BlServices.AddServices(services);

            services
            .AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme    = CookieAuthenticationDefaults.AuthenticationScheme;
            }
                               )
            .AddCookie(options =>
            {
                options.Events = new CookieAuthenticationEvents
                {
                    OnRedirectToLogin = context =>
                    {
                        context.Response.StatusCode = 401;
                        return(Task.CompletedTask);
                    }
                };
            }
                       );

            services
            .Configure <CookiePolicyOptions>(options =>
            {
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            }
                                             );

            services
            .AddSpaStaticFiles(configuration =>
            {
                configuration.RootPath = Configuration.GetSection("SpaRootPath").Value;
            }
                               );

            services
            .AddMvc()
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
        }
コード例 #2
0
ファイル: Startup.cs プロジェクト: zlobur/Parleo-backend
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSignalR().AddAzureSignalR(Configuration.GetConnectionString("SignalRConnection"));
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Latest);

            services.AddSwaggerDocumentation();

            IJwtSettings jwtSettings = new JwtSettings(Configuration);

            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(options =>
            {
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuer   = false,
                    ValidateAudience = false,
                    ValidateLifetime = true,
                    IssuerSigningKey = new SymmetricSecurityKey(
                        Encoding.UTF8.GetBytes(jwtSettings.JWTKey)
                        ),
                    ValidateIssuerSigningKey = true,
                };
            });

            // TODO: refactor this and specify origins
            services.AddCors(options =>
            {
                options.AddPolicy("AllowAll",
                                  builder =>
                {
                    builder
                    .AllowAnyHeader()
                    .AllowAnyMethod()
                    .SetIsOriginAllowed((host) => true)
                    .AllowCredentials();
                });
            });

            ConfigureMapperFactory(services);
            BLServices.AddServices(services);
            DalServices.AddServices(services, Configuration.GetConnectionString("DefaultConnection"));
            WebServices.AddServices(services);

            var policy = new AuthorizationPolicyBuilder()
                         .RequireAuthenticatedUser()
                         .RequireClaim("IsAuthorization", "true")
                         .Build();

            services
            .AddMvc(options =>
            {
                options.Filters.Add(new AuthorizeFilter(policy));
            })
            .SetCompatibilityVersion(CompatibilityVersion.Latest);

            services.AddResponseCompression(options =>
            {
                options.Providers.Add <GzipCompressionProvider>();
                options.MimeTypes      = new[] { "image/jpg", "image/jpeg", "image/png", "image/svg+xml" };
                options.EnableForHttps = true;
            });
            services.Configure <GzipCompressionProviderOptions>(options =>
            {
                options.Level = CompressionLevel.Optimal;
            });
        }
コード例 #3
0
        public void SetUpDb()
        {
            DalServices dalServices = new DalServices();

            dalServices.DalSetUpDb();
        }