Ajustes copia RDLC y variables de entorno.
All checks were successful
Build and Deploy / remote-build-and-deploy (push) Successful in 21m46s

This commit is contained in:
2025-06-18 12:15:41 -03:00
parent d514864986
commit 19ea4b23a0
4 changed files with 65 additions and 9 deletions

View File

@@ -17,4 +17,12 @@
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.9.0" />
</ItemGroup>
<ItemGroup>
<!-- Esto le dice a MSBuild que busque todos los archivos .rdlc -->
<Content Include="Controllers\Reportes\RDLC\**\*.rdlc">
<!-- Esto asegura que los archivos se copien a la carpeta de publicación -->
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>

View File

@@ -93,15 +93,62 @@ builder.Services.AddScoped<IReportesRepository, ReportesRepository>();
// Servicios de Reportes
builder.Services.AddScoped<IReportesService, ReportesService>();
// --- INICIO DE CAMBIOS: Configuración de Autenticación JWT ---
// 1. Obtener la sección de configuración de JWT.
// Esto leerá desde appsettings.json y SOBRESCRIBIRÁ con variables de entorno si existen.
var jwtSection = builder.Configuration.GetSection("JwtSettings");
var jwtKey = jwtSection["Key"];
var jwtIssuer = jwtSection["Issuer"];
var jwtAudience = jwtSection["Audience"];
// 2. Validar que todas las configuraciones necesarias existan.
if (string.IsNullOrEmpty(jwtKey) || string.IsNullOrEmpty(jwtIssuer) || string.IsNullOrEmpty(jwtAudience))
{
throw new InvalidOperationException("La configuración de JWT (Key, Issuer, Audience) no está completa. Verifique appsettings.json o las variables de entorno.");
}
var keyBytes = Encoding.ASCII.GetBytes(jwtKey);
builder.Services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(options =>
{
// Es buena práctica usar HTTPS en producción. Si tu proxy inverso maneja SSL, esto puede ser false.
options.RequireHttpsMetadata = builder.Environment.IsProduction();
options.SaveToken = true;
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuerSigningKey = true,
IssuerSigningKey = new SymmetricSecurityKey(keyBytes),
ValidateIssuer = true,
ValidIssuer = jwtIssuer, // Usar la variable leída de la configuración
ValidateAudience = true,
ValidAudience = jwtAudience, // Usar la variable leída de la configuración
ValidateLifetime = true,
ClockSkew = TimeSpan.Zero
};
});
// --- Configuración de Autenticación JWT ---
var jwtSettings = builder.Configuration.GetSection("Jwt");
/*var jwtSettings = builder.Configuration.GetSection("Jwt");
// Le decimos que busque la clave JWT en la raíz de la configuración (donde están las variables de entorno).
// Si no la encuentra, como respaldo, busca en la sección "Jwt" del appsettings.
//var jwtKey = builder.Configuration["JWT_KEY"] ?? jwtSettings["Key"] ?? throw new ArgumentNullException("JWT_KEY or Jwt:Key not configured");
var jwtKey = jwtSettings["Key"] ?? throw new ArgumentNullException("Jwt:Key", "JWT Key not configured in appsettings.json");
//var jwtKey = jwtSettings["Key"] ?? throw new ArgumentNullException("Jwt:Key", "JWT Key not configured in appsettings.json");
var keyBytes = Encoding.ASCII.GetBytes(jwtKey);
//var keyBytes = Encoding.ASCII.GetBytes(jwtKey);
builder.Services.AddAuthentication(options =>
{
@@ -124,7 +171,7 @@ builder.Services.AddAuthentication(options =>
ValidateLifetime = true,
ClockSkew = TimeSpan.Zero
};
});
});*/
// --- Configuración de Autorización ---
builder.Services.AddAuthorization();
@@ -221,7 +268,7 @@ if (app.Environment.IsDevelopment())
app.UseCors(MyAllowSpecificOrigins);
app.UseAuthentication(); // Debe ir ANTES de UseAuthorization
app.UseAuthentication(); // SIEMPRE ANTES de UseAuthorization
app.UseAuthorization();
app.MapControllers();

View File

@@ -6,10 +6,10 @@
}
},
"Jwt": {
"Key": "badb1a38d221c9e23bcf70958840ca7f5a5dc54f2047dadf7ce45b578b5bc3e2",
"Issuer": "GestionIntegralApi",
"Audience": "GestionIntegralClient",
"Key": "",
"Issuer": "",
"Audience": "",
"DurationInHours": 8
},
"AllowedHosts": "*"
}
}