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