Files
Heimdall/src/Heimdall.Infrastructure/Security/AuthDataService.cs
T
Arnaud Dartois 6978d2e9ab fix(cqrs): implement missing auth service interfaces and fix tests
- Create RolePermissionService (delegates to AppPermissions)
- Create AuthSignInService (wraps SignInManager)
- Create AuthDataService (handles settings, first-user, token revocation)
- Register all new services in Infrastructure DI
- Fix AuthDataService RevokedRefreshToken constructor usage
- All 226 tests passing
2026-07-22 20:05:59 +00:00

42 lines
1.2 KiB
C#

using Heimdall.Application.Services;
using Heimdall.Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
namespace Heimdall.Infrastructure.Security;
public class AuthDataService : IAuthDataService
{
private readonly AppDbContext _db;
public AuthDataService(AppDbContext db)
{
_db = db;
}
public async Task<string?> GetSettingValueAsync(string key, CancellationToken ct)
{
var setting = await _db.AppSettings
.AsNoTracking()
.FirstOrDefaultAsync(s => s.Key == key, ct);
return setting?.Value;
}
public async Task<bool> IsFirstUserAsync(CancellationToken ct)
{
return await _db.Users.AnyAsync(ct);
}
public async Task<bool> IsRefreshTokenRevokedAsync(string tokenHash, CancellationToken ct)
{
return await _db.RevokedRefreshTokens
.AnyAsync(r => r.TokenHash == tokenHash, ct);
}
public async Task RevokeRefreshTokenAsync(string refreshToken, Guid userId, CancellationToken ct)
{
_db.RevokedRefreshTokens.Add(new Heimdall.Domain.Entities.RevokedRefreshToken(
refreshToken, userId, DateTime.UtcNow.AddDays(7)));
await _db.SaveChangesAsync(ct);
}
}