remove 移除user项目

This commit is contained in:
2024-06-28 11:58:37 +08:00
parent 9daa92d849
commit 0214309e64
10 changed files with 4 additions and 195 deletions

View File

@@ -0,0 +1,38 @@
using System.Text;
using Dlhis.Sys.Identity.Request;
using Kurisu.AspNetCore.Authentication.Options;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Newtonsoft.Json.Linq;
namespace Dlhis.Sys.Identity.Controllers;
/// <summary>
/// OAuth2认证
/// </summary>
[Route("api/[controller]")]
[ApiController]
public class OAuth2Controller : ControllerBase
{
private readonly IHttpClientFactory _httpClientFactory;
private readonly IOptions<IdentityServerOptions> _identityServerOption;
public OAuth2Controller(IHttpClientFactory httpClientFactory, IOptions<IdentityServerOptions> identityServerOption)
{
_httpClientFactory = httpClientFactory;
_identityServerOption = identityServerOption;
}
[HttpPost("clientgrant")]
public async Task<object> ClientGrant(ClientGrantRequest request)
{
var authority = _identityServerOption.Value.Authority;
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);
}
}

View File

@@ -0,0 +1,10 @@
namespace Dlhis.Sys.Identity.Request;
public class ClientGrantRequest
{
public string ClientId { get; set; }
public string ClientSecret { get; set; }
public string Scope { get; set; } = "yikatong";
}

View File

@@ -0,0 +1,27 @@
using Kurisu.AspNetCore.Startup;
namespace Dlhis.Sys.Packs;
public class OAuth2HttpClientPack : BaseAppPack
{
public override void ConfigureServices(IServiceCollection services)
{
services.AddHttpClient("oauth2", (sp, httpClient) =>
{
if (sp.GetService<IWebHostEnvironment>().IsProduction())
{
httpClient.DefaultRequestHeaders.Add("X-Requested-Internal", "internal");
}
})
.ConfigurePrimaryHttpMessageHandler(() =>
{
var handler = new HttpClientHandler
{
ClientCertificateOptions = ClientCertificateOption.Manual,
ServerCertificateCustomValidationCallback = (_, _, _, _) => true
};
return handler;
});
}
}