Ajout de la gestion du Cors Origin

develop
Yanaël GRETTE 4 years ago
parent 2f3e202450
commit 7c889ca1c7
  1. 13
      Startup.cs

@ -16,6 +16,8 @@ namespace EPAServeur
{ {
public class Startup public class Startup
{ {
readonly string AllowCrossClientEPA = "_AllowsCrossOriginClientEPA";
public Startup(IConfiguration configuration) public Startup(IConfiguration configuration)
{ {
Configuration = configuration; Configuration = configuration;
@ -26,6 +28,15 @@ namespace EPAServeur
// This method gets called by the runtime. Use this method to add services to the container. // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
services.AddCors(options =>
{
options.AddPolicy(name: AllowCrossClientEPA,
builder =>
{
builder.WithOrigins("http://localhost:4200").AllowAnyHeader().AllowAnyMethod();
});
});
services.AddControllers(); services.AddControllers();
services.AddAuthentication(BearerAuthenticationHandler.SchemeName) services.AddAuthentication(BearerAuthenticationHandler.SchemeName)
.AddScheme<AuthenticationSchemeOptions, BearerAuthenticationHandler>(BearerAuthenticationHandler.SchemeName, null); .AddScheme<AuthenticationSchemeOptions, BearerAuthenticationHandler>(BearerAuthenticationHandler.SchemeName, null);
@ -70,6 +81,8 @@ namespace EPAServeur
app.UseRouting(); app.UseRouting();
app.UseCors(AllowCrossClientEPA);
app.UseAuthorization(); app.UseAuthorization();
app.UseEndpoints(endpoints => app.UseEndpoints(endpoints =>

Loading…
Cancel
Save