* Fixed issue with not authorizing user
This commit is contained in:
@@ -7,6 +7,7 @@ namespace FaKrosnoApi.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
[Authorize]
|
||||
public class ScheduleOrdersController(IScheduleOrderService service) : Controller
|
||||
{
|
||||
[HttpGet]
|
||||
|
||||
@@ -37,7 +37,6 @@ public class UsersController(IUserService service, IConfiguration configuration)
|
||||
[HttpPost("login")]
|
||||
public async Task<IActionResult> Login([FromBody] AuthenticateRequestModel loginDto)
|
||||
{
|
||||
// Sprawdź poprawność użytkownika (np. w bazie danych)
|
||||
var user = await service.GetByUsername(loginDto.Login);
|
||||
|
||||
if(user == null || !BCrypt.Net.BCrypt.Verify(loginDto.Password, user.PasswordHash))
|
||||
@@ -47,19 +46,19 @@ public class UsersController(IUserService service, IConfiguration configuration)
|
||||
|
||||
var claims = new[]
|
||||
{
|
||||
new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()),
|
||||
new Claim(ClaimTypes.Name, user.Login),
|
||||
new Claim(JwtRegisteredClaimNames.Sub, user.Login),
|
||||
new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString())
|
||||
};
|
||||
|
||||
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(configuration["Jwt:Key"]));
|
||||
var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
|
||||
var credentials = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
|
||||
|
||||
var token = new JwtSecurityToken(
|
||||
issuer: configuration["Jwt:Issuer"],
|
||||
audience: configuration["Jwt:Audience"],
|
||||
claims: claims,
|
||||
expires: DateTime.Now.AddHours(1), // Token ważny przez 1 godzinę
|
||||
signingCredentials: creds);
|
||||
expires: DateTime.Now.AddHours(1),
|
||||
signingCredentials: credentials);
|
||||
|
||||
return Ok(new
|
||||
{
|
||||
|
||||
@@ -43,7 +43,8 @@ builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
||||
ValidateIssuerSigningKey = true,
|
||||
ValidIssuer = builder.Configuration["Jwt:Issuer"],
|
||||
ValidAudience = builder.Configuration["Jwt:Audience"],
|
||||
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(builder.Configuration["Jwt:Key"] ?? string.Empty))
|
||||
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(builder.Configuration["Jwt:Key"] ?? string.Empty)),
|
||||
NameClaimType = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier"
|
||||
};
|
||||
});
|
||||
|
||||
@@ -71,19 +72,19 @@ builder.Services.AddOpenApiDocument(config =>
|
||||
config.OperationProcessors.Add(new OperationSecurityScopeProcessor("Bearer"));
|
||||
});
|
||||
|
||||
builder.Services.AddHangfire(config => config
|
||||
.SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
|
||||
.UseSimpleAssemblyNameTypeSerializer()
|
||||
.UseRecommendedSerializerSettings()
|
||||
.UseSqlServerStorage(builder.Configuration.GetConnectionString("OrdersManagementConnection"), new SqlServerStorageOptions
|
||||
{
|
||||
CommandBatchMaxTimeout = TimeSpan.FromMinutes(5),
|
||||
SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5),
|
||||
QueuePollInterval = TimeSpan.Zero,
|
||||
UseRecommendedIsolationLevel = true,
|
||||
DisableGlobalLocks = true
|
||||
}));
|
||||
builder.Services.AddHangfireServer();
|
||||
// builder.Services.AddHangfire(config => config
|
||||
// .SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
|
||||
// .UseSimpleAssemblyNameTypeSerializer()
|
||||
// .UseRecommendedSerializerSettings()
|
||||
// .UseSqlServerStorage(builder.Configuration.GetConnectionString("OrdersManagementConnection"), new SqlServerStorageOptions
|
||||
// {
|
||||
// CommandBatchMaxTimeout = TimeSpan.FromMinutes(5),
|
||||
// SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5),
|
||||
// QueuePollInterval = TimeSpan.Zero,
|
||||
// UseRecommendedIsolationLevel = true,
|
||||
// DisableGlobalLocks = true
|
||||
// }));
|
||||
// builder.Services.AddHangfireServer();
|
||||
|
||||
builder.Services.AddAutoMapper(typeof(FaKrosnoMappingProfile), typeof(SytelineSaAppMappingProfile),
|
||||
typeof(OrdersManagementMappingProfile));
|
||||
@@ -115,6 +116,6 @@ app.UseAuthorization();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.UseHangfireDashboard();
|
||||
// app.UseHangfireDashboard();
|
||||
|
||||
app.Run();
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
{
|
||||
MenuItems = new List<MenuItem>
|
||||
{
|
||||
new() { Text = "Zamówienia DELFOR", Url = "/", IconCss = "fa-solid fa-landmark" },
|
||||
new() { Text = "Zamówienia DELFOR", Url = "/ScheduleOrders", IconCss = "fa-solid fa-landmark" },
|
||||
new() { Text = "Zamówienia klienta EDI", Url = "/EdiCustomerOrders", IconCss = "fa-solid fa-list-check" },
|
||||
new() { Text = "Zamówienia klienta", Url = "/CustomerOrders", IconCss = "fa-solid fa-database" }
|
||||
};
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
@page "/ScheduleOrder/{ScheduleOrderId:int}"
|
||||
|
||||
@rendermode InteractiveServer
|
||||
@attribute [Authorize]
|
||||
|
||||
@using Microsoft.AspNetCore.Authorization
|
||||
@using Syncfusion.Blazor.Grids
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
@page "/"
|
||||
@page "/ScheduleOrders"
|
||||
|
||||
@attribute [Authorize]
|
||||
|
||||
@using Microsoft.AspNetCore.Authorization
|
||||
@using Microsoft.AspNetCore.Components.Authorization
|
||||
@using Microsoft.IdentityModel.Tokens
|
||||
@using OrdersManagement.Components.Pages.Shared
|
||||
@using Syncfusion.Blazor.Grids
|
||||
|
||||
@inject ScheduleOrderService ScheduleOrderService
|
||||
@inject AuthenticationStateProvider AuthStateProvider
|
||||
@* //@inject AuthTokenHandler TokenHandler *@
|
||||
|
||||
<div class="h-100 d-flex flex-column">
|
||||
<h5>Zamówienia DELFOR</h5>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
@using OrdersManagement.Components.Layout
|
||||
<Router AppAssembly="@typeof(Program).Assembly">
|
||||
<Router AppAssembly="@typeof(Program).Assembly">
|
||||
<Found Context="routeData">
|
||||
<RouteView RouteData="@routeData" DefaultLayout="@typeof(Layout.MainLayout)" />
|
||||
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
|
||||
|
||||
@@ -27,7 +27,8 @@ builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
||||
ValidateIssuerSigningKey = true,
|
||||
ValidIssuer = builder.Configuration["Jwt:Issuer"],
|
||||
ValidAudience = builder.Configuration["Jwt:Audience"],
|
||||
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(builder.Configuration["Jwt:Key"]))
|
||||
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(builder.Configuration["Jwt:Key"] ?? string.Empty)),
|
||||
NameClaimType = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier"
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user