Files
tiku-backend.net/Tiku.Infrastructure/Auth/Sessions/AuthSessionService.cs
xiong 33375a38d7
Some checks failed
ci / release-gate (push) Has been cancelled
refactor(architecture): harden module boundaries
2026-08-04 12:10:36 +08:00

33 lines
1.2 KiB
C#

using Tiku.Application.Auth;
namespace Tiku.Infrastructure.Auth;
internal sealed class AuthSessionService(AuthServiceDependencies dependencies)
: AuthServiceBase(dependencies), IAuthSessionService
{
public async Task<AuthTokenPair> RefreshAsync(
RefreshSessionRequest request,
CancellationToken cancellationToken = default)
{
return await sessionStore.RotateAsync(
request.RefreshToken, request.IpAddress, request.UserAgent, cancellationToken);
}
public async Task LogoutAsync(
LogoutSessionRequest request,
CancellationToken cancellationToken = default)
{
await sessionStore.RevokeFamilyAsync(request.RefreshToken, "logout", cancellationToken);
}
public async Task LogoutAllAsync(Guid userId, CancellationToken cancellationToken = default)
{
var user = await userManager.FindByIdAsync(userId.ToString())
?? throw new InvalidCredentialsException();
var stampResult = await userManager.UpdateSecurityStampAsync(user);
if (!stampResult.Succeeded) throw new InvalidOperationException("Unable to update the user's security stamp.");
await sessionStore.RevokeAllAsync(userId, "logout_all", cancellationToken);
}
}