|
@ -1,17 +1,8 @@ |
|
|
using System; |
|
|
using System; |
|
|
using System.Collections.Generic; |
|
|
|
|
|
using System.IO; |
|
|
|
|
|
using System.Linq; |
|
|
|
|
|
using System.Net.Http.Headers; |
|
|
using System.Net.Http.Headers; |
|
|
using Microsoft.AspNetCore.Authentication.JwtBearer; |
|
|
|
|
|
using Microsoft.AspNetCore.Builder; |
|
|
|
|
|
using Microsoft.AspNetCore.Cors; |
|
|
|
|
|
using Microsoft.Extensions.Configuration; |
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
using Microsoft.Extensions.DependencyInjection.Extensions; |
|
|
using Microsoft.Extensions.DependencyInjection.Extensions; |
|
|
using Polly; |
|
|
using Polly; |
|
|
using Volo.Abp; |
|
|
|
|
|
using Volo.Abp.AspNetCore.Mvc.AntiForgery; |
|
|
|
|
|
using Volo.Abp.AspNetCore.Mvc.Client; |
|
|
using Volo.Abp.AspNetCore.Mvc.Client; |
|
|
using Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy; |
|
|
using Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy; |
|
|
using Volo.Abp.AspNetCore.Serilog; |
|
|
using Volo.Abp.AspNetCore.Serilog; |
|
@ -22,9 +13,8 @@ using Volo.Abp.Http.Client; |
|
|
using Volo.Abp.Http.Client.Authentication; |
|
|
using Volo.Abp.Http.Client.Authentication; |
|
|
using Volo.Abp.Http.Client.IdentityModel.Web; |
|
|
using Volo.Abp.Http.Client.IdentityModel.Web; |
|
|
using Volo.Abp.Identity; |
|
|
using Volo.Abp.Identity; |
|
|
using Volo.Abp.Localization; |
|
|
|
|
|
using Volo.Abp.Modularity; |
|
|
using Volo.Abp.Modularity; |
|
|
using Volo.Abp.MultiTenancy; |
|
|
using Volo.Abp.SettingManagement.EntityFrameworkCore; |
|
|
using Volo.Abp.Swashbuckle; |
|
|
using Volo.Abp.Swashbuckle; |
|
|
using Volo.Abp.Users; |
|
|
using Volo.Abp.Users; |
|
|
using Win_in.Sfs.Auth; |
|
|
using Win_in.Sfs.Auth; |
|
@ -42,7 +32,9 @@ namespace Win_in.Sfs.Wms.Dashboard.Host; |
|
|
typeof(AbpIdentityHttpApiClientModule), |
|
|
typeof(AbpIdentityHttpApiClientModule), |
|
|
typeof(AbpAspNetCoreMvcClientModule), |
|
|
typeof(AbpAspNetCoreMvcClientModule), |
|
|
typeof(AbpHttpClientIdentityModelWebModule), |
|
|
typeof(AbpHttpClientIdentityModelWebModule), |
|
|
typeof(SharedHostModule) |
|
|
typeof(SharedHostModule), |
|
|
|
|
|
typeof(AbpSettingManagementEntityFrameworkCoreModule) |
|
|
|
|
|
|
|
|
)] |
|
|
)] |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
@ -65,10 +57,8 @@ namespace Win_in.Sfs.Wms.Dashboard.Host; |
|
|
typeof(MessageApplicationContractsModule), |
|
|
typeof(MessageApplicationContractsModule), |
|
|
typeof(AuthApplicationContractsModule) |
|
|
typeof(AuthApplicationContractsModule) |
|
|
)] |
|
|
)] |
|
|
public class DashboardHttpApiHostModule : AbpModule |
|
|
public class DashboardHttpApiHostModule : ModuleBase<DashboardHttpApiHostModule> |
|
|
{ |
|
|
{ |
|
|
private bool _isMultiTenancy = true; |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// 预配置服务
|
|
|
/// 预配置服务
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
@ -120,55 +110,9 @@ public class DashboardHttpApiHostModule : AbpModule |
|
|
context.Services.Replace(ServiceDescriptor.Transient<IRemoteServiceHttpClientAuthenticator, SfsHttpContextIdentityModelRemoteServiceHttpClientAuthenticator>()); |
|
|
context.Services.Replace(ServiceDescriptor.Transient<IRemoteServiceHttpClientAuthenticator, SfsHttpContextIdentityModelRemoteServiceHttpClientAuthenticator>()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
protected override void ConfigureHttpClientProxies() |
|
|
/// 配置服务
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="context"></param>
|
|
|
|
|
|
public override void ConfigureServices(ServiceConfigurationContext context) |
|
|
|
|
|
{ |
|
|
|
|
|
_ = context.Services.GetHostingEnvironment(); |
|
|
|
|
|
var configuration = context.Services.GetConfiguration(); |
|
|
|
|
|
|
|
|
|
|
|
context.SetConsoleTitleOfWebApp("Dashboard.Host"); |
|
|
|
|
|
|
|
|
|
|
|
_isMultiTenancy = Convert.ToBoolean(configuration["IsMultiTenancy"]); |
|
|
|
|
|
|
|
|
|
|
|
context.Services.Configure<AuthenticationOptions>(configuration.GetSection("Authentication")); |
|
|
|
|
|
|
|
|
|
|
|
ConfigureHttpClientProxies(context); |
|
|
|
|
|
|
|
|
|
|
|
ConfigureMultiTenancy(); |
|
|
|
|
|
|
|
|
|
|
|
ConfigureSwaggerServices(context, configuration); |
|
|
|
|
|
|
|
|
|
|
|
ConfigureLocalization(); |
|
|
|
|
|
|
|
|
|
|
|
ConfigureAuthentication(context, configuration); |
|
|
|
|
|
|
|
|
|
|
|
ConfigureCors(context, configuration); |
|
|
|
|
|
|
|
|
|
|
|
ConfigureAntiForgery(); |
|
|
|
|
|
|
|
|
|
|
|
var testConfig = configuration["TestConfig"]; |
|
|
|
|
|
Console.WriteLine("----------------------------"); |
|
|
|
|
|
Console.WriteLine(testConfig); |
|
|
|
|
|
Console.WriteLine("----------------------------"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void ConfigureAntiForgery() |
|
|
|
|
|
{ |
|
|
|
|
|
Configure<AbpAntiForgeryOptions>(options => |
|
|
|
|
|
{ |
|
|
|
|
|
options.TokenCookie.SameSite = Microsoft.AspNetCore.Http.SameSiteMode.Lax; |
|
|
|
|
|
options.TokenCookie.Expiration = TimeSpan.FromDays(365); |
|
|
|
|
|
options.AutoValidateIgnoredHttpMethods.Add("POST"); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static void ConfigureHttpClientProxies(ServiceConfigurationContext context) |
|
|
|
|
|
{ |
|
|
{ |
|
|
_ = context.Services.GetConfiguration(); |
|
|
var context = this.ServiceConfigurationContext; |
|
|
|
|
|
|
|
|
context.Services.AddHttpClientProxies( |
|
|
context.Services.AddHttpClientProxies( |
|
|
typeof(AuthApplicationContractsModule).Assembly, |
|
|
typeof(AuthApplicationContractsModule).Assembly, |
|
|
"Auth" |
|
|
"Auth" |
|
@ -202,145 +146,4 @@ public class DashboardHttpApiHostModule : AbpModule |
|
|
"FileStorage" |
|
|
"FileStorage" |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void ConfigureMultiTenancy() |
|
|
|
|
|
{ |
|
|
|
|
|
Configure<AbpMultiTenancyOptions>(options => { options.IsEnabled = _isMultiTenancy; }); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static void ConfigureCors(ServiceConfigurationContext context, IConfiguration configuration) |
|
|
|
|
|
{ |
|
|
|
|
|
var origins = configuration.GetSection("App:CorsOrigins").Get<string[]>(); |
|
|
|
|
|
|
|
|
|
|
|
context.Services.AddCors(options => |
|
|
|
|
|
{ |
|
|
|
|
|
options.AddDefaultPolicy(builder => |
|
|
|
|
|
{ |
|
|
|
|
|
builder |
|
|
|
|
|
.WithOrigins( |
|
|
|
|
|
origins.Select(o => o.RemovePostFix("/")) |
|
|
|
|
|
.ToArray() |
|
|
|
|
|
) |
|
|
|
|
|
.WithAbpExposedHeaders() |
|
|
|
|
|
.SetIsOriginAllowedToAllowWildcardSubdomains() |
|
|
|
|
|
.AllowAnyHeader() |
|
|
|
|
|
.AllowAnyMethod() |
|
|
|
|
|
.AllowCredentials(); |
|
|
|
|
|
}); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static void ConfigureAuthentication(ServiceConfigurationContext context, IConfiguration configuration) |
|
|
|
|
|
{ |
|
|
|
|
|
//var isAlwaysAllowAuthorization = configuration.GetValue<bool>("AuthServer:AlwaysAllowAuthorization");
|
|
|
|
|
|
//if (isAlwaysAllowAuthorization)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// //绕过授权服务,用于测试
|
|
|
|
|
|
// context.Services.AddAlwaysAllowAuthorization();
|
|
|
|
|
|
//}
|
|
|
|
|
|
//else
|
|
|
|
|
|
//{
|
|
|
|
|
|
// context.Services.AddAuthentication()
|
|
|
|
|
|
// .AddJwtBearer(options =>
|
|
|
|
|
|
// {
|
|
|
|
|
|
// options.Authority = configuration["AuthServer:Authority"];
|
|
|
|
|
|
// options.RequireHttpsMetadata = Convert.ToBoolean(configuration["AuthServer:RequireHttpsMetadata"]);
|
|
|
|
|
|
// options.Audience = "DataExchange";
|
|
|
|
|
|
// options.BackchannelHttpHandler = new HttpClientHandler
|
|
|
|
|
|
// {
|
|
|
|
|
|
// ServerCertificateCustomValidationCallback =
|
|
|
|
|
|
// HttpClientHandler.DangerousAcceptAnyServerCertificateValidator
|
|
|
|
|
|
// };
|
|
|
|
|
|
// });
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
context.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) |
|
|
|
|
|
.AddJwtBearer(options => |
|
|
|
|
|
{ |
|
|
|
|
|
options.Authority = configuration["IdentityClients:Default:Authority"]; |
|
|
|
|
|
options.RequireHttpsMetadata = Convert.ToBoolean(configuration["IdentityClients:Default:RequireHttps"]); |
|
|
|
|
|
options.Audience = configuration["IdentityClients:Default:Scope"]; |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void ConfigureLocalization() |
|
|
|
|
|
{ |
|
|
|
|
|
Configure<AbpLocalizationOptions>(options => |
|
|
|
|
|
{ |
|
|
|
|
|
options.Languages.Add(new LanguageInfo("en", "en", "English")); |
|
|
|
|
|
options.Languages.Add(new LanguageInfo("zh-Hans", "zh-Hans", "简体中文")); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 应用初始化
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="context"></param>
|
|
|
|
|
|
public override void OnApplicationInitialization(ApplicationInitializationContext context) |
|
|
|
|
|
{ |
|
|
|
|
|
var app = context.GetApplicationBuilder(); |
|
|
|
|
|
var env = context.GetEnvironment(); |
|
|
|
|
|
var configuration = context.GetConfiguration(); |
|
|
|
|
|
|
|
|
|
|
|
app.UseDeveloperExceptionPage(); |
|
|
|
|
|
//if (env.IsDevelopment())
|
|
|
|
|
|
//{
|
|
|
|
|
|
// app.UseDeveloperExceptionPage();
|
|
|
|
|
|
//}
|
|
|
|
|
|
//else
|
|
|
|
|
|
//{
|
|
|
|
|
|
// //app.UseErrorPage();
|
|
|
|
|
|
// app.UseHsts();
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
app.UseHttpsRedirection(); |
|
|
|
|
|
app.UseCorrelationId(); |
|
|
|
|
|
app.UseStaticFiles(); |
|
|
|
|
|
app.UseRouting(); |
|
|
|
|
|
app.UseCors(); |
|
|
|
|
|
app.UseAuthentication(); |
|
|
|
|
|
if (_isMultiTenancy) |
|
|
|
|
|
{ |
|
|
|
|
|
app.UseMultiTenancy(); |
|
|
|
|
|
} |
|
|
|
|
|
app.UseAbpRequestLocalization(); |
|
|
|
|
|
app.UseAuthorization(); |
|
|
|
|
|
app.UseSwagger(); |
|
|
|
|
|
app.UseAbpSwaggerUI(options => |
|
|
|
|
|
{ |
|
|
|
|
|
options.SwaggerEndpoint("/swagger/v1/swagger.json", "Dashboard API"); |
|
|
|
|
|
|
|
|
|
|
|
//options.OAuthClientId(configuration["AuthServer:SwaggerClientId"]);
|
|
|
|
|
|
//options.OAuthClientSecret(configuration["AuthServer:SwaggerClientSecret"]);
|
|
|
|
|
|
//options.OAuthScopes("Dashboard");
|
|
|
|
|
|
|
|
|
|
|
|
options.OAuthClientId(configuration["IdentityClients:Default:ClientId"]); |
|
|
|
|
|
options.OAuthClientSecret(configuration["IdentityClients:Default:ClientSecret"]); |
|
|
|
|
|
options.OAuthScopes(configuration["IdentityClients:Default:Scope"]); |
|
|
|
|
|
}); |
|
|
|
|
|
app.UseAuditing(); |
|
|
|
|
|
app.UseAbpSerilogEnrichers(); |
|
|
|
|
|
app.UseConfiguredEndpoints(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static void ConfigureSwaggerServices(ServiceConfigurationContext context, IConfiguration configuration) |
|
|
|
|
|
{ |
|
|
|
|
|
//context.Services.AddAbpSwaggerGenWithOAuth(
|
|
|
|
|
|
// configuration["IdentityClients:Default:Authority"],
|
|
|
|
|
|
// new Dictionary<string, string>
|
|
|
|
|
|
// {
|
|
|
|
|
|
// {"Dashboard", "Dashboard API"}
|
|
|
|
|
|
// },
|
|
|
|
|
|
// options =>
|
|
|
|
|
|
// {
|
|
|
|
|
|
// options.SwaggerDoc("v1", new OpenApiInfo { Title = "Dashboard API", Version = "v1" });
|
|
|
|
|
|
// options.DocInclusionPredicate((docName, description) => true);
|
|
|
|
|
|
// options.CustomSchemaIds(type => type.FullName);
|
|
|
|
|
|
|
|
|
|
|
|
// GetXmlFiles().ForEach(file =>
|
|
|
|
|
|
// {
|
|
|
|
|
|
// options.IncludeXmlComments(file);
|
|
|
|
|
|
// });
|
|
|
|
|
|
// });
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|