Files
TenWholeYears.Server/RecNet.Application/Neutrino/NeutrinoAuthorizationService.cs

31 lines
1.2 KiB
C#

using RecNet.Application.Common.Interfaces;
using RecNet.Domain.Repositories;
namespace RecNet.Application.Neutrino;
public class NeutrinoAuthorizationService(
IProfileRepository profileRepository,
ITokenService tokenService) : INeutrinoAuthorizationService
{
public async Task<NeutrinoAuthorizationResult> AuthorizeAsync(
AuthorizeNeutrinoCommand command,
CancellationToken ct = default)
{
if (command.ProfileId == Guid.Empty || string.IsNullOrWhiteSpace(command.AccessToken))
return NeutrinoAuthorizationResult.InvalidParameters();
var tokenVerifyResult = tokenService.VerifyToken(command.AccessToken);
if (!tokenVerifyResult.Succeeded || tokenVerifyResult.ProfileId is null)
return NeutrinoAuthorizationResult.AuthenticationFailed();
if (tokenVerifyResult.ProfileId.Value != command.ProfileId)
return NeutrinoAuthorizationResult.AuthenticationFailed();
var profile = await profileRepository.GetByIdAsync(command.ProfileId, ct);
if (profile is null || profile.IsBanned)
return NeutrinoAuthorizationResult.AuthenticationFailed();
return NeutrinoAuthorizationResult.Success(profile.ProfileId, profile.Name);
}
}