using System.Text; using Microsoft.EntityFrameworkCore; using Microsoft.IdentityModel.Tokens; using OpenIddict.Abstractions; using OpenIddict.Demo.Server.EntityFrameworkCore; using OpenIddict.Server.AspNetCore; 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.Theme.Basic; using Volo.Abp.Autofac; using Volo.Abp.Data; using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore.SqlServer; using Volo.Abp.FeatureManagement; using Volo.Abp.FeatureManagement.EntityFrameworkCore; using Volo.Abp.Identity; using Volo.Abp.Identity.EntityFrameworkCore; using Volo.Abp.Identity.Web; using Volo.Abp.Modularity; using Volo.Abp.MultiTenancy; using Volo.Abp.OpenIddict; using Volo.Abp.OpenIddict.EntityFrameworkCore; using Volo.Abp.OpenIddict.WildcardDomains; using Volo.Abp.PermissionManagement; using Volo.Abp.PermissionManagement.EntityFrameworkCore; using Volo.Abp.PermissionManagement.HttpApi; using Volo.Abp.PermissionManagement.Identity; using Volo.Abp.SettingManagement; using Volo.Abp.SettingManagement.EntityFrameworkCore; using Volo.Abp.SettingManagement.Web; using Volo.Abp.TenantManagement; using Volo.Abp.TenantManagement.EntityFrameworkCore; using Volo.Abp.TenantManagement.Web; namespace OpenIddict.Demo.Server; [DependsOn( typeof(AbpAspNetCoreMvcModule), typeof(AbpAutofacModule), typeof(AbpEntityFrameworkCoreSqlServerModule), typeof(AbpAspNetCoreMvcUiBasicThemeModule), typeof(AbpAspNetCoreMultiTenancyModule), typeof(AbpOpenIddictAspNetCoreModule), typeof(AbpOpenIddictEntityFrameworkCoreModule), typeof(AbpAccountApplicationModule), typeof(AbpAccountHttpApiModule), typeof(AbpAccountWebOpenIddictModule), typeof(AbpTenantManagementApplicationModule), typeof(AbpTenantManagementHttpApiModule), typeof(AbpTenantManagementEntityFrameworkCoreModule), typeof(AbpTenantManagementWebModule), typeof(AbpPermissionManagementDomainIdentityModule), typeof(AbpIdentityApplicationModule), typeof(AbpIdentityHttpApiModule), typeof(AbpIdentityEntityFrameworkCoreModule), typeof(AbpIdentityWebModule), typeof(AbpPermissionManagementApplicationModule), typeof(AbpPermissionManagementHttpApiModule), typeof(AbpPermissionManagementEntityFrameworkCoreModule), typeof(AbpFeatureManagementApplicationModule), typeof(AbpFeatureManagementEntityFrameworkCoreModule), typeof(AbpFeatureManagementHttpApiModule), typeof(AbpFeatureManagementWebModule), typeof(AbpSettingManagementApplicationModule), typeof(AbpSettingManagementEntityFrameworkCoreModule), typeof(AbpSettingManagementHttpApiModule), typeof(AbpSettingManagementWebModule) )] public class OpenIddictServerModule : AbpModule { public override void PreConfigureServices(ServiceConfigurationContext context) { PreConfigure(builder => { //https://documentation.openiddict.com/configuration/token-formats.html#disabling-jwt-access-token-encryption //https://documentation.openiddict.com/configuration/encryption-and-signing-credentials.html builder.AddSigningKey(new SymmetricSecurityKey(Encoding.UTF8.GetBytes("Abp_OpenIddict_Demo_C40DBB176E78"))); builder.AddEncryptionKey(new SymmetricSecurityKey(Encoding.UTF8.GetBytes("Abp_OpenIddict_Demo_87E33FC57D80"))); }); PreConfigure(options => { options.EnableWildcardDomainSupport = true; options.WildcardDomainsFormat.Add("https://{0}.abp.io/signin-oidc"); }); PreConfigure(builder => { builder.AddValidation(options => { options.AddAudiences("AbpAPIResource"); options.UseLocalServer(); options.UseAspNetCore(); }); }); } public override void ConfigureServices(ServiceConfigurationContext context) { context.Services.ConfigureApplicationCookie(options => { options.ForwardDefaultSelector = ctx => ctx.Request.Path.StartsWithSegments("/api") ? OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme : null; }); Configure(options => { options.AddDevelopmentEncryptionAndSigningCertificate = false; }); context.Services.AddAbpDbContext(options => { options.AddDefaultRepositories(includeAllEntities: true); }); Configure(options => { options.UseSqlServer(); }); Configure(options => { options.IsEnabled = true; }); } public async override Task OnApplicationInitializationAsync(ApplicationInitializationContext context) { var dbContext = context.ServiceProvider .GetRequiredService(); if ((await dbContext.Database.GetPendingMigrationsAsync()).Any()) { await dbContext.Database.MigrateAsync(); await context.ServiceProvider .GetRequiredService() .SeedAsync(); } var tenantManager = context.ServiceProvider.GetRequiredService(); var tenantRepository = context.ServiceProvider.GetRequiredService(); if (await tenantRepository.FindByNameAsync("Default") == null) { var tenant = await tenantRepository.InsertAsync( await tenantManager.CreateAsync("Default")); await context.ServiceProvider .GetRequiredService() .SeedAsync(tenant.Id); } } }