fix offline token
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using Dlhis.Middle.Request;
|
using Dlhis.Middle.Request;
|
||||||
|
using Dlhis.Middle.Services;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
@@ -14,11 +15,13 @@ public class OAuth2Controller : ControllerBase
|
|||||||
{
|
{
|
||||||
private readonly IHttpClientFactory _httpClientFactory;
|
private readonly IHttpClientFactory _httpClientFactory;
|
||||||
private readonly IConfiguration _configuration;
|
private readonly IConfiguration _configuration;
|
||||||
|
private readonly IHealthCheckService _healthCheckService;
|
||||||
|
|
||||||
public OAuth2Controller(IHttpClientFactory httpClientFactory, IConfiguration configuration)
|
public OAuth2Controller(IHttpClientFactory httpClientFactory, IConfiguration configuration, IHealthCheckService healthCheckService)
|
||||||
{
|
{
|
||||||
_httpClientFactory = httpClientFactory;
|
_httpClientFactory = httpClientFactory;
|
||||||
_configuration = configuration;
|
_configuration = configuration;
|
||||||
|
_healthCheckService = healthCheckService;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("clientgrant")]
|
[HttpPost("clientgrant")]
|
||||||
@@ -27,14 +30,7 @@ public class OAuth2Controller : ControllerBase
|
|||||||
var authority = _configuration.GetSection("Authority").Value;
|
var authority = _configuration.GetSection("Authority").Value;
|
||||||
var httpClient = _httpClientFactory.CreateClient("face");
|
var httpClient = _httpClientFactory.CreateClient("face");
|
||||||
|
|
||||||
try
|
if (_healthCheckService.GetIsOffline())
|
||||||
{
|
|
||||||
var content = new StringContent($"grant_type=client_credentials&client_id={request.ClientId}&client_secret={request.ClientSecret}&scope={request.Scope}", Encoding.UTF8, "application/x-www-form-urlencoded");
|
|
||||||
var response = await httpClient.PostAsync($"{authority}/oauth2/connect/token", content);
|
|
||||||
var result = await response.Content.ReadAsStringAsync();
|
|
||||||
return JObject.Parse(result);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
{
|
||||||
return new
|
return new
|
||||||
{
|
{
|
||||||
@@ -44,5 +40,10 @@ public class OAuth2Controller : ControllerBase
|
|||||||
scope = "yikatong"
|
scope = "yikatong"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var content = new StringContent($"grant_type=client_credentials&client_id={request.ClientId}&client_secret={request.ClientSecret}&scope={request.Scope}", Encoding.UTF8, "application/x-www-form-urlencoded");
|
||||||
|
var response = await httpClient.PostAsync($"{authority}/oauth2/connect/token", content);
|
||||||
|
var result = await response.Content.ReadAsStringAsync();
|
||||||
|
return JObject.Parse(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user