fix 优化本地离线和在线消费处理
This commit is contained in:
36
Src/Dlhis.Middle/Controllers/OAuth2Controller.cs
Normal file
36
Src/Dlhis.Middle/Controllers/OAuth2Controller.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Text;
|
||||
using Dlhis.Middle.Request;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Dlhis.Middle.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// OAuth2认证
|
||||
/// </summary>
|
||||
[Route("api/user/[controller]")]
|
||||
[ApiController]
|
||||
public class OAuth2Controller : ControllerBase
|
||||
{
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
public OAuth2Controller(IHttpClientFactory httpClientFactory, IConfiguration configuration)
|
||||
{
|
||||
_httpClientFactory = httpClientFactory;
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
[HttpPost("clientgrant")]
|
||||
public async Task<object> ClientGrant(ClientGrantRequest request)
|
||||
{
|
||||
var authority = _configuration.GetSection("Authority").Value;
|
||||
|
||||
var httpClient = _httpClientFactory.CreateClient();
|
||||
|
||||
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}/connect/token", content);
|
||||
var result = await response.Content.ReadAsStringAsync();
|
||||
return JObject.Parse(result);
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ namespace Dlhis.Middle.Controllers;
|
||||
/// 订单
|
||||
/// </summary>
|
||||
[Authorize]
|
||||
[Route("api/[controller]")]
|
||||
[Route("api/canteen/[controller]")]
|
||||
[ApiController]
|
||||
public class OrdersController : ControllerBase
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user