using System.Net.Http.Headers; using NexusReader.Application.Abstractions.Services; namespace NexusReader.Web.Client.Handlers; public class AuthenticationHeaderHandler : DelegatingHandler { private readonly INativeStorageService _storageService; private const string TokenKey = "nexus_auth_token"; public AuthenticationHeaderHandler(INativeStorageService storageService) { _storageService = storageService; } protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { var tokenResult = await _storageService.GetSecureString(TokenKey); if (tokenResult.IsSuccess && !string.IsNullOrEmpty(tokenResult.Value)) { request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", tokenResult.Value); } return await base.SendAsync(request, cancellationToken); } }