From 1895db686d2385b23ad3c90b13ba435f77e1bc8b Mon Sep 17 00:00:00 2001 From: wxd <123@qq.com> Date: Sat, 22 Jun 2024 17:52:10 +0800 Subject: [PATCH 1/2] =?UTF-8?q?http=E7=AB=99=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Users/UserAppService.cs | 22 ++++++++++--------- .../WebPeisHttpApiHostModule.cs | 7 +++++- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/Shentun.WebPeis.Application/Users/UserAppService.cs b/src/Shentun.WebPeis.Application/Users/UserAppService.cs index 2d86185..0b4701c 100644 --- a/src/Shentun.WebPeis.Application/Users/UserAppService.cs +++ b/src/Shentun.WebPeis.Application/Users/UserAppService.cs @@ -95,7 +95,7 @@ namespace Shentun.WebPeis.Users [HttpPost("api/app/Users/UpdatePassWord")] public async Task UpdatePassWordAsync(UpdatePassWordDto input) { - + var user = await _userManager.FindByIdAsync(_currentUser.Id.ToString()); if (user != null) { @@ -110,7 +110,7 @@ namespace Shentun.WebPeis.Users await _userManager.AddPasswordAsync(user, input.NewPassWord); } - + } @@ -204,11 +204,13 @@ namespace Shentun.WebPeis.Users protected virtual async Task RequestAuthServerLoginByPasswordAsync(HttpClient client, string username, string password) { - + var AdminUrl = _configuration.GetSection("Kestrel") + .GetSection("Endpoints").GetSection("Http") + .GetSection("Url").Value; var request = new PasswordTokenRequest { - Address = _configuration["AuthServer:Authority"] + "/connect/token", + Address = AdminUrl + "/connect/token", //GrantType = "password", //UserName = username, //Password = password, @@ -216,12 +218,12 @@ namespace Shentun.WebPeis.Users //ClientId = "Peis_App", Parameters = { - {"username",username}, - {"password",password }, - {"scope","WebPeis offline_access" }, - {"client_id","WebPeis_App" }, - {"grant_type","password" } - } + { "username",username}, + { "password",password }, + { "scope","WebPeis offline_access" }, + { "client_id","WebPeis_App" }, + { "grant_type","password" } + } }; //request.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); diff --git a/src/Shentun.WebPeis.HttpApi.Host/WebPeisHttpApiHostModule.cs b/src/Shentun.WebPeis.HttpApi.Host/WebPeisHttpApiHostModule.cs index d2abfd6..475fddb 100644 --- a/src/Shentun.WebPeis.HttpApi.Host/WebPeisHttpApiHostModule.cs +++ b/src/Shentun.WebPeis.HttpApi.Host/WebPeisHttpApiHostModule.cs @@ -182,7 +182,12 @@ public class WebPeisHttpApiHostModule : AbpModule }); - + ///解除https限制 + context.Services.AddOpenIddict() + .AddServer(option => + { + option.UseAspNetCore().DisableTransportSecurityRequirement(); + }); //Configure(configure => From b4df1f344731cb3f89d3b3997266bedcc8f92453 Mon Sep 17 00:00:00 2001 From: wxd <123@qq.com> Date: Sat, 22 Jun 2024 18:19:55 +0800 Subject: [PATCH 2/2] =?UTF-8?q?swagger=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WebPeisHttpApiHostModule.cs | 30 +++++++++++-------- .../appsettings.json | 3 ++ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/Shentun.WebPeis.HttpApi.Host/WebPeisHttpApiHostModule.cs b/src/Shentun.WebPeis.HttpApi.Host/WebPeisHttpApiHostModule.cs index 475fddb..4cd24e7 100644 --- a/src/Shentun.WebPeis.HttpApi.Host/WebPeisHttpApiHostModule.cs +++ b/src/Shentun.WebPeis.HttpApi.Host/WebPeisHttpApiHostModule.cs @@ -459,20 +459,24 @@ public class WebPeisHttpApiHostModule : AbpModule app.UseDynamicClaims(); app.UseAuthorization(); - app.UseSwagger(); - app.UseAbpSwaggerUI(c => + //配置是否启用swagger + var IsSwagger = Convert.ToBoolean(configuration["Swagger:IsEnabled"]); + if (IsSwagger) { - c.SwaggerEndpoint($"/swagger/Work/swagger.json", "业务API"); //分组显示 - c.SwaggerEndpoint($"/swagger/Sys/swagger.json", "底层API"); //分组显示 - //c.SwaggerEndpoint("/swagger/v1/swagger.json", "WebPeis API"); - - var configuration = context.ServiceProvider.GetRequiredService(); - c.OAuthClientId(configuration["AuthServer:SwaggerClientId"]); - c.OAuthClientSecret(configuration["AuthServer:ClientSecret"]); - c.OAuthScopes("WebPeis"); - c.DefaultModelExpandDepth(-1); - }); - + app.UseSwagger(); + app.UseAbpSwaggerUI(c => + { + c.SwaggerEndpoint($"/swagger/Work/swagger.json", "业务API"); //分组显示 + c.SwaggerEndpoint($"/swagger/Sys/swagger.json", "底层API"); //分组显示 + //c.SwaggerEndpoint("/swagger/v1/swagger.json", "WebPeis API"); + + var configuration = context.ServiceProvider.GetRequiredService(); + c.OAuthClientId(configuration["AuthServer:SwaggerClientId"]); + c.OAuthClientSecret(configuration["AuthServer:ClientSecret"]); + c.OAuthScopes("WebPeis"); + c.DefaultModelExpandDepth(-1); + }); + } app.UseAuditing(); app.UseAbpSerilogEnrichers(); app.UseConfiguredEndpoints(); diff --git a/src/Shentun.WebPeis.HttpApi.Host/appsettings.json b/src/Shentun.WebPeis.HttpApi.Host/appsettings.json index 08e0546..495cd34 100644 --- a/src/Shentun.WebPeis.HttpApi.Host/appsettings.json +++ b/src/Shentun.WebPeis.HttpApi.Host/appsettings.json @@ -64,5 +64,8 @@ "BaseAddress": "http://10.1.13.31", "ReportListApiUrl": "http://10.1.13.31/api/report/page", "ReportApiUrl": "http://10.1.13.31/api/report/download" + }, + "Swagger": { + "IsEnabled": true } }