/// <summary>
        /// Configures the services.
        /// </summary>
        /// <param name="services">The services.</param>
        public void ConfigureServices(IServiceCollection services)
        {
            ConfigurationOptions.ConfigureService(services, Configuration);

            // Add framework services.
            services.AddMvc(
                options =>
            {
                options.Filters.Add(typeof(ValidateModelStateAttribute));
            });
            // Remove commented code and above semicolon
            // if the assembly of the API Controllers is different than project which contains Startup class
            //.AddApplicationPart(typeof(BaseController<>).Assembly);

            // Localization support
            LocalizationConfiguration.ConfigureService(services);

            Mapper.Reset();
            // https://github.com/AutoMapper/AutoMapper.Extensions.Microsoft.DependencyInjection/issues/28
            services.AddAutoMapper(typeof(Startup));

            // Swagger API documentation
            SwaggerConfiguration.ConfigureService(services);

            // IOC containers / Entity Framework
            EntityFrameworkConfiguration.ConfigureService(services, Configuration);
            IocContainerConfiguration.ConfigureService(services, Configuration);
            ApiVersioningConfiguration.ConfigureService(services);
        }
Beispiel #2
0
        public void ConfigureServices(IServiceCollection services)
        {
            ConfigurationOptions.ConfigureService(services, Configuration);

            services.AddMvc(
                options =>
            {
                options.Filters.Add(typeof(ValidateModelStateAttribute));
            });

            Mapper.Reset();
            services.AddAutoMapper(typeof(Startup));    // Swagger API documentation
            SwaggerConfiguration.ConfigureService(services);

            EntityFrameworkConfiguration.ConfigureService(services, Configuration);
            IocContainerConfiguration.ConfigureService(services, Configuration);
            ApiVersioningConfiguration.ConfigureService(services);


            services.AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = "JwtBearer";
                options.DefaultChallengeScheme    = "JwtBearer";
            })
            .AddJwtBearer("JwtBearer", jwtBearerOptions =>
            {
                jwtBearerOptions.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey         = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Constants.SymmetricSecurityKey)),

                    ValidateIssuer = false,

                    ValidateAudience = false,

                    ValidateLifetime = true,            //validate the expiration and not before values in the token

                    ClockSkew = TimeSpan.FromMinutes(5) //5 minute tolerance for the expiration date
                };

                jwtBearerOptions.Events = new JwtBearerEvents
                {
                    OnTokenValidated = context =>
                    {
                        var slug = context.HttpContext.Request.Headers[Constants.TenantId].ToString();

                        if (context.SecurityToken is JwtSecurityToken accessToken && !string.IsNullOrWhiteSpace(slug))
                        {
                            if (accessToken.Claims.Where(claim => claim.Type.Equals(ClaimTypes.PrimaryGroupSid)).Any(claim => slug == claim.Value))
                            {
                                return(Task.CompletedTask);
                            }
                        }

                        context.Fail($"Invalid 'slug'");
                        return(Task.CompletedTask);
                    }
                };
            });
Beispiel #3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <ForwardedHeadersOptions>(options =>
            {
                options.KnownProxies.Add(IPAddress.Parse("10.0.0.100"));
            });

            //Configure loging
            Log.Logger = new LoggerConfiguration()
                         .ReadFrom.Configuration(Configuration)
                         .WriteTo.Console()
                         .CreateLogger();
            services.AddSingleton(Log.Logger);

            //Configure db context
            EntityFrameworkConfiguration.ConfigureService(services, Configuration);

            //Add auto mapper on start up
            services.AddAutoMapper(typeof(Startup));

            //Configure dependency injection
            IocContainerConfiguration.ConfigureService(services);

            //Configure jwt
            JwtConfiguration.ConfigureService(services, Configuration);
            // Configure your policies
            services.AddAuthorization(options =>
            {
                options.AddPolicy(nameof(Role.SuperAdmin),
                                  policy => policy.RequireClaim(nameof(Role.SuperAdmin)));

                options.AddPolicy(nameof(Role.Administrator),
                                  policy => policy.RequireClaim(nameof(Role.Administrator)));

                options.AddPolicy(nameof(Role.User),
                                  policy => policy.RequireClaim(nameof(Role.User)));
            });

            // Configure action filter attribute
            services.AddControllers(opt =>
            {
                opt.Filters.Add(typeof(ValidateModel));
            });

            // Configure enforce lowercase routing
            services.AddRouting(options => options.LowercaseUrls = true);

            SwaggerConfiguration.ConfigureService(services);

            // Config for upload file
            services.Configure <FormOptions>(o => {
                o.ValueLengthLimit         = int.MaxValue;
                o.MultipartBodyLengthLimit = int.MaxValue;
                o.MemoryBufferThreshold    = int.MaxValue;
            });

            // Config Api Version
            services.AddApiVersioning();
        }
Beispiel #4
0
        /// <summary>
        /// Configures the services.
        /// This method gets called by the runtime. Use this method to add services to the container.
        /// </summary>
        /// <param name="services">The services.</param>
        public void ConfigureServices(IServiceCollection services)
        {
            ConfigurationOptions.ConfigureService(services, Configuration);

            // Add framework services.
            services.AddMvc();

            IocContainerConfiguration.ConfigureService(services, Configuration);
            SwaggerConfiguration.ConfigureService(services);
        }
Beispiel #5
0
        /// <summary>
        /// Configures the services.
        /// </summary>
        /// <param name="services">The services.</param>
        public void ConfigureServices(IServiceCollection services)
        {
            ConfigurationOptions.ConfigureService(services, Configuration);

            // Add framework services.
            services.AddMvc();

            // Swagger API documentation
            SwaggerConfiguration.ConfigureService(services);

            // IOC containers / Entity Framework
            EntityFrameworkConfiguration.ConfigureService(services, Configuration);
            IocContainerConfiguration.ConfigureService(services, Configuration);
        }
Beispiel #6
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // IdentityServerConfiguration
            IdentityServerApiConfiguration.ConfigureService(services, "MovieArchive_API");

            // ApiVersionConfiguration
            ApiVersionConfiguration.ConfigureService(services, ApiVersionConfig);

            // Swagger API documentation
            SwaggerConfiguration.ConfigureService(services, SwaggerConfig);

            // Cors Orgin
            CorsOrginConfiguration.ConfigureService(services);

            services.AddHealthChecks();
            services.AddControllers();
        }
Beispiel #7
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
            services.AddAutoMapper(typeof(MappingProfile));

            ConfigurationOptions.ConfigureService(services, Configuration);

            // IOC containers
            IocContainerConfiguration.ConfigureService(services, Configuration);

            // JWT containers
            JwtConfiguration.ConfigureService(services, Configuration);

            // Swagger API documentation
            SwaggerConfiguration.ConfigureService(services);

            // Cors Orgin
            CorsOrginConfiguration.ConfigureService(services);
        }