50 lines
1.2 KiB
C#
50 lines
1.2 KiB
C#
using System.Text;
|
|
using Dlhis.Middle.Apis;
|
|
using Dlhis.Middle.Request;
|
|
using Dlhis.Middle.Services;
|
|
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 ICommonApi _commonApi;
|
|
private readonly IHealthCheckService _healthCheckService;
|
|
|
|
public OAuth2Controller(
|
|
ICommonApi commonApi,
|
|
IHealthCheckService healthCheckService)
|
|
{
|
|
_commonApi = commonApi;
|
|
_healthCheckService = healthCheckService;
|
|
}
|
|
|
|
[HttpPost("clientgrant")]
|
|
public async Task<object> ClientGrant(ClientGrantRequest request)
|
|
{
|
|
if (_healthCheckService.GetIsOffline())
|
|
{
|
|
return new
|
|
{
|
|
access_token = "123",
|
|
expires_in = 36000,
|
|
token_type = "Bearer",
|
|
scope = "yikatong"
|
|
};
|
|
}
|
|
|
|
var r = await _commonApi.AuthAsync(new
|
|
{
|
|
request.ClientId,
|
|
request.ClientSecret
|
|
});
|
|
|
|
return r.Data;
|
|
}
|
|
} |