* Fixed issue with not authorizing user
This commit is contained in:
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user