You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
160 lines
5.8 KiB
160 lines
5.8 KiB
using DotNetCore.CAP;
|
|
using LINGYUN.Abp.EventBus.CAP;
|
|
using LINGYUN.Abp.IdentityServer;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Cors;
|
|
using Microsoft.AspNetCore.DataProtection;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using StackExchange.Redis;
|
|
using System;
|
|
using System.Linq;
|
|
using Volo.Abp;
|
|
using Volo.Abp.AspNetCore.MultiTenancy;
|
|
using Volo.Abp.Auditing;
|
|
using Volo.Abp.Autofac;
|
|
using Volo.Abp.Data;
|
|
using Volo.Abp.EntityFrameworkCore;
|
|
using Volo.Abp.EntityFrameworkCore.MySQL;
|
|
using Volo.Abp.Identity.AspNetCore;
|
|
using Volo.Abp.Identity.EntityFrameworkCore;
|
|
using Volo.Abp.IdentityServer.EntityFrameworkCore;
|
|
using Volo.Abp.Localization;
|
|
using Volo.Abp.Modularity;
|
|
using Volo.Abp.MultiTenancy;
|
|
using Volo.Abp.PermissionManagement.EntityFrameworkCore;
|
|
using Volo.Abp.SettingManagement.EntityFrameworkCore;
|
|
using Volo.Abp.TenantManagement.EntityFrameworkCore;
|
|
using Volo.Abp.Threading;
|
|
|
|
namespace AuthServer.Host
|
|
{
|
|
[DependsOn(
|
|
typeof(AbpAspNetCoreMultiTenancyModule),
|
|
typeof(AbpAutofacModule),
|
|
typeof(AbpCAPEventBusModule),
|
|
typeof(AbpIdentityAspNetCoreModule),
|
|
typeof(AbpIdentityServerSmsValidatorModule),
|
|
typeof(AbpEntityFrameworkCoreMySQLModule),
|
|
typeof(AbpIdentityEntityFrameworkCoreModule),
|
|
typeof(AbpIdentityServerEntityFrameworkCoreModule),
|
|
typeof(AbpSettingManagementEntityFrameworkCoreModule),
|
|
typeof(AbpTenantManagementEntityFrameworkCoreModule),
|
|
typeof(AbpPermissionManagementEntityFrameworkCoreModule)
|
|
)]
|
|
public class AuthIdentityServerModule : AbpModule
|
|
{
|
|
private const string DefaultCorsPolicyName = "Default";
|
|
|
|
public override void PreConfigureServices(ServiceConfigurationContext context)
|
|
{
|
|
var configuration = context.Services.GetConfiguration();
|
|
|
|
PreConfigure<CapOptions>(options =>
|
|
{
|
|
options
|
|
.UseMySql(configuration.GetConnectionString("Default"))
|
|
.UseRabbitMQ(rabbitMQOptions =>
|
|
{
|
|
configuration.GetSection("CAP:RabbitMQ").Bind(rabbitMQOptions);
|
|
});
|
|
});
|
|
}
|
|
|
|
public override void ConfigureServices(ServiceConfigurationContext context)
|
|
{
|
|
var hostingEnvironment = context.Services.GetHostingEnvironment();
|
|
var configuration = context.Services.GetConfiguration();
|
|
|
|
Configure<AbpDbContextOptions>(options =>
|
|
{
|
|
options.UseMySQL();
|
|
});
|
|
|
|
Configure<AbpLocalizationOptions>(options =>
|
|
{
|
|
options.Languages.Add(new LanguageInfo("en", "en", "English"));
|
|
options.Languages.Add(new LanguageInfo("zh-Hans", "zh-Hans", "简体中文"));
|
|
});
|
|
|
|
Configure<AbpAuditingOptions>(options =>
|
|
{
|
|
// options.IsEnabledForGetRequests = true;
|
|
options.ApplicationName = "AuthServer";
|
|
});
|
|
|
|
// context.Services.AddAuthentication();
|
|
//context.Services.AddAuthentication()
|
|
// .AddIdentityServerAuthentication(options =>
|
|
// {
|
|
// options.Authority = configuration["AuthServer:Authority"];
|
|
// options.RequireHttpsMetadata = false;
|
|
// options.ApiName = configuration["AuthServer:ApiName"];
|
|
// });
|
|
|
|
Configure<AbpMultiTenancyOptions>(options =>
|
|
{
|
|
options.IsEnabled = true;
|
|
});
|
|
|
|
context.Services.AddStackExchangeRedisCache(options =>
|
|
{
|
|
options.InstanceName = configuration["Redis:InstanceName"];
|
|
options.Configuration = configuration["Redis:Configuration"];
|
|
});
|
|
|
|
if (!hostingEnvironment.IsDevelopment())
|
|
{
|
|
var redis = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]);
|
|
context.Services
|
|
.AddDataProtection()
|
|
.PersistKeysToStackExchangeRedis(redis, "AuthServer-Protection-Keys");
|
|
}
|
|
|
|
context.Services.AddCors(options =>
|
|
{
|
|
options.AddPolicy(DefaultCorsPolicyName, builder =>
|
|
{
|
|
builder
|
|
.WithOrigins(
|
|
configuration["App:CorsOrigins"]
|
|
.Split(",", StringSplitOptions.RemoveEmptyEntries)
|
|
.Select(o => o.RemovePostFix("/"))
|
|
.ToArray()
|
|
)
|
|
.WithAbpExposedHeaders()
|
|
.SetIsOriginAllowedToAllowWildcardSubdomains()
|
|
.AllowAnyHeader()
|
|
.AllowAnyMethod()
|
|
.AllowCredentials();
|
|
});
|
|
});
|
|
}
|
|
|
|
public override void OnApplicationInitialization(ApplicationInitializationContext context)
|
|
{
|
|
var app = context.GetApplicationBuilder();
|
|
|
|
app.UseCorrelationId();
|
|
app.UseVirtualFiles();
|
|
app.UseAbpRequestLocalization();
|
|
app.UseRouting();
|
|
app.UseCors(DefaultCorsPolicyName);
|
|
app.UseMultiTenancy();
|
|
app.UseIdentityServer();
|
|
app.UseAuditing();
|
|
SeedData(context);
|
|
}
|
|
|
|
private void SeedData(ApplicationInitializationContext context)
|
|
{
|
|
AsyncHelper.RunSync(async () =>
|
|
{
|
|
using var scope = context.ServiceProvider.CreateScope();
|
|
await scope.ServiceProvider.GetRequiredService<IDataSeeder>().SeedAsync();
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|