FÉLKÉSZ

This commit is contained in:
2025-04-05 18:11:42 +02:00
parent 4951fc0c7a
commit 33232bae75
15 changed files with 404 additions and 72 deletions
@@ -10,6 +10,8 @@ using System.Text;
using System.Threading.Tasks;
using WorkFlowCheck.MAUI.DataLayer;
using WorkFlowCheck.MAUI.Services.Interfaces;
using Android.Provider;
using Android.DeviceLock;
namespace WorkFlowCheck.MAUI.Services
{
@@ -20,6 +22,7 @@ namespace WorkFlowCheck.MAUI.Services
public readonly AppDbContext _dbContext;
public readonly IConfiguration _configuration;
public readonly IMapper _mapper;
private string _deviceId;
public BaseService(HttpClient httpClient, IConfiguration configuration, AppDbContext dbContext, IMapper mapper)
{
@@ -33,6 +36,7 @@ namespace WorkFlowCheck.MAUI.Services
var apiKey = configuration["ApiKey"];
_httpClient.DefaultRequestHeaders.Add("X-Api-Key", apiKey);
_deviceId = GetDeviceId();
}
protected async Task PrepareAuthenticatedRequestAsync()
{
@@ -41,6 +45,20 @@ namespace WorkFlowCheck.MAUI.Services
if (!string.IsNullOrEmpty(jwtToken) && _httpClient != null)
{
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", jwtToken);
_httpClient.DefaultRequestHeaders.Add("DeviceId", _deviceId);
}
}
protected string GetDeviceId()
{
try
{
var context = Android.App.Application.Context;
return Settings.Secure.GetString(context.ContentResolver, Settings.Secure.AndroidId) ?? "NO_ANDROID_DEVICE";
}
catch (Exception ex)
{
Console.WriteLine($"Error retrieving device ID: {ex.Message}");
return "UnknownDevice";
}
}
}