// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddCors(options => { options.AddPolicy("CorsAPI", builder => builder .AllowAnyOrigin() .AllowAnyHeader() .AllowAnyMethod() ); }); services.AddControllers(); services.AddDbContext <ApplicationDbContext>(options => options.UseNpgsql(Configuration.GetConnectionString("PostgreSQL"))); // options.UseSqlServer(Configuration.GetConnectionString("SqlServer"))); services.AddScoped <IAuthRepository, AuthRepository>(); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuerSigningKey = true, IssuerSigningKey = new SymmetricSecurityKey( Encoding.ASCII.GetBytes(Configuration.GetSection("AppSettings:Token").Value)), ValidateIssuer = false, ValidateAudience = false }; }); services.AddAuthorization(config => { config.AddPolicy(Policies.Operator, Policies.OperatorPolicy()); config.AddPolicy(Policies.Driver, Policies.DriverPolicy()); config.AddPolicy(Policies.Client, Policies.ClientPolicy()); }); }