Working on auth
This commit is contained in:
parent
b60c57e19c
commit
247e256d09
@ -0,0 +1,9 @@
|
||||
namespace Liber_Incantamentum.Application.Authentification.DTOs.Request
|
||||
{
|
||||
public class LoginRequestDto
|
||||
{
|
||||
public string? Username { get; set; }
|
||||
public string? Email { get; set; }
|
||||
public required string Password { get; set; }
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,8 @@
|
||||
namespace Liber_Incantamentum.Application.Authentification.DTOs.Request
|
||||
{
|
||||
public class RefreshTokenRequestDto
|
||||
{
|
||||
public Guid UserId { get; set; }
|
||||
public required string RefreshToken { get; set; }
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
namespace Liber_Incantamentum.Application.Authentification.DTOs.Request
|
||||
{
|
||||
public class RegisterRequestDto
|
||||
{
|
||||
public required string Username { get; set; }
|
||||
public required string Email { get; set; }
|
||||
public required string Password { get; set; }
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
namespace Liber_Incantamentum.Application.Authentification.DTOs.Request
|
||||
{
|
||||
public class UserFilterDto
|
||||
{
|
||||
public Guid? Id { get; set; }
|
||||
public string? UserName { get; set; }
|
||||
public string? Email { get; set; }
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
namespace Liber_Incantamentum.Application.Authentification.DTOs.Response
|
||||
{
|
||||
public class AuthResponseDto
|
||||
{
|
||||
public UserResponseDto UserResponse { get; set; } = null!;
|
||||
public string AccessToken { get; set; } = string.Empty;
|
||||
public string Refreshtoken { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
namespace Liber_Incantamentum.Application.Authentification.DTOs.Response
|
||||
{
|
||||
public class UserResponseDto
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public string Username { get; set; } = string.Empty;
|
||||
public string Email { get; set; } = string.Empty;
|
||||
public string Role { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
using Liber_Incantamentum.Application.Authentification.DTOs.Request;
|
||||
using Liber_Incantamentum.Application.Authentification.DTOs.Response;
|
||||
|
||||
namespace Liber_Incantamentum.Application.Authentification.Interfaces
|
||||
{
|
||||
public interface IAuthentificationService
|
||||
{
|
||||
Task<UserResponseDto> RegisterUserAsync(RegisterRequestDto user);
|
||||
Task<IEnumerable<UserResponseDto>> GetAllUsersAsync(UserFilterDto filter);
|
||||
Task<UserResponseDto> LoginUserAsync(LoginRequestDto user);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
using Liber_Incantamentum.Application.Authentification.DTOs.Request;
|
||||
using Liber_Incantamentum.Application.Authentification.DTOs.Response;
|
||||
using Liber_Incantamentum.Domain.Authentification.Entities;
|
||||
|
||||
namespace Liber_Incantamentum.Application.Authentification.Interfaces
|
||||
{
|
||||
public interface ITokenService
|
||||
{
|
||||
Task<AuthResponseDto> GenerateTokensAsync(User user); // génère et stocke refresh token
|
||||
Task<AuthResponseDto?> RefreshTokensAsync(RefreshTokenRequestDto request); // vérifie et renouvelle
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,23 @@
|
||||
using Liber_Incantamentum.Application.Authentification.DTOs.Request;
|
||||
using Liber_Incantamentum.Application.Authentification.DTOs.Response;
|
||||
using Liber_Incantamentum.Application.Authentification.Interfaces;
|
||||
|
||||
namespace Liber_Incantamentum.Application.Authentification.Services.Generals
|
||||
{
|
||||
public class AuthentificationService : IAuthentificationService
|
||||
{
|
||||
public Task<UserResponseDto> RegisterUserAsync(RegisterRequestDto user)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<UserResponseDto> LoginUserAsync(LoginRequestDto user)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public Task<IEnumerable<UserResponseDto>> GetAllUsersAsync(UserFilterDto filter)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
using Liber_Incantamentum.Application.Authentification.DTOs.Request;
|
||||
using Liber_Incantamentum.Application.Authentification.DTOs.Response;
|
||||
using Liber_Incantamentum.Application.Authentification.Interfaces;
|
||||
using Liber_Incantamentum.Domain.Authentification.Entities;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace Liber_Incantamentum.Application.Authentification.Services.Generals
|
||||
{
|
||||
public class TokenService : ITokenService
|
||||
{
|
||||
public Task<AuthResponseDto> GenerateTokensAsync(User user)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<AuthResponseDto?> RefreshTokensAsync(RefreshTokenRequestDto request)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -6,4 +6,14 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Authentification\Exceptions\" />
|
||||
<Folder Include="Authentification\Services\Mappings\" />
|
||||
<Folder Include="Authentification\Services\Validations\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\LiberIncantamentum.Domain\Liber_Incantamentum.Domain.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@ -0,0 +1,13 @@
|
||||
namespace Liber_Incantamentum.Domain.Authentification.Entities
|
||||
{
|
||||
public class RefreshToken
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public required string Token { get; set; }
|
||||
public DateTime ExpiresAt { get; set; }
|
||||
public bool IsRevoked { get; set; }
|
||||
|
||||
public Guid UserId { get; set; }
|
||||
public User User { get; set; } = null!;
|
||||
}
|
||||
}
|
||||
13
LiberIncantamentum.Domain/Authentification/Entities/User.cs
Normal file
13
LiberIncantamentum.Domain/Authentification/Entities/User.cs
Normal file
@ -0,0 +1,13 @@
|
||||
namespace Liber_Incantamentum.Domain.Authentification.Entities
|
||||
{
|
||||
public class User
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public string Username { get; set; } = string.Empty;
|
||||
public string Email { get; set; } = string.Empty;
|
||||
public string PasswordHash { get; set; } = string.Empty;
|
||||
public string Role { get; set; } = string.Empty;
|
||||
public string? RefreshToken { get; set; }
|
||||
public DateTime? RefreshTokenExpiryTime { get; set; }
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
namespace Liber_Incantamentum.Domain.Authentification.Filters
|
||||
{
|
||||
public class UserFilter
|
||||
{
|
||||
public Guid? Id { get; set; }
|
||||
public string? Username { get; set; }
|
||||
public string? Email { get; set; }
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
using Liber_Incantamentum.Domain.Authentification.Entities;
|
||||
using Liber_Incantamentum.Domain.Authentification.Filters;
|
||||
|
||||
namespace Liber_Incantamentum.Domain.Authentification.Repositories
|
||||
{
|
||||
public interface IAuthentificationRepository
|
||||
{
|
||||
Task<User?> ListUsersAsync(UserFilter datasOnUser); // Usage : Récuperer un/des users à partir d'infos
|
||||
Task<bool> AddAsync(User user); // Usage : Créer un user
|
||||
Task<bool> UpdateAsync(User user); // Usage : Mettre à jour un user
|
||||
Task<bool> RemoveUserAsync(Guid id); // Usage : Supprimer un user
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
using Liber_Incantamentum.Domain.Authentification.Entities;
|
||||
|
||||
namespace Liber_Incantamentum.Domain.Authentification.Repositories
|
||||
{
|
||||
public interface IRefreshTokenRepository
|
||||
{
|
||||
Task<RefreshToken?> GetRefreshTokenByIdAsync(string token); //Usage : quand l’utilisateur envoie un refresh token pour obtenir un nouveau JWT, on doit vérifier qu’il est valide et non révoqué.
|
||||
Task<IEnumerable<RefreshToken>> GetRefreshTokenByUserIdAsync(Guid userId); // Usage : afficher les sessions actives d’un utilisateur & révoquer certains tokens manuellement
|
||||
Task AddRefreshTokenAsyn(RefreshToken refreshToken); // Usage : après un login réussi ou une génération de refresh token.
|
||||
Task UpdateRefreshTokenAsync(RefreshToken refreshToken); // Usage : marquer un token comme révoqué (IsRevoked = true) & prolonger la date d’expiration si tu veux étendre la validité
|
||||
Task RevokeAllRefreshTokenAsync(Guid userId); // Usage : l’utilisateur se déconnecte de tous les appareils & le compte a été compromis
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user