- 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
42 lines
1.2 KiB
C#
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);
|
|
}
|
|
}
|