// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc(); services.AddAuthentication(options => { options.DefaultSignInScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }).AddJwtBearer(cfg => { cfg.RequireHttpsMetadata = false; cfg.SaveToken = true; cfg.TokenValidationParameters = new TokenValidationParameters { ValidIssuer = Configuration["token:issuer"], ValidAudience = Configuration["token:audience"], IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["token:key"])), ClockSkew = TimeSpan.Zero // remove delay of token when expire }; }); services.AddAuthorization(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "Zenit Payroll API V1", Version = "v1", Description = "Zenit Payroll Web API written in ASP.NET Core Web API", Contact = new Contact { Name = "Qinisela Molefe", Email = "*****@*****.**", Url = "https://www.codeassembly.co.za" }, }); //// Set the comments path for the Swagger JSON and UI. //var basePath = PlatformServices.Default.Application.ApplicationBasePath; //var xmlPath = Path.Combine(basePath, "dotnetcore-file-upload.xml"); //c.IncludeXmlComments(xmlPath); }); services.AddCors(options => { options.AddPolicy("all_origins", policy => policy.WithOrigins("http://localhost:4300") .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials() ); }); services.AddDbContext <PayrollContext>(options => options.UseNpgsql(Configuration.GetConnectionString("Payroll_DB_Local")), ServiceLifetime.Transient); services.AddTransient <IUnitOfWork, UnitOfWork>(); Adapters.Initialise(services); Builders.Initialise(services); BusinessRules.Initialise(services); Services.Initialise(services); services.AddScoped <LoginProvider>(); }