Exemplo n.º 1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            JwtModel model = GetJwtSettings();

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

                    ValidateIssuer = false,
                    ValidIssuer    = model.Issuer,

                    ValidateAudience = true,
                    ValidAudience    = model.Audience,

                    ValidateLifetime = true,
                    ClockSkew        = TimeSpan.FromMinutes(model.MinutesToExpiration)
                };
            });

            services.AddSingleton <JwtModel>(model);
            services.AddSingleton <MainDbUser>();


            RepositoryMapper repoMapper    = new RepositoryMapper();
            ServiceMapper    serviceMapper = new ServiceMapper();

            repoMapper.AddMappings(services);
            serviceMapper.AddMappings(services);


            services.AddSingleton <IConfiguration>(Configuration);
            services.AddCors();
            services.AddMvc();
        }