// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { // if (env.IsDevelopment()) // { // app.UseDeveloperExceptionPage(); // app.UseSwagger(); // app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "API v1")); // } app.UseMiddleware <ExceptionMiddleware>(); app.UseSwagger(); app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "API v1")); app.UseHttpsRedirection(); app.UseRouting(); app.UseCors(Policy => Policy.AllowAnyHeader().AllowAnyMethod().WithOrigins("https://localhost:4200")); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddAutoMapper(typeof(MappingProfiles)); services.AddControllers(); services.AddDbContext <StoreContext>(x => x.UseSqlite(_config.GetConnectionString("DefaultConnection"))); services.AddApplicationServices(); services.AddSwaggerDocumentation(); services.AddCors(opt => { opt.AddPolicy("CorsPolicy", Policy => { Policy.AllowAnyHeader().AllowAnyMethod().WithOrigins("https://localhost:4200"); }); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddDbContext <DataContext>(opt => { opt.UseSqlite(Configuration.GetConnectionString("DefaultConnection")); }); services.AddCors(opt => { opt.AddPolicy("CorsPolicy", Policy => { Policy.AllowAnyHeader().AllowAnyMethod().WithOrigins("http://localhost:3000"); }); }); services.AddMediatR(typeof(List.Handler).Assembly); services.AddControllers(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddDbContext <DataContext>(opt => { opt.UseLazyLoadingProxies(); opt.UseSqlite(Configuration.GetConnectionString("DefaultConnection")); }); services.AddCors(opt => { opt.AddPolicy("CorsPolicy", Policy => { Policy.AllowAnyHeader().AllowAnyMethod().WithOrigins("http://localhost:3000") .AllowCredentials(); }); }); services.AddMediatR(typeof(List.Handler).Assembly); services.AddAutoMapper(typeof(List.Handler)); services.AddSignalR(); services.AddControllers(opt => { var Policy = new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build(); opt.Filters.Add(new AuthorizeFilter(Policy)); }) .AddFluentValidation(cfg => { cfg.RegisterValidatorsFromAssemblyContaining <Create>(); }); var builder = services.AddIdentityCore <AppUser>(); var identityBuilder = new IdentityBuilder(builder.UserType, builder.Services); identityBuilder.AddEntityFrameworkStores <DataContext>(); identityBuilder.AddSignInManager <SignInManager <AppUser> >(); services.AddAuthorization(opt => { opt.AddPolicy("IsActivityHost", policy => { policy.Requirements.Add(new IsHostRequirement()); }); }); services.AddTransient <IAuthorizationHandler, IsHostRequirementHandler>(); services.AddScoped <IJwtGenerator, JwtGenerator>(); services.AddScoped <IUserAccessor, UserAccessor>(); services.AddScoped <IPhotoAccessor, PhotoAccessor>(); services.AddScoped <IProfileReader, ProfileReader>(); services.Configure <CloudinarySettings>(Configuration.GetSection("Cloudinary")); var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["TokenKey"])); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(opt => { opt.TokenValidationParameters = new TokenValidationParameters { ValidateIssuerSigningKey = true, IssuerSigningKey = key, ValidateAudience = false, ValidateIssuer = false }; opt.Events = new JwtBearerEvents { OnMessageReceived = context => { var accessToken = context.Request.Query["access_token"]; var path = context.HttpContext.Request.Path; if (!string.IsNullOrEmpty(accessToken) && (path.StartsWithSegments("/chat"))) { context.Token = accessToken; } return(Task.CompletedTask); } }; }); }