* Added Authorization which is not working
This commit is contained in:
@@ -12,6 +12,8 @@ using OrdersManagementDataModel;
|
||||
using OrdersManagementDataModel.Services;
|
||||
using SytelineSaAppEfDataModel;
|
||||
using SytelineSaAppEfDataModel.Services;
|
||||
using NSwag;
|
||||
using NSwag.Generation.Processors.Security;
|
||||
using FaKrosnoMappingProfile = FaKrosnoEfDataModel.MappingProfile;
|
||||
using SytelineSaAppMappingProfile = SytelineSaAppEfDataModel.MappingProfile;
|
||||
using OrdersManagementMappingProfile = OrdersManagementDataModel.MappingProfile;
|
||||
@@ -30,12 +32,43 @@ builder.Services.Configure<JobSettingsModel>(builder.Configuration.GetSection("J
|
||||
|
||||
builder.WebHost.UseUrls("http://*:5001");
|
||||
|
||||
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
||||
.AddJwtBearer(options =>
|
||||
{
|
||||
options.TokenValidationParameters = new TokenValidationParameters
|
||||
{
|
||||
ValidateIssuer = true,
|
||||
ValidateAudience = true,
|
||||
ValidateLifetime = true,
|
||||
ValidateIssuerSigningKey = true,
|
||||
ValidIssuer = builder.Configuration["Jwt:Issuer"],
|
||||
ValidAudience = builder.Configuration["Jwt:Audience"],
|
||||
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(builder.Configuration["Jwt:Key"] ?? string.Empty))
|
||||
};
|
||||
});
|
||||
|
||||
builder.Services.AddControllers();
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
|
||||
// Konfiguracja NSwag z obsługą Bearer Token
|
||||
builder.Services.AddOpenApiDocument(config =>
|
||||
{
|
||||
config.Title = "FaKrosnoApi";
|
||||
config.Version = "v1";
|
||||
|
||||
// Dodaj definicję zabezpieczeń Bearer Token
|
||||
config.AddSecurity("Bearer", new OpenApiSecurityScheme
|
||||
{
|
||||
Name = "Authorization",
|
||||
Type = OpenApiSecuritySchemeType.Http,
|
||||
Scheme = "Bearer",
|
||||
BearerFormat = "JWT",
|
||||
In = OpenApiSecurityApiKeyLocation.Header,
|
||||
Description = "Wprowadź token JWT w formacie: Bearer {token}"
|
||||
});
|
||||
|
||||
// Zastosuj zabezpieczenia globalnie
|
||||
config.OperationProcessors.Add(new OperationSecurityScopeProcessor("Bearer"));
|
||||
});
|
||||
|
||||
builder.Services.AddHangfire(config => config
|
||||
@@ -52,29 +85,9 @@ builder.Services.AddHangfire(config => config
|
||||
}));
|
||||
builder.Services.AddHangfireServer();
|
||||
|
||||
// Configure AutoMapper
|
||||
builder.Services.AddAutoMapper(typeof(FaKrosnoMappingProfile), typeof(SytelineSaAppMappingProfile),
|
||||
typeof(OrdersManagementMappingProfile));
|
||||
|
||||
// Configure JWT Authentication
|
||||
builder.Services.AddAuthentication(options =>
|
||||
{
|
||||
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||
}).AddJwtBearer(options =>
|
||||
{
|
||||
options.TokenValidationParameters = new TokenValidationParameters
|
||||
{
|
||||
ValidateIssuer = true,
|
||||
ValidateAudience = true,
|
||||
ValidateLifetime = true,
|
||||
ValidateIssuerSigningKey = true,
|
||||
ValidIssuer = builder.Configuration["Jwt:Issuer"],
|
||||
ValidAudience = builder.Configuration["Jwt:Audience"],
|
||||
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(builder.Configuration["Jwt:Key"]))
|
||||
};
|
||||
});
|
||||
|
||||
builder.Services.AddScoped<IScheduleOrderService, ScheduleOrderService>();
|
||||
builder.Services.AddScoped<IScheduleOrderDetailsService, ScheduleOrderDetailsService>();
|
||||
builder.Services.AddScoped<IEdiCustomerOrderService, EdiCustomerOrderService>();
|
||||
@@ -104,11 +117,4 @@ app.MapControllers();
|
||||
|
||||
app.UseHangfireDashboard();
|
||||
|
||||
// var scopeFactory = app.Services.GetRequiredService<IServiceScopeFactory>();
|
||||
// using (var scope = scopeFactory.CreateScope())
|
||||
// {
|
||||
// var scheduledJob = scope.ServiceProvider.GetRequiredService<IScheduleJobService>();
|
||||
// scheduledJob.Start();
|
||||
// }
|
||||
|
||||
app.Run();
|
||||
app.Run();
|
||||
|
||||
Reference in New Issue
Block a user