first commit
This commit is contained in:
@ -0,0 +1,224 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Cors;
|
||||
using Microsoft.AspNetCore.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using KonSoft.Admin.EntityFrameworkCore;
|
||||
using KonSoft.Admin.MultiTenancy;
|
||||
using Volo.Abp.AspNetCore.Mvc.UI.Theme.LeptonXLite;
|
||||
using Volo.Abp.AspNetCore.Mvc.UI.Theme.LeptonXLite.Bundling;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using OpenIddict.Validation.AspNetCore;
|
||||
using Volo.Abp;
|
||||
using Volo.Abp.Account;
|
||||
using Volo.Abp.Account.Web;
|
||||
using Volo.Abp.AspNetCore.MultiTenancy;
|
||||
using Volo.Abp.AspNetCore.Mvc;
|
||||
using Volo.Abp.AspNetCore.Mvc.UI.Bundling;
|
||||
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared;
|
||||
using Volo.Abp.AspNetCore.Serilog;
|
||||
using Volo.Abp.Autofac;
|
||||
using Volo.Abp.Localization;
|
||||
using Volo.Abp.Modularity;
|
||||
using Volo.Abp.Security.Claims;
|
||||
using Volo.Abp.Swashbuckle;
|
||||
using Volo.Abp.UI.Navigation.Urls;
|
||||
using Volo.Abp.VirtualFileSystem;
|
||||
|
||||
namespace KonSoft.Admin;
|
||||
|
||||
[DependsOn(
|
||||
typeof(AdminHttpApiModule),
|
||||
typeof(AbpAutofacModule),
|
||||
typeof(AbpAspNetCoreMultiTenancyModule),
|
||||
typeof(AdminApplicationModule),
|
||||
typeof(AdminEntityFrameworkCoreModule),
|
||||
typeof(AbpAspNetCoreMvcUiLeptonXLiteThemeModule),
|
||||
typeof(AbpAccountWebOpenIddictModule),
|
||||
typeof(AbpAspNetCoreSerilogModule),
|
||||
typeof(AbpSwashbuckleModule)
|
||||
)]
|
||||
public class AdminHttpApiHostModule : AbpModule
|
||||
{
|
||||
public override void PreConfigureServices(ServiceConfigurationContext context)
|
||||
{
|
||||
PreConfigure<OpenIddictBuilder>(builder =>
|
||||
{
|
||||
builder.AddValidation(options =>
|
||||
{
|
||||
options.AddAudiences("Admin");
|
||||
options.UseLocalServer();
|
||||
options.UseAspNetCore();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public override void ConfigureServices(ServiceConfigurationContext context)
|
||||
{
|
||||
var configuration = context.Services.GetConfiguration();
|
||||
var hostingEnvironment = context.Services.GetHostingEnvironment();
|
||||
|
||||
ConfigureAuthentication(context);
|
||||
ConfigureBundles();
|
||||
ConfigureUrls(configuration);
|
||||
ConfigureConventionalControllers();
|
||||
ConfigureVirtualFileSystem(context);
|
||||
ConfigureCors(context, configuration);
|
||||
ConfigureSwaggerServices(context, configuration);
|
||||
}
|
||||
|
||||
private void ConfigureAuthentication(ServiceConfigurationContext context)
|
||||
{
|
||||
context.Services.ForwardIdentityAuthenticationForBearer(OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme);
|
||||
context.Services.Configure<AbpClaimsPrincipalFactoryOptions>(options =>
|
||||
{
|
||||
options.IsDynamicClaimsEnabled = true;
|
||||
});
|
||||
}
|
||||
|
||||
private void ConfigureBundles()
|
||||
{
|
||||
Configure<AbpBundlingOptions>(options =>
|
||||
{
|
||||
options.StyleBundles.Configure(
|
||||
LeptonXLiteThemeBundles.Styles.Global,
|
||||
bundle =>
|
||||
{
|
||||
bundle.AddFiles("/global-styles.css");
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
private void ConfigureUrls(IConfiguration configuration)
|
||||
{
|
||||
Configure<AppUrlOptions>(options =>
|
||||
{
|
||||
options.Applications["MVC"].RootUrl = configuration["App:SelfUrl"];
|
||||
options.RedirectAllowedUrls.AddRange(configuration["App:RedirectAllowedUrls"]?.Split(',') ?? Array.Empty<string>());
|
||||
|
||||
options.Applications["Angular"].RootUrl = configuration["App:ClientUrl"];
|
||||
options.Applications["Angular"].Urls[AccountUrlNames.PasswordReset] = "account/reset-password";
|
||||
});
|
||||
}
|
||||
|
||||
private void ConfigureVirtualFileSystem(ServiceConfigurationContext context)
|
||||
{
|
||||
var hostingEnvironment = context.Services.GetHostingEnvironment();
|
||||
|
||||
if (hostingEnvironment.IsDevelopment())
|
||||
{
|
||||
Configure<AbpVirtualFileSystemOptions>(options =>
|
||||
{
|
||||
options.FileSets.ReplaceEmbeddedByPhysical<AdminDomainSharedModule>(
|
||||
Path.Combine(hostingEnvironment.ContentRootPath,
|
||||
$"..{Path.DirectorySeparatorChar}KonSoft.Admin.Domain.Shared"));
|
||||
options.FileSets.ReplaceEmbeddedByPhysical<AdminDomainModule>(
|
||||
Path.Combine(hostingEnvironment.ContentRootPath,
|
||||
$"..{Path.DirectorySeparatorChar}KonSoft.Admin.Domain"));
|
||||
options.FileSets.ReplaceEmbeddedByPhysical<AdminApplicationContractsModule>(
|
||||
Path.Combine(hostingEnvironment.ContentRootPath,
|
||||
$"..{Path.DirectorySeparatorChar}KonSoft.Admin.Application.Contracts"));
|
||||
options.FileSets.ReplaceEmbeddedByPhysical<AdminApplicationModule>(
|
||||
Path.Combine(hostingEnvironment.ContentRootPath,
|
||||
$"..{Path.DirectorySeparatorChar}KonSoft.Admin.Application"));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void ConfigureConventionalControllers()
|
||||
{
|
||||
Configure<AbpAspNetCoreMvcOptions>(options =>
|
||||
{
|
||||
options.ConventionalControllers.Create(typeof(AdminApplicationModule).Assembly);
|
||||
});
|
||||
}
|
||||
|
||||
private static void ConfigureSwaggerServices(ServiceConfigurationContext context, IConfiguration configuration)
|
||||
{
|
||||
context.Services.AddAbpSwaggerGenWithOAuth(
|
||||
configuration["AuthServer:Authority"]!,
|
||||
new Dictionary<string, string>
|
||||
{
|
||||
{"Admin", "Admin API"}
|
||||
},
|
||||
options =>
|
||||
{
|
||||
options.SwaggerDoc("v1", new OpenApiInfo { Title = "Admin API", Version = "v1" });
|
||||
options.DocInclusionPredicate((docName, description) => true);
|
||||
options.CustomSchemaIds(type => type.FullName);
|
||||
});
|
||||
}
|
||||
|
||||
private void ConfigureCors(ServiceConfigurationContext context, IConfiguration configuration)
|
||||
{
|
||||
context.Services.AddCors(options =>
|
||||
{
|
||||
options.AddDefaultPolicy(builder =>
|
||||
{
|
||||
builder
|
||||
.WithOrigins(configuration["App:CorsOrigins"]?
|
||||
.Split(",", StringSplitOptions.RemoveEmptyEntries)
|
||||
.Select(o => o.RemovePostFix("/"))
|
||||
.ToArray() ?? Array.Empty<string>())
|
||||
.WithAbpExposedHeaders()
|
||||
.SetIsOriginAllowedToAllowWildcardSubdomains()
|
||||
.AllowAnyHeader()
|
||||
.AllowAnyMethod()
|
||||
.AllowCredentials();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public override void OnApplicationInitialization(ApplicationInitializationContext context)
|
||||
{
|
||||
var app = context.GetApplicationBuilder();
|
||||
var env = context.GetEnvironment();
|
||||
|
||||
if (env.IsDevelopment())
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
}
|
||||
|
||||
app.UseAbpRequestLocalization();
|
||||
|
||||
if (!env.IsDevelopment())
|
||||
{
|
||||
app.UseErrorPage();
|
||||
}
|
||||
|
||||
app.UseCorrelationId();
|
||||
app.UseStaticFiles();
|
||||
app.UseRouting();
|
||||
app.UseCors();
|
||||
app.UseAuthentication();
|
||||
app.UseAbpOpenIddictValidation();
|
||||
|
||||
if (MultiTenancyConsts.IsEnabled)
|
||||
{
|
||||
app.UseMultiTenancy();
|
||||
}
|
||||
app.UseUnitOfWork();
|
||||
app.UseDynamicClaims();
|
||||
app.UseAuthorization();
|
||||
|
||||
app.UseSwagger();
|
||||
app.UseAbpSwaggerUI(c =>
|
||||
{
|
||||
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Admin API");
|
||||
|
||||
var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>();
|
||||
c.OAuthClientId(configuration["AuthServer:SwaggerClientId"]);
|
||||
c.OAuthScopes("Admin");
|
||||
});
|
||||
|
||||
app.UseAuditing();
|
||||
app.UseAbpSerilogEnrichers();
|
||||
app.UseConfiguredEndpoints();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user