From 802c89ffe53b73fbca5086bb80ae23eb14843684 Mon Sep 17 00:00:00 2001 From: dmolinari Date: Tue, 14 Apr 2026 13:17:11 -0300 Subject: [PATCH] feat(app): add IRefreshTokenRepository abstraction --- .../Persistence/IRefreshTokenRepository.cs | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/api/SIGCM2.Application/Abstractions/Persistence/IRefreshTokenRepository.cs diff --git a/src/api/SIGCM2.Application/Abstractions/Persistence/IRefreshTokenRepository.cs b/src/api/SIGCM2.Application/Abstractions/Persistence/IRefreshTokenRepository.cs new file mode 100644 index 0000000..1ad2b01 --- /dev/null +++ b/src/api/SIGCM2.Application/Abstractions/Persistence/IRefreshTokenRepository.cs @@ -0,0 +1,33 @@ +using SIGCM2.Domain.Entities; + +namespace SIGCM2.Application.Abstractions.Persistence; + +public interface IRefreshTokenRepository +{ + /// + /// Finds a refresh token record by its SHA-256 hash. + /// Returns the record even if it is revoked or expired — callers decide what to do. + /// Returns null if no record matches the hash. + /// + Task GetByHashAsync(string tokenHash, CancellationToken ct = default); + + /// Persists a new refresh token and returns its generated Id. + Task AddAsync(RefreshToken token, CancellationToken ct = default); + + /// Marks a single token as revoked and optionally records its successor. + Task RevokeAsync(int id, int? replacedById, DateTime revokedAt, CancellationToken ct = default); + + /// + /// Revokes all active (RevokedAt IS NULL) tokens in a family. + /// Used for chain revocation on reuse detection. + /// Returns the count of rows affected. + /// + Task RevokeFamilyAsync(Guid familyId, DateTime revokedAt, CancellationToken ct = default); + + /// + /// Revokes all active tokens for a user across all families. + /// Used for logout. + /// Returns the count of rows affected. + /// + Task RevokeAllActiveForUserAsync(int usuarioId, DateTime revokedAt, CancellationToken ct = default); +}