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; /// /// OAuth2认证 /// [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 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; } }