|
|
|
|
|
|
|
|
private async Task<string> GetToken() |
|
|
private async Task<string> GetToken() |
|
|
{ |
|
|
{ |
|
|
string token = ""; |
|
|
string token = ""; |
|
|
if (_memoryCache.TryGetValue("JWT", out string t)) |
|
|
|
|
|
|
|
|
if (_memoryCache.TryGetValue("JWT", out string t) && !string.IsNullOrEmpty(t)) |
|
|
{ |
|
|
{ |
|
|
token = t; |
|
|
token = t; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<AuthSuccessResponse> LoginToScreening() |
|
|
public async Task<AuthSuccessResponse> LoginToScreening() |
|
|
{ |
|
|
{ |
|
|
_logger.LogInformation($"Start calling microservice to login"); |
|
|
|
|
|
|
|
|
_logger.LogInformation($"Start calling microservice to login on service {string.Format(_settings.Url + "auth")}"); |
|
|
var httpClient = new HttpClient(); |
|
|
var httpClient = new HttpClient(); |
|
|
var requestUri = new Uri(string.Format(_settings.Url + "auth")); |
|
|
var requestUri = new Uri(string.Format(_settings.Url + "auth")); |
|
|
var httpContent = new StringContent(System.Text.Json.JsonSerializer.Serialize(new AuthMicroserviceRequest |
|
|
var httpContent = new StringContent(System.Text.Json.JsonSerializer.Serialize(new AuthMicroserviceRequest |
|
|
|
|
|
|
|
|
try |
|
|
try |
|
|
{ |
|
|
{ |
|
|
var result = JsonConvert.DeserializeObject<AuthSuccessResponse>(content); |
|
|
var result = JsonConvert.DeserializeObject<AuthSuccessResponse>(content); |
|
|
var expires = result.Expires.Value - DateTime.Now; |
|
|
|
|
|
|
|
|
var expires = result.Expires.Value - DateTime.UtcNow; |
|
|
var cacheEntryOptions = new MemoryCacheEntryOptions() |
|
|
var cacheEntryOptions = new MemoryCacheEntryOptions() |
|
|
.SetSlidingExpiration(TimeSpan.FromSeconds(60)) |
|
|
.SetSlidingExpiration(TimeSpan.FromSeconds(60)) |
|
|
.SetAbsoluteExpiration(expires) |
|
|
.SetAbsoluteExpiration(expires) |