using RecNet.Application.Common.Interfaces; using RecNet.Domain.Repositories; namespace RecNet.Application.Neutrino; public class NeutrinoAuthorizationService( IProfileRepository profileRepository, ITokenService tokenService) : INeutrinoAuthorizationService { public async Task 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) return NeutrinoAuthorizationResult.AuthenticationFailed(); return NeutrinoAuthorizationResult.Success(profile.ProfileId, profile.Name); } }