421.1 Abp microserices and Keycloak - chempkovsky/CS82ANGULAR GitHub Wiki
- Only security aspects will be discussed and implemented.
- We are currently using:
- MS Visual studio 22 (Community Edition)
- Volo.Abp.Studio.Cli v.1.1.1 Community Edition
- Volo.Abp.Cli v.9.2.3 Community Edition
- ABP Studio v.1.1.1 Community Edition
- Keycloak v.26.3.0
- Redis v=7.0.15
- Suppose we have a folder
D:\Development - start
cmd.exeand run the commands
d:
cd D:\Development
abp new rupbes.tstapp --template module --database-provider ef --database-management-system SqlServer --create-solution-folder --version 9.2.3 --old
- we ignore all errors
Click to show the code
[09:05:47 ERR] warning [email protected]: This version is no longer supported. Please see https://eslint.org/version-support for other options.
[09:05:47 ERR] warning eslint > @humanwhocodes/[email protected]: Use @eslint/config-array instead
[09:05:47 ERR] warning eslint > @humanwhocodes/config-array > @humanwhocodes/[email protected]: Use @eslint/object-schema instead
[09:05:47 ERR] warning eslint > file-entry-cache > flat-cache > [email protected]: Rimraf versions prior to v4 are no longer supported
[09:05:47 ERR] warning eslint > file-entry-cache > flat-cache > rimraf > [email protected]: Glob versions prior to v9 are no longer supported
[09:05:47 ERR] warning eslint > file-entry-cache > flat-cache > rimraf > glob > [email protected]: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
[09:05:47 ERR] warning karma > [email protected]: Glob versions prior to v9 are no longer supported
[09:05:47 ERR] warning karma > [email protected]: Rimraf versions prior to v4 are no longer supported
[09:05:51 INF] [2/4] Fetching packages...
[09:05:54 INF] [3/4] Linking dependencies...
[09:05:54 ERR] warning "@abp/ng.schematics > @angular/cli > @inquirer/[email protected]" has incorrect peer dependency "@types/node@>=18".
[09:05:54 ERR] warning "@angular-devkit/build-angular > @angular/build > @inquirer/[email protected]" has incorrect peer dependency "@types/node@>=18".
[09:05:54 ERR] warning "@angular-devkit/build-angular > @vitejs/[email protected]" has unmet peer dependency "vite@^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0".
[09:05:54 ERR] warning " > @angular-eslint/[email protected]" has unmet peer dependency "@typescript-eslint/utils@^7.11.0 || ^8.0.0".
[09:05:54 ERR] warning "@angular-eslint/eslint-plugin > @angular-eslint/[email protected]" has unmet peer dependency "@typescript-eslint/utils@^7.11.0 || ^8.0.0".
[09:05:54 ERR] warning " > @angular-eslint/[email protected]" has unmet peer dependency "@typescript-eslint/types@^7.11.0 || ^8.0.0".
[09:05:54 ERR] warning " > @angular-eslint/[email protected]" has unmet peer dependency "@typescript-eslint/utils@^7.11.0 || ^8.0.0".
...
[09:06:29 ERR] warning "@abp/aspnetcore.mvc.ui.theme.basic > @abp/aspnetcore.mvc.ui.theme.shared > @abp/bootstrap > [email protected]" has unmet peer dependency "@popperjs/core@^2.11.8".
[09:06:29 ERR] warning "@abp/aspnetcore.mvc.ui.theme.basic > @abp/aspnetcore.mvc.ui.theme.shared > @abp/jquery-validation-unobtrusive > @abp/jquery-validation > [email protected]" has unmet peer dependency "jquery@^1.7 || ^2.0 || ^
...
[09:06:38 ERR] warning "@abp/aspnetcore.mvc.ui.theme.basic > @abp/aspnetcore.mvc.ui.theme.shared > @abp/bootstrap > [email protected]" has unmet peer dependency "@popperjs/core@^2.11.8".
...
[09:07:01 ERR] Unhandled exception. System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
[09:07:01 ERR] Could not load file or assembly 'Volo.Abp.Core, Version=9.2.3.0, Culture=neutral, PublicKeyToken=null'. The located assembly's manifest definition does not match the assembly reference. (0x80131040)[09:07:01 ERR] Could not load file or assembly 'Volo.Abp.Core, Version=9.2.3.0, Culture=neutral, PublicKeyToken=null'. The located assembly's manifest definition does not match the assembly reference. (0x80131040)[09:07:01 ERR] Could not load file or assembly 'Volo.Abp.Core, Version=9.2.3.0, Culture=neutral, PublicKeyToken=null'. The located assembly's manifest definition does not match the assembly reference. (0x80131040)[09:07:01 ERR] at System.Reflection.RuntimeModule.GetTypes(QCallModule module, ObjectHandleOnStack retTypes)
[09:07:01 ERR] at System.Reflection.RuntimeModule.GetDefinedTypes()
[09:07:01 ERR] at System.Reflection.RuntimeModule.GetTypes()
[09:07:01 ERR] at Volo.Abp.Cli.Bundling.BundlingService.GetStartupModule(String assemblyPath) in D:\ci\Jenkins\workspace\abp-volo-release\abp\framework\src\Volo.Abp.Cli.Core\Volo\Abp\Cli\Bundling\BundlingService.cs:line 312
[09:07:01 ERR] at Volo.Abp.Cli.Bundling.BundlingService.BundleAsync(String directory, Boolean forceBuild, String projectType) in D:\ci\Jenkins\workspace\abp-volo-release\abp\framework\src\Volo.Abp.Cli.Core\Volo\Abp\Cli\Bundling\BundlingService.cs:line 77
[09:07:01 ERR] at Volo.Abp.Cli.Commands.ProjectCreationCommandBase.RunBundleInternalAsync(ProjectBuildArgs projectArgs) in D:\ci\Jenkins\workspace\abp-volo-release\abp\framework\src\Volo.Abp.Cli.Core\Volo\Abp\Cli\Commands\ProjectCreationCommandBase.cs:line 477
[09:07:01 ERR] at Volo.Abp.Cli.Commands.NewCommand.ExecuteAsync(CommandLineArgs commandLineArgs) in D:\ci\Jenkins\workspace\abp-volo-release\abp\framework\src\Volo.Abp.Cli.Core\Volo\Abp\Cli\Commands\NewCommand.cs:line 120
[09:07:01 ERR] at Volo.Abp.Cli.CliService.RunInternalAsync(CommandLineArgs commandLineArgs) in D:\ci\Jenkins\workspace\abp-volo-release\abp\framework\src\Volo.Abp.Cli.Core\Volo\Abp\Cli\CliService.cs:line 171
[09:07:01 ERR] at Volo.Abp.Cli.CliService.RunAsync(String[] args) in D:\ci\Jenkins\workspace\abp-volo-release\abp\framework\src\Volo.Abp.Cli.Core\Volo\Abp\Cli\CliService.cs:line 77
[09:07:01 ERR] at Volo.Abp.Cli.Program.Main(String[] args) in D:\ci\Jenkins\workspace\abp-volo-release\abp\framework\src\Volo.Abp.Cli\Volo\Abp\Cli\Program.cs:line 43
[09:07:01 ERR] at Volo.Abp.Cli.Program.<Main>(String[] args)
[09:07:01 ERR] System.IO.FileLoadException: Could not load file or assembly 'Volo.Abp.Core, Version=9.2.3.0, Culture=neutral, PublicKeyToken=null'. The located assembly's manifest definition does not match the assembly reference. (0x80131040)
[09:07:01 ERR] File name: 'Volo.Abp.Core, Version=9.2.3.0, Culture=neutral, PublicKeyToken=null'
[09:07:01 ERR] ---> System.IO.FileLoadException: Could not load file or assembly 'D:\Development\rupbes.tstapp\host\rupbes.tstapp.Blazor.Host.Client\bin\Debug\net9.0\Volo.Abp.Core.dll'. The located assembly's manifest definition does not match the assembly reference. (0x80131040)
[09:07:01 ERR] File name: 'D:\Development\rupbes.tstapp\host\rupbes.tstapp.Blazor.Host.Client\bin\Debug\net9.0\Volo.Abp.Core.dll'
[09:07:01 ERR] at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)
[09:07:01 ERR] at System.Reflection.Assembly.LoadFrom(String assemblyFile)
[09:07:01 ERR] at System.Reflection.Assembly.LoadFromResolveHandler(Object sender, ResolveEventArgs args)
[09:07:01 ERR] at System.Runtime.Loader.AssemblyLoadContext.InvokeResolveEvent(ResolveEventHandler eventHandler, RuntimeAssembly assembly, String name)
[09:07:01 ERR] System.IO.FileLoadException: Could not load file or assembly 'Volo.Abp.Core, Version=9.2.3.0, Culture=neutral, PublicKeyToken=null'. The located assembly's manifest definition does not match the assembly reference. (0x80131040)
[09:07:01 ERR] File name: 'Volo.Abp.Core, Version=9.2.3.0, Culture=neutral, PublicKeyToken=null'
[09:07:01 ERR] ---> System.IO.FileLoadException: Could not load file or assembly 'D:\Development\rupbes.tstapp\host\rupbes.tstapp.Blazor.Host.Client\bin\Debug\net9.0\Volo.Abp.Core.dll'. The located assembly's manifest definition does not match the assembly reference. (0x80131040)
[09:07:01 ERR] File name: 'D:\Development\rupbes.tstapp\host\rupbes.tstapp.Blazor.Host.Client\bin\Debug\net9.0\Volo.Abp.Core.dll'
[09:07:01 ERR] at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)
[09:07:01 ERR] at System.Reflection.Assembly.LoadFrom(String assemblyFile)
[09:07:01 ERR] at System.Reflection.Assembly.LoadFromResolveHandler(Object sender, ResolveEventArgs args)
[09:07:01 ERR] at System.Runtime.Loader.AssemblyLoadContext.InvokeResolveEvent(ResolveEventHandler eventHandler, RuntimeAssembly assembly, String name)
[09:07:01 ERR] System.IO.FileLoadException: Could not load file or assembly 'Volo.Abp.Core, Version=9.2.3.0, Culture=neutral, PublicKeyToken=null'. The located assembly's manifest definition does not match the assembly reference. (0x80131040)
[09:07:01 ERR] File name: 'Volo.Abp.Core, Version=9.2.3.0, Culture=neutral, PublicKeyToken=null'
[09:07:01 ERR] ---> System.IO.FileLoadException: Could not load file or assembly 'D:\Development\rupbes.tstapp\host\rupbes.tstapp.Blazor.Host.Client\bin\Debug\net9.0\Volo.Abp.Core.dll'. The located assembly's manifest definition does not match the assembly reference. (0x80131040)
[09:07:01 ERR] File name: 'D:\Development\rupbes.tstapp\host\rupbes.tstapp.Blazor.Host.Client\bin\Debug\net9.0\Volo.Abp.Core.dll'
[09:07:01 ERR] at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)
[09:07:01 ERR] at System.Reflection.Assembly.LoadFrom(String assemblyFile)
[09:07:01 ERR] at System.Reflection.Assembly.LoadFromResolveHandler(Object sender, ResolveEventArgs args)
[09:07:01 ERR] at System.Runtime.Loader.AssemblyLoadContext.InvokeResolveEvent(ResolveEventHandler eventHandler, RuntimeAssembly assembly, String name)
- our first file is
tstappWebHostModule.csof therupbes.tstapp.Web.Host.csproj-
AddAbpOpenIdConnect()method is used to setup authentication (!!!) - The Initial code is shown below:
-
Click to show the code
using System;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.OpenApi.Models;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options;
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
using rupbes.tstapp.Localization;
using rupbes.tstapp.MultiTenancy;
using rupbes.tstapp.Web;
using StackExchange.Redis;
using Volo.Abp;
using Volo.Abp.AspNetCore.Authentication.OAuth;
using Volo.Abp.AspNetCore.Authentication.OpenIdConnect;
using Volo.Abp.AspNetCore.MultiTenancy;
using Volo.Abp.AspNetCore.Mvc.Client;
using Volo.Abp.AspNetCore.Mvc.Localization;
using Volo.Abp.AspNetCore.Mvc.UI;
using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared;
using Volo.Abp.AspNetCore.Serilog;
using Volo.Abp.Autofac;
using Volo.Abp.AutoMapper;
using Volo.Abp.Caching;
using Volo.Abp.Caching.StackExchangeRedis;
using Volo.Abp.FeatureManagement;
using Volo.Abp.Http.Client.IdentityModel.Web;
using Volo.Abp.Identity;
using Volo.Abp.Identity.Web;
using Volo.Abp.Http.Client.Web;
using Volo.Abp.Modularity;
using Volo.Abp.MultiTenancy;
using Volo.Abp.PermissionManagement;
using Volo.Abp.PermissionManagement.Web;
using Volo.Abp.Security.Claims;
using Volo.Abp.Swashbuckle;
using Volo.Abp.TenantManagement;
using Volo.Abp.TenantManagement.Web;
using Volo.Abp.SettingManagement;
using Volo.Abp.SettingManagement.Web;
using Volo.Abp.UI.Navigation.Urls;
using Volo.Abp.UI;
using Volo.Abp.UI.Navigation;
using Volo.Abp.VirtualFileSystem;
namespace rupbes.tstapp;
[DependsOn(
typeof(tstappWebModule),
typeof(tstappHttpApiClientModule),
typeof(tstappHttpApiModule),
typeof(AbpAspNetCoreAuthenticationOpenIdConnectModule),
typeof(AbpAspNetCoreMvcClientModule),
typeof(AbpHttpClientWebModule),
typeof(AbpAspNetCoreMvcUiBasicThemeModule),
typeof(AbpAutofacModule),
typeof(AbpCachingStackExchangeRedisModule),
typeof(AbpHttpClientIdentityModelWebModule),
typeof(AbpIdentityWebModule),
typeof(AbpIdentityHttpApiClientModule),
typeof(AbpFeatureManagementWebModule),
typeof(AbpFeatureManagementHttpApiClientModule),
typeof(AbpTenantManagementWebModule),
typeof(AbpTenantManagementHttpApiClientModule),
typeof(AbpPermissionManagementHttpApiClientModule),
typeof(AbpSettingManagementHttpApiClientModule),
typeof(AbpSettingManagementWebModule),
typeof(AbpAspNetCoreSerilogModule),
typeof(AbpSwashbuckleModule)
)]
public class tstappWebHostModule : AbpModule
{
public override void PreConfigureServices(ServiceConfigurationContext context)
{
context.Services.PreConfigure<AbpMvcDataAnnotationsLocalizationOptions>(options =>
{
options.AddAssemblyResource(
typeof(tstappResource),
typeof(tstappDomainSharedModule).Assembly,
typeof(tstappApplicationContractsModule).Assembly,
typeof(tstappWebHostModule).Assembly
);
});
}
public override void ConfigureServices(ServiceConfigurationContext context)
{
var hostingEnvironment = context.Services.GetHostingEnvironment();
var configuration = context.Services.GetConfiguration();
ConfigureMenu(configuration);
ConfigureCache(configuration);
ConfigureUrls(configuration);
ConfigureAuthentication(context, configuration);
ConfigureAutoMapper();
ConfigureVirtualFileSystem(hostingEnvironment);
ConfigureSwaggerServices(context.Services);
ConfigureMultiTenancy();
ConfigureDataProtection(context, configuration, hostingEnvironment);
}
private void ConfigureMenu(IConfiguration configuration)
{
Configure<AbpNavigationOptions>(options =>
{
options.MenuContributors.Add(new tstappWebHostMenuContributor(configuration));
});
}
private void ConfigureCache(IConfiguration configuration)
{
Configure<AbpDistributedCacheOptions>(options =>
{
options.KeyPrefix = "tstapp:";
});
}
private void ConfigureUrls(IConfiguration configuration)
{
Configure<AppUrlOptions>(options =>
{
options.Applications["MVC"].RootUrl = configuration["App:SelfUrl"];
});
}
private void ConfigureMultiTenancy()
{
Configure<AbpMultiTenancyOptions>(options =>
{
options.IsEnabled = MultiTenancyConsts.IsEnabled;
});
}
private void ConfigureAuthentication(ServiceConfigurationContext context, IConfiguration configuration)
{
context.Services.AddAuthentication(options =>
{
options.DefaultScheme = "Cookies";
options.DefaultChallengeScheme = "oidc";
})
.AddCookie("Cookies", options =>
{
options.ExpireTimeSpan = TimeSpan.FromDays(365);
})
.AddAbpOpenIdConnect("oidc", options =>
{
options.Authority = configuration["AuthServer:Authority"];
options.RequireHttpsMetadata = configuration.GetValue<bool>("AuthServer:RequireHttpsMetadata");
options.ResponseType = OpenIdConnectResponseType.CodeIdToken;
options.ClientId = configuration["AuthServer:ClientId"];
options.SaveTokens = true;
options.GetClaimsFromUserInfoEndpoint = true;
options.Scope.Add("roles");
options.Scope.Add("email");
options.Scope.Add("phone");
options.Scope.Add("tstapp");
});
}
private void ConfigureAutoMapper()
{
Configure<AbpAutoMapperOptions>(options =>
{
options.AddMaps<tstappWebHostModule>();
});
}
private void ConfigureVirtualFileSystem(IWebHostEnvironment hostingEnvironment)
{
if (hostingEnvironment.IsDevelopment())
{
Configure<AbpVirtualFileSystemOptions>(options =>
{
options.FileSets.ReplaceEmbeddedByPhysical<tstappDomainSharedModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}src{0}rupbes.tstapp.Domain.Shared", Path.DirectorySeparatorChar)));
options.FileSets.ReplaceEmbeddedByPhysical<tstappApplicationContractsModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}src{0}rupbes.tstapp.Application.Contracts", Path.DirectorySeparatorChar)));
options.FileSets.ReplaceEmbeddedByPhysical<tstappWebModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}src{0}rupbes.tstapp.Web", Path.DirectorySeparatorChar)));
});
}
}
private void ConfigureSwaggerServices(IServiceCollection services)
{
services.AddAbpSwaggerGen(
options =>
{
options.SwaggerDoc("v1", new OpenApiInfo { Title = "tstapp API", Version = "v1" });
options.DocInclusionPredicate((docName, description) => true);
options.CustomSchemaIds(type => type.FullName);
}
);
}
private void ConfigureDataProtection(
ServiceConfigurationContext context,
IConfiguration configuration,
IWebHostEnvironment hostingEnvironment)
{
var dataProtectionBuilder = context.Services.AddDataProtection().SetApplicationName("tstapp");
if (!hostingEnvironment.IsDevelopment())
{
var redis = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]!);
dataProtectionBuilder.PersistKeysToStackExchangeRedis(redis, "tstapp-Protection-Keys");
}
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
var app = context.GetApplicationBuilder();
var env = context.GetEnvironment();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseErrorPage();
app.UseHsts();
}
app.UseHttpsRedirection();
app.MapAbpStaticAssets();
app.UseRouting();
app.UseAuthentication();
if (MultiTenancyConsts.IsEnabled)
{
app.UseMultiTenancy();
}
app.UseAbpRequestLocalization();
app.UseAuthorization();
app.UseSwagger();
app.UseAbpSwaggerUI(options =>
{
options.SwaggerEndpoint("/swagger/v1/swagger.json", "tstapp API");
});
app.UseAuditing();
app.UseAbpSerilogEnrichers();
app.UseConfiguredEndpoints();
}
}- our second file is
tstappHttpApiHostModule.csof therupbes.tstapp.HttpApi.Host.csproj-project- AddAbpJwtBearer() method is used to setup authentication (!!!)
- Her is an initial code
Click to show the code
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using IdentityModel;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using rupbes.tstapp.EntityFrameworkCore;
using rupbes.tstapp.MultiTenancy;
using StackExchange.Redis;
using Microsoft.OpenApi.Models;
using Volo.Abp;
using Volo.Abp.AspNetCore.Authentication.JwtBearer;
using Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared;
using Volo.Abp.AspNetCore.Serilog;
using Volo.Abp.AuditLogging.EntityFrameworkCore;
using Volo.Abp.Autofac;
using Volo.Abp.Caching;
using Volo.Abp.Caching.StackExchangeRedis;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore.SqlServer;
using Volo.Abp.Localization;
using Volo.Abp.Modularity;
using Volo.Abp.MultiTenancy;
using Volo.Abp.PermissionManagement.EntityFrameworkCore;
using Volo.Abp.Security.Claims;
using Volo.Abp.SettingManagement.EntityFrameworkCore;
using Volo.Abp.Swashbuckle;
using Volo.Abp.TenantManagement.EntityFrameworkCore;
using Volo.Abp.VirtualFileSystem;
namespace rupbes.tstapp;
[DependsOn(
typeof(tstappApplicationModule),
typeof(tstappEntityFrameworkCoreModule),
typeof(tstappHttpApiModule),
typeof(AbpAspNetCoreMvcUiMultiTenancyModule),
typeof(AbpAspNetCoreAuthenticationJwtBearerModule),
typeof(AbpAutofacModule),
typeof(AbpCachingStackExchangeRedisModule),
typeof(AbpEntityFrameworkCoreSqlServerModule),
typeof(AbpAuditLoggingEntityFrameworkCoreModule),
typeof(AbpPermissionManagementEntityFrameworkCoreModule),
typeof(AbpSettingManagementEntityFrameworkCoreModule),
typeof(AbpTenantManagementEntityFrameworkCoreModule),
typeof(AbpAspNetCoreSerilogModule),
typeof(AbpSwashbuckleModule)
)]
public class tstappHttpApiHostModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
var hostingEnvironment = context.Services.GetHostingEnvironment();
var configuration = context.Services.GetConfiguration();
Configure<AbpDbContextOptions>(options =>
{
options.UseSqlServer();
});
Configure<AbpMultiTenancyOptions>(options =>
{
options.IsEnabled = MultiTenancyConsts.IsEnabled;
});
if (hostingEnvironment.IsDevelopment())
{
Configure<AbpVirtualFileSystemOptions>(options =>
{
options.FileSets.ReplaceEmbeddedByPhysical<tstappDomainSharedModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}src{0}rupbes.tstapp.Domain.Shared", Path.DirectorySeparatorChar)));
options.FileSets.ReplaceEmbeddedByPhysical<tstappDomainModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}src{0}rupbes.tstapp.Domain", Path.DirectorySeparatorChar)));
options.FileSets.ReplaceEmbeddedByPhysical<tstappApplicationContractsModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}src{0}rupbes.tstapp.Application.Contracts", Path.DirectorySeparatorChar)));
options.FileSets.ReplaceEmbeddedByPhysical<tstappApplicationModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}src{0}rupbes.tstapp.Application", Path.DirectorySeparatorChar)));
});
}
context.Services.AddAbpSwaggerGenWithOAuth(
configuration["AuthServer:Authority"]!,
new Dictionary<string, string>
{
{"tstapp", "tstapp API"}
},
options =>
{
options.SwaggerDoc("v1", new OpenApiInfo {Title = "tstapp API", Version = "v1"});
options.DocInclusionPredicate((docName, description) => true);
options.CustomSchemaIds(type => type.FullName);
});
Configure<AbpLocalizationOptions>(options =>
{
options.Languages.Add(new LanguageInfo("ar", "ar", "العربية"));
options.Languages.Add(new LanguageInfo("cs", "cs", "Čeština"));
options.Languages.Add(new LanguageInfo("en", "en", "English"));
options.Languages.Add(new LanguageInfo("en-GB", "en-GB", "English (UK)"));
options.Languages.Add(new LanguageInfo("fi", "fi", "Finnish"));
options.Languages.Add(new LanguageInfo("fr", "fr", "Français"));
options.Languages.Add(new LanguageInfo("hi", "hi", "Hindi"));
options.Languages.Add(new LanguageInfo("is", "is", "Icelandic"));
options.Languages.Add(new LanguageInfo("it", "it", "Italiano"));
options.Languages.Add(new LanguageInfo("hu", "hu", "Magyar"));
options.Languages.Add(new LanguageInfo("pt-BR", "pt-BR", "Português"));
options.Languages.Add(new LanguageInfo("ro-RO", "ro-RO", "Română"));
options.Languages.Add(new LanguageInfo("ru", "ru", "Русский"));
options.Languages.Add(new LanguageInfo("sk", "sk", "Slovak"));
options.Languages.Add(new LanguageInfo("tr", "tr", "Türkçe"));
options.Languages.Add(new LanguageInfo("zh-Hans", "zh-Hans", "简体中文"));
options.Languages.Add(new LanguageInfo("zh-Hant", "zh-Hant", "繁體中文"));
options.Languages.Add(new LanguageInfo("de-DE", "de-DE", "Deutsch"));
options.Languages.Add(new LanguageInfo("es", "es", "Español"));
options.Languages.Add(new LanguageInfo("el", "el", "Ελληνικά"));
});
context.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddAbpJwtBearer(options =>
{
options.Authority = configuration["AuthServer:Authority"];
options.RequireHttpsMetadata = configuration.GetValue<bool>("AuthServer:RequireHttpsMetadata");
options.Audience = "tstapp";
});
Configure<AbpDistributedCacheOptions>(options =>
{
options.KeyPrefix = "tstapp:";
});
var dataProtectionBuilder = context.Services.AddDataProtection().SetApplicationName("tstapp");
if (!hostingEnvironment.IsDevelopment())
{
var redis = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]!);
dataProtectionBuilder.PersistKeysToStackExchangeRedis(redis, "tstapp-Protection-Keys");
}
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();
}
else
{
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseCorrelationId();
app.MapAbpStaticAssets();
app.UseRouting();
app.UseCors();
app.UseAuthentication();
if (MultiTenancyConsts.IsEnabled)
{
app.UseMultiTenancy();
}
app.UseAbpRequestLocalization();
app.UseAuthorization();
app.UseSwagger();
app.UseAbpSwaggerUI(options =>
{
options.SwaggerEndpoint("/swagger/v1/swagger.json", "Support APP API");
var configuration = context.GetConfiguration();
options.OAuthClientId(configuration["AuthServer:SwaggerClientId"]);
options.OAuthScopes("tstapp");
});
app.UseAuditing();
app.UseAbpSerilogEnrichers();
app.UseConfiguredEndpoints();
}
}- Both projects do not use
OpenIdDictlibraries. All is ready to integrateKeycloakand Abp application.
- Our goal is to create an analogue of the
rupbes.tstapp.AuthServer-project- It will not work as Authentication server for the front app (
rupbes.tstapp.Web.Host) - But it will not work as Authorization server
- It will not work as Authentication server for the front app (
- We are not alone in our efforts.
- Abp developers have created a sample application
- More detailed information here and here
- Abp developers have created a sample application