FÉLKÉSZ
This commit is contained in:
@@ -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";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user