Updated CORS statements Policy

This commit is contained in:
Santhosh S 2023-11-25 23:08:04 -05:00
parent 2ab8f37489
commit 87fa29d9d4
9 changed files with 41 additions and 10 deletions

View File

@ -9,6 +9,10 @@ using System.Reflection;
using System.Text; using System.Text;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
builder.Services.AddCors(p => p.AddPolicy("DamageAppCorsPolicy", build => {
build.WithOrigins("*").AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin();
}));
var authkey = builder.Configuration.GetValue<string>("JwtSettings:securitykey"); var authkey = builder.Configuration.GetValue<string>("JwtSettings:securitykey");
builder.Services.AddAuthentication(item => builder.Services.AddAuthentication(item =>
{ {
@ -85,6 +89,7 @@ if (app.Environment.IsDevelopment())
app.UseSwagger(); app.UseSwagger();
app.UseSwaggerUI(); app.UseSwaggerUI();
} }
app.UseCors("DamageAppCorsPolicy");
app.UseAuthentication(); app.UseAuthentication();
app.UseAuthorization(); app.UseAuthorization();

View File

@ -11,7 +11,11 @@ using System.Reflection;
using System.Text; using System.Text;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
builder.Services.AddCors(p => p.AddPolicy("DamageAppCorsPolicy", build => {
build.WithOrigins("*").AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin();
}));
var authkey = builder.Configuration.GetValue<string>("JwtSettings:securitykey"); var authkey = builder.Configuration.GetValue<string>("JwtSettings:securitykey");
builder.Services.AddAuthentication(item => builder.Services.AddAuthentication(item =>
{ {
item.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; item.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
@ -94,7 +98,7 @@ if (app.Environment.IsDevelopment())
app.UseSwagger(); app.UseSwagger();
app.UseSwaggerUI(); app.UseSwaggerUI();
} }
app.UseCors("DamageAppCorsPolicy");
app.UseAuthentication(); app.UseAuthentication();
app.UseAuthorization(); app.UseAuthorization();
app.UseHttpsRedirection(); app.UseHttpsRedirection();

View File

@ -9,9 +9,12 @@ using System.Text;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
builder.Services.AddCors(p => p.AddPolicy("DamageAppCorsPolicy", build => {
build.WithOrigins("*").AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin();
}));
// Add services to the container. // Add services to the container.
var authkey = builder.Configuration.GetValue<string>("JwtSettings:securitykey"); var authkey = builder.Configuration.GetValue<string>("JwtSettings:securitykey");
builder.Services.AddAuthentication(item => builder.Services.AddAuthentication(item =>
{ {
item.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; item.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
@ -85,7 +88,7 @@ if (app.Environment.IsDevelopment())
app.UseSwagger(); app.UseSwagger();
app.UseSwaggerUI(); app.UseSwaggerUI();
} }
app.UseCors("DamageAppCorsPolicy");
app.UseAuthentication(); app.UseAuthentication();
app.UseAuthorization(); app.UseAuthorization();

View File

@ -9,9 +9,12 @@ using System.Reflection;
using System.Text; using System.Text;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
builder.Services.AddCors(p => p.AddPolicy("DamageAppCorsPolicy", build => {
build.WithOrigins("*").AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin();
}));
// Add services to the container. // Add services to the container.
var authkey = builder.Configuration.GetValue<string>("JwtSettings:securitykey"); var authkey = builder.Configuration.GetValue<string>("JwtSettings:securitykey");
builder.Services.AddAuthentication(item => builder.Services.AddAuthentication(item =>
{ {
item.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; item.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
@ -93,7 +96,7 @@ if (app.Environment.IsDevelopment())
employeesProvider.SeedData(); employeesProvider.SeedData();
} }
} }
app.UseCors("DamageAppCorsPolicy");
app.UseAuthentication(); app.UseAuthentication();
app.UseAuthorization(); app.UseAuthorization();

View File

@ -9,9 +9,12 @@ using System.Reflection;
using System.Text; using System.Text;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
builder.Services.AddCors(p => p.AddPolicy("DamageAppCorsPolicy", build => {
build.WithOrigins("*").AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin();
}));
// Add services to the container. // Add services to the container.
var authkey = builder.Configuration.GetValue<string>("JwtSettings:securitykey"); var authkey = builder.Configuration.GetValue<string>("JwtSettings:securitykey");
builder.Services.AddAuthentication(item => builder.Services.AddAuthentication(item =>
{ {
item.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; item.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
@ -96,7 +99,7 @@ if (app.Environment.IsDevelopment())
regionProvider.SeedData(); regionProvider.SeedData();
} }
} }
app.UseCors("DamageAppCorsPolicy");
app.UseAuthentication(); app.UseAuthentication();
app.UseAuthorization(); app.UseAuthorization();

View File

@ -9,6 +9,9 @@ using System.Reflection;
using System.Text; using System.Text;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
builder.Services.AddCors(p => p.AddPolicy("DamageAppCorsPolicy", build => {
build.WithOrigins("*").AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin();
}));
// Add services to the container. // Add services to the container.
var authkey = builder.Configuration.GetValue<string>("JwtSettings:securitykey"); var authkey = builder.Configuration.GetValue<string>("JwtSettings:securitykey");
builder.Services.AddAuthentication(item => builder.Services.AddAuthentication(item =>
@ -93,6 +96,7 @@ if (app.Environment.IsDevelopment())
questionProvider.SeedData(); questionProvider.SeedData();
} }
} }
app.UseCors("DamageAppCorsPolicy");
app.UseAuthentication(); app.UseAuthentication();
app.UseAuthorization(); app.UseAuthorization();

View File

@ -16,6 +16,9 @@ const int intervalToRetry = 2; //2 seconds
const int maxRetryForCircuitBraker = 5; const int maxRetryForCircuitBraker = 5;
const int intervalForCircuitBraker = 5; //5 seconds const int intervalForCircuitBraker = 5; //5 seconds
builder.Services.AddCors(p => p.AddPolicy("DamageAppCorsPolicy", build => {
build.WithOrigins("*").AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin();
}));
// Add services to the container. // Add services to the container.
var authkey = builder.Configuration.GetValue<string>("JwtSettings:securitykey"); var authkey = builder.Configuration.GetValue<string>("JwtSettings:securitykey");
@ -106,7 +109,7 @@ if (app.Environment.IsDevelopment())
app.UseSwagger(); app.UseSwagger();
app.UseSwaggerUI(); app.UseSwaggerUI();
} }
app.UseCors("DamageAppCorsPolicy");
app.UseAuthentication(); app.UseAuthentication();
app.UseAuthorization(); app.UseAuthorization();

View File

@ -9,7 +9,9 @@ using System.Reflection;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
builder.Services.AddCors(p => p.AddPolicy("DamageAppCorsPolicy", build => {
build.WithOrigins("*").AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin();
}));
// Add services to the container. // Add services to the container.
var authkey = builder.Configuration.GetValue<string>("JwtSettings:securitykey"); var authkey = builder.Configuration.GetValue<string>("JwtSettings:securitykey");
builder.Services.AddAuthentication(item => builder.Services.AddAuthentication(item =>
@ -93,6 +95,7 @@ if (app.Environment.IsDevelopment())
} }
} }
app.UseCors("DamageAppCorsPolicy");
app.UseAuthentication(); app.UseAuthentication();
app.UseAuthorization(); app.UseAuthorization();

View File

@ -17,7 +17,9 @@ const int maxRetryForCircuitBraker = 5;
const int intervalForCircuitBraker = 5; //5 seconds const int intervalForCircuitBraker = 5; //5 seconds
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
builder.Services.AddCors(p => p.AddPolicy("DamageAppCorsPolicy", build => {
build.WithOrigins("*").AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin();
}));
// Add services to the container. // Add services to the container.
var authkey = builder.Configuration.GetValue<string>("JwtSettings:securitykey"); var authkey = builder.Configuration.GetValue<string>("JwtSettings:securitykey");
@ -139,6 +141,7 @@ if (app.Environment.IsDevelopment())
} }
} }
app.UseCors("DamageAppCorsPolicy");
app.UseAuthentication(); app.UseAuthentication();
app.UseAuthorization(); app.UseAuthorization();