Commit inicial: ITCA_API_SAP_WMS (.NET Core 3.1)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
2b82744eb8
168 files changed
+11066
No files matched your search
@@ -0,0 +1,141 @@
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
namespace Net.Business.Services
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
public Startup(IConfiguration configuration)
|
||||
{
|
||||
Configuration = configuration;
|
||||
Net.Data.LocalData.Configure(configuration);
|
||||
}
|
||||
|
||||
public IConfiguration Configuration { get; }
|
||||
|
||||
// This method gets called by the runtime. Use this method to add services to the container.
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.ConfigureCors();
|
||||
services.ConfigureIISIntegration();
|
||||
services.ConfigureSQLConnection();
|
||||
services.ConfigureHttpClientServiceLayer();
|
||||
|
||||
/*Linea con el cual obtenemos datos de la cabecera*/
|
||||
services.AddSingleton<Microsoft.AspNetCore.Http.IHttpContextAccessor, Microsoft.AspNetCore.Http.HttpContextAccessor>();
|
||||
|
||||
//Autenticacion
|
||||
string semilla = Configuration.GetSection("ParametrosTokenConfig").GetValue<string>("Semilla");
|
||||
string emisor = Configuration.GetSection("ParametrosTokenConfig").GetValue<string>("Emisor");
|
||||
string destinatario = Configuration.GetSection("ParametrosTokenConfig").GetValue<string>("Destinatario");
|
||||
|
||||
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(semilla));
|
||||
|
||||
services.AddAuthentication
|
||||
(JwtBearerDefaults.AuthenticationScheme)
|
||||
.AddJwtBearer(opt => {
|
||||
opt.TokenValidationParameters = new TokenValidationParameters
|
||||
{
|
||||
ValidateIssuer = true,
|
||||
ValidateAudience = true,
|
||||
ValidateLifetime = true,
|
||||
ValidIssuer = emisor,
|
||||
ValidAudience = destinatario,
|
||||
IssuerSigningKey = key
|
||||
};
|
||||
|
||||
});
|
||||
services.ConfigureRepositoryWrapper();
|
||||
|
||||
/*De aqui en adelante configuracion de documentacion de nuestra API*/
|
||||
services.AddSwaggerGen(options => {
|
||||
options.SwaggerDoc("ApiSAPWMS", new Microsoft.OpenApi.Models.OpenApiInfo()
|
||||
{
|
||||
Title = "API SAP - WMS",
|
||||
Version = "1",
|
||||
Description = "API Integración SAP / WMS",
|
||||
Contact = new Microsoft.OpenApi.Models.OpenApiContact()
|
||||
{
|
||||
Name = "IT Consultores Asociados",
|
||||
},
|
||||
License = new Microsoft.OpenApi.Models.OpenApiLicense()
|
||||
{
|
||||
Name = "MIT License",
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
var archivoXmlComentarios = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
|
||||
var rutaApiComentarios = Path.Combine(AppContext.BaseDirectory, archivoXmlComentarios);
|
||||
|
||||
options.IncludeXmlComments(rutaApiComentarios);
|
||||
|
||||
/*Primero definir el esquema de seguridad*/
|
||||
options.AddSecurityDefinition("Bearer", new Microsoft.OpenApi.Models.OpenApiSecurityScheme
|
||||
{
|
||||
Description = "Autenticacion JWT (Bearer)",
|
||||
Type = Microsoft.OpenApi.Models.SecuritySchemeType.Http,
|
||||
Scheme = "bearer"
|
||||
});
|
||||
|
||||
options.AddSecurityRequirement(new Microsoft.OpenApi.Models.OpenApiSecurityRequirement {
|
||||
{
|
||||
new Microsoft.OpenApi.Models.OpenApiSecurityScheme
|
||||
{
|
||||
Reference = new Microsoft.OpenApi.Models.OpenApiReference
|
||||
{
|
||||
Id = "Bearer",
|
||||
Type = Microsoft.OpenApi.Models.ReferenceType.SecurityScheme
|
||||
}
|
||||
}, new List<string>()
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
services.AddControllers();
|
||||
}
|
||||
|
||||
// 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.UseHttpsRedirection();
|
||||
|
||||
app.ConfigureExceptionHandler();
|
||||
|
||||
//Linea para documentacion api
|
||||
app.UseSwagger();
|
||||
|
||||
app.UseSwaggerUI(options =>
|
||||
{
|
||||
options.SwaggerEndpoint("swagger/ApiSAPWMS/swagger.json", "API SAP - WMS");
|
||||
options.RoutePrefix = "";
|
||||
});
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
app.UseCors("CorsPolicy");
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapControllers();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user