diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index 123cc3ea62..0000000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: 'Main' -on: - pull_request: - paths: - - 'framework/**' - - 'modules/**' - branches: - - dev -jobs: - build-test: - runs-on: windows-latest - steps: - - uses: actions/checkout@v1 - - uses: actions/setup-dotnet@master - with: - dotnet-version: '3.0.100' - - - name: Build All - run: .\build-all.ps1 - shell: pwsh - - - name: Test All - run: .\test-all.ps1 - shell: pwsh diff --git a/.gitignore b/.gitignore index 4eabbccebd..73d74ec7c6 100644 --- a/.gitignore +++ b/.gitignore @@ -289,4 +289,5 @@ samples/MicroserviceDemo/gateways/BackendAdminAppGateway.Host/Logs/logs.txt samples/MicroserviceDemo/applications/PublicWebSite.Host/Logs/logs.txt samples/MicroserviceDemo/gateways/PublicWebSiteGateway.Host/Logs/logs.txt samples/MicroserviceDemo/microservices/BloggingService.Host/Logs/logs.txt +samples/MicroserviceDemo/applications/ConsoleClientDemo/Logs/logs.txt modules/docs/app/Volo.DocsTestApp/Logs/logs.txt diff --git a/docs/zh-Hans/Best-Practices/Application-Services.md b/docs/zh-Hans/Best-Practices/Application-Services.md index 342d7cc3bb..6c8d11b32b 100644 --- a/docs/zh-Hans/Best-Practices/Application-Services.md +++ b/docs/zh-Hans/Best-Practices/Application-Services.md @@ -45,7 +45,7 @@ public class IssueLabelDto ##### 详细DTO -**Do** 如果实体持有对其他聚合根的引用,那么应该为其定义**详细**DTO. +**推荐** 如果实体持有对其他聚合根的引用,那么应该为其定义**详细**DTO. * 直接包含实体中所有的 **原始属性**. - 例外-1: 出于**安全**原因,可以**排除**某些属性(像 `User.Password`). diff --git a/docs/zh-Hans/Best-Practices/Entity-Framework-Core-Integration.md b/docs/zh-Hans/Best-Practices/Entity-Framework-Core-Integration.md index 1e59793a7f..3dd687be53 100644 --- a/docs/zh-Hans/Best-Practices/Entity-Framework-Core-Integration.md +++ b/docs/zh-Hans/Best-Practices/Entity-Framework-Core-Integration.md @@ -58,7 +58,7 @@ public static string Schema { get; set; } = AbpIdentityConsts.DefaultDbSchema; ### Model Mapping -- **Do** 重写 `DbContext` 的 `OnModelCreating` 方法显式 **配置所有实体**. 例如: +- **推荐** 重写 `DbContext` 的 `OnModelCreating` 方法显式 **配置所有实体**. 例如: ````C# protected override void OnModelCreating(ModelBuilder builder) diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Localization/Resources/tr.json b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Localization/Resources/tr.json new file mode 100644 index 0000000000..9340b7999f --- /dev/null +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Localization/Resources/tr.json @@ -0,0 +1,8 @@ +{ + "culture": "tr", + "texts": { + "Volo.IdentityServer:DuplicateIdentityResourceName": "Identity Resource adı zaten mevcut: {Name}", + "Volo.IdentityServer:DuplicateApiResourceName": "Api Resource adı zaten mevcut: {Name}", + "Volo.IdentityServer:DuplicateClientId": "ClientId already zaten mevcut: {ClientId}" + } +} \ No newline at end of file diff --git a/samples/MicroserviceDemo/_run/01_AuthServer.ps1 b/samples/MicroserviceDemo/_run/01_AuthServer.ps1 new file mode 100644 index 0000000000..14d1b32981 --- /dev/null +++ b/samples/MicroserviceDemo/_run/01_AuthServer.ps1 @@ -0,0 +1,2 @@ +cd ../applications/AuthServer.Host +dotnet run \ No newline at end of file diff --git a/samples/MicroserviceDemo/_run/02_IdentityService.ps1 b/samples/MicroserviceDemo/_run/02_IdentityService.ps1 new file mode 100644 index 0000000000..c47c8406c3 --- /dev/null +++ b/samples/MicroserviceDemo/_run/02_IdentityService.ps1 @@ -0,0 +1,2 @@ +cd ../microservices/IdentityService.Host +dotnet run \ No newline at end of file diff --git a/samples/MicroserviceDemo/_run/03_BloggingService.ps1 b/samples/MicroserviceDemo/_run/03_BloggingService.ps1 new file mode 100644 index 0000000000..65b2c9ca11 --- /dev/null +++ b/samples/MicroserviceDemo/_run/03_BloggingService.ps1 @@ -0,0 +1,2 @@ +cd ../microservices/BloggingService.Host +dotnet run \ No newline at end of file diff --git a/samples/MicroserviceDemo/_run/04_ProductService.ps1 b/samples/MicroserviceDemo/_run/04_ProductService.ps1 new file mode 100644 index 0000000000..1181edd4e0 --- /dev/null +++ b/samples/MicroserviceDemo/_run/04_ProductService.ps1 @@ -0,0 +1,2 @@ +cd ../microservices/ProductService.Host +dotnet run \ No newline at end of file diff --git a/samples/MicroserviceDemo/_run/05_InternalGateway.ps1 b/samples/MicroserviceDemo/_run/05_InternalGateway.ps1 new file mode 100644 index 0000000000..f27befba7b --- /dev/null +++ b/samples/MicroserviceDemo/_run/05_InternalGateway.ps1 @@ -0,0 +1,2 @@ +cd ../gateways/InternalGateway.Host +dotnet run \ No newline at end of file diff --git a/samples/MicroserviceDemo/_run/06_BackendAdminAppGateway.ps1 b/samples/MicroserviceDemo/_run/06_BackendAdminAppGateway.ps1 new file mode 100644 index 0000000000..3d819542c2 --- /dev/null +++ b/samples/MicroserviceDemo/_run/06_BackendAdminAppGateway.ps1 @@ -0,0 +1,2 @@ +cd ../gateways/BackendAdminAppGateway.Host +dotnet run \ No newline at end of file diff --git a/samples/MicroserviceDemo/_run/07_PublicWebSiteGateway.ps1 b/samples/MicroserviceDemo/_run/07_PublicWebSiteGateway.ps1 new file mode 100644 index 0000000000..009f45bc66 --- /dev/null +++ b/samples/MicroserviceDemo/_run/07_PublicWebSiteGateway.ps1 @@ -0,0 +1,2 @@ +cd ../gateways/PublicWebSiteGateway.Host +dotnet run \ No newline at end of file diff --git a/samples/MicroserviceDemo/_run/08_BackendAdminApp.ps1 b/samples/MicroserviceDemo/_run/08_BackendAdminApp.ps1 new file mode 100644 index 0000000000..356d7ac981 --- /dev/null +++ b/samples/MicroserviceDemo/_run/08_BackendAdminApp.ps1 @@ -0,0 +1,2 @@ +cd ../applications/BackendAdminApp.Host +dotnet run \ No newline at end of file diff --git a/samples/MicroserviceDemo/_run/09_PublicWebSite.ps1 b/samples/MicroserviceDemo/_run/09_PublicWebSite.ps1 new file mode 100644 index 0000000000..24d31ced0f --- /dev/null +++ b/samples/MicroserviceDemo/_run/09_PublicWebSite.ps1 @@ -0,0 +1,2 @@ +cd ../applications/PublicWebSite.Host +dotnet run \ No newline at end of file diff --git a/samples/MicroserviceDemo/_run/10_ConsoleClientDemo.ps1 b/samples/MicroserviceDemo/_run/10_ConsoleClientDemo.ps1 new file mode 100644 index 0000000000..0fc3d40edc --- /dev/null +++ b/samples/MicroserviceDemo/_run/10_ConsoleClientDemo.ps1 @@ -0,0 +1,2 @@ +cd ../applications/ConsoleClientDemo +dotnet run \ No newline at end of file diff --git a/samples/MicroserviceDemo/_run/README.md b/samples/MicroserviceDemo/_run/README.md new file mode 100644 index 0000000000..f81e093cc2 --- /dev/null +++ b/samples/MicroserviceDemo/_run/README.md @@ -0,0 +1,19 @@ +# Run the Microservice Demo Solution + +This folder contains PowerShell files to run the system: + +* **__Run_All_Application.ps1**: Runs all the applications in one click. +* **__Run_Browser.ps1**: Opens all the UIs of the applications in Google Chrome browser. + +Other files runs the individual applications. + +> This files are only tested in Windows 10. + +### Pre-Requirements + +- [SQL Server](https://www.microsoft.com/en-us/sql-server/sql-server-downloads) 2015+ (can be [express edition](https://www.microsoft.com/en-us/sql-server/sql-server-editions-express)) +- [Redis](https://redis.io/download) 5.0+ +- [RabbitMQ](https://www.rabbitmq.com/install-windows.html) 3.7.11+ +- [MongoDB](https://www.mongodb.com/download-center) 4.0+ +- [ElasticSearch](https://www.elastic.co/downloads/elasticsearch) 6.6+ +- [Kibana](https://www.elastic.co/downloads/kibana) 6.6+ (optional, recommended to see logs) \ No newline at end of file diff --git a/samples/MicroserviceDemo/_run/__Run_All_Application.ps1 b/samples/MicroserviceDemo/_run/__Run_All_Application.ps1 new file mode 100644 index 0000000000..9129959d85 --- /dev/null +++ b/samples/MicroserviceDemo/_run/__Run_All_Application.ps1 @@ -0,0 +1,9 @@ +start powershell .\01_AuthServer.ps1 +start powershell .\02_IdentityService.ps1 +start powershell .\03_BloggingService.ps1 +start powershell .\04_ProductService.ps1 +start powershell .\05_InternalGateway.ps1 +start powershell .\06_BackendAdminAppGateway.ps1 +start powershell .\07_PublicWebSiteGateway.ps1 +start powershell .\08_BackendAdminApp.ps1 +start powershell .\09_PublicWebSite.ps1 \ No newline at end of file diff --git a/samples/MicroserviceDemo/_run/__Run_Browser.ps1 b/samples/MicroserviceDemo/_run/__Run_Browser.ps1 new file mode 100644 index 0000000000..50c010b9bb --- /dev/null +++ b/samples/MicroserviceDemo/_run/__Run_Browser.ps1 @@ -0,0 +1 @@ +start chrome http://localhost:64999,http://localhost:63568,http://localhost:62157,http://localhost:60244,http://localhost:65129/swagger,http://localhost:65115/swagger,http://localhost:64897/swagger,http://localhost:51954,http://localhost:53435 \ No newline at end of file diff --git a/samples/MicroserviceDemo/applications/AuthServer.Host/Properties/launchSettings.json b/samples/MicroserviceDemo/applications/AuthServer.Host/Properties/launchSettings.json index 64eeed40fe..d8e84747ac 100644 --- a/samples/MicroserviceDemo/applications/AuthServer.Host/Properties/launchSettings.json +++ b/samples/MicroserviceDemo/applications/AuthServer.Host/Properties/launchSettings.json @@ -18,7 +18,7 @@ "AuthServer.Host": { "commandName": "Project", "launchBrowser": true, - "applicationUrl": "http://localhost:5000", + "applicationUrl": "http://localhost:64999", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } diff --git a/samples/MicroserviceDemo/applications/BackendAdminApp.Host/Properties/launchSettings.json b/samples/MicroserviceDemo/applications/BackendAdminApp.Host/Properties/launchSettings.json index affa8826fb..f7ea179db1 100644 --- a/samples/MicroserviceDemo/applications/BackendAdminApp.Host/Properties/launchSettings.json +++ b/samples/MicroserviceDemo/applications/BackendAdminApp.Host/Properties/launchSettings.json @@ -18,7 +18,7 @@ "BackendAdminApp.Host": { "commandName": "Project", "launchBrowser": true, - "applicationUrl": "http://localhost:5000", + "applicationUrl": "http://localhost:51954", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } diff --git a/samples/MicroserviceDemo/applications/PublicWebSite.Host/Properties/launchSettings.json b/samples/MicroserviceDemo/applications/PublicWebSite.Host/Properties/launchSettings.json index 3945c0c403..9b9ac6527f 100644 --- a/samples/MicroserviceDemo/applications/PublicWebSite.Host/Properties/launchSettings.json +++ b/samples/MicroserviceDemo/applications/PublicWebSite.Host/Properties/launchSettings.json @@ -18,7 +18,7 @@ "PublicWebSite.Host": { "commandName": "Project", "launchBrowser": true, - "applicationUrl": "http://localhost:5000", + "applicationUrl": "http://localhost:53435", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } diff --git a/samples/MicroserviceDemo/gateways/BackendAdminAppGateway.Host/BackendAdminAppGatewayHostModule.cs b/samples/MicroserviceDemo/gateways/BackendAdminAppGateway.Host/BackendAdminAppGatewayHostModule.cs index d30dc8e4fb..81a109a6f0 100644 --- a/samples/MicroserviceDemo/gateways/BackendAdminAppGateway.Host/BackendAdminAppGatewayHostModule.cs +++ b/samples/MicroserviceDemo/gateways/BackendAdminAppGateway.Host/BackendAdminAppGatewayHostModule.cs @@ -1,4 +1,7 @@ -using Microsoft.AspNetCore.Builder; +using System.Collections.Generic; +using System.Linq; +using System.Security.Claims; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.DataProtection; using Microsoft.Extensions.DependencyInjection; using Ocelot.DependencyInjection; @@ -52,14 +55,6 @@ namespace BackendAdminAppGateway.Host options.Authority = configuration["AuthServer:Authority"]; options.ApiName = configuration["AuthServer:ApiName"]; options.RequireHttpsMetadata = false; - //TODO: Should create an extension method for that (may require to create a new ABP package depending on the IdentityServer4.AccessTokenValidation) - //options.InboundJwtClaimTypeMap["sub"] = AbpClaimTypes.UserId; - //options.InboundJwtClaimTypeMap["role"] = AbpClaimTypes.Role; - //options.InboundJwtClaimTypeMap["email"] = AbpClaimTypes.Email; - //options.InboundJwtClaimTypeMap["email_verified"] = AbpClaimTypes.EmailVerified; - //options.InboundJwtClaimTypeMap["phone_number"] = AbpClaimTypes.PhoneNumber; - //options.InboundJwtClaimTypeMap["phone_number_verified"] = AbpClaimTypes.PhoneNumberVerified; - //options.InboundJwtClaimTypeMap["name"] = AbpClaimTypes.UserName; }); context.Services.AddSwaggerGen(options => @@ -94,6 +89,22 @@ namespace BackendAdminAppGateway.Host app.UseVirtualFiles(); app.UseRouting(); app.UseAuthentication(); + + app.Use(async (ctx, next) => + { + var currentPrincipalAccessor = ctx.RequestServices.GetRequiredService(); + var map = new Dictionary() + { + { "sub", AbpClaimTypes.UserId }, + { "role", AbpClaimTypes.Role }, + { "email", AbpClaimTypes.Email }, + //any other map + }; + var mapClaims = currentPrincipalAccessor.Principal.Claims.Where(p => map.Keys.Contains(p.Type)).ToList(); + currentPrincipalAccessor.Principal.AddIdentity(new ClaimsIdentity(mapClaims.Select(p => new Claim(map[p.Type], p.Value, p.ValueType, p.Issuer)))); + await next(); + }); + app.UseSwagger(); app.UseSwaggerUI(options => { diff --git a/samples/MicroserviceDemo/gateways/BackendAdminAppGateway.Host/Properties/launchSettings.json b/samples/MicroserviceDemo/gateways/BackendAdminAppGateway.Host/Properties/launchSettings.json index 981961f411..f56a0bdb72 100644 --- a/samples/MicroserviceDemo/gateways/BackendAdminAppGateway.Host/Properties/launchSettings.json +++ b/samples/MicroserviceDemo/gateways/BackendAdminAppGateway.Host/Properties/launchSettings.json @@ -18,7 +18,7 @@ "BackendAdminAppGateway.Host": { "commandName": "Project", "launchBrowser": true, - "applicationUrl": "http://localhost:5000", + "applicationUrl": "http://localhost:65115", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } diff --git a/samples/MicroserviceDemo/gateways/InternalGateway.Host/InternalGatewayHostModule.cs b/samples/MicroserviceDemo/gateways/InternalGateway.Host/InternalGatewayHostModule.cs index 8b470f826f..a3572551f9 100644 --- a/samples/MicroserviceDemo/gateways/InternalGateway.Host/InternalGatewayHostModule.cs +++ b/samples/MicroserviceDemo/gateways/InternalGateway.Host/InternalGatewayHostModule.cs @@ -1,4 +1,7 @@ -using Microsoft.AspNetCore.Builder; +using System.Collections.Generic; +using System.Linq; +using System.Security.Claims; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.DataProtection; using Microsoft.Extensions.DependencyInjection; using Ocelot.DependencyInjection; @@ -41,14 +44,6 @@ namespace InternalGateway.Host options.Authority = configuration["AuthServer:Authority"]; options.ApiName = configuration["AuthServer:ApiName"]; options.RequireHttpsMetadata = false; - //TODO: Should create an extension method for that (may require to create a new ABP package depending on the IdentityServer4.AccessTokenValidation) - //options.InboundJwtClaimTypeMap["sub"] = AbpClaimTypes.UserId; - //options.InboundJwtClaimTypeMap["role"] = AbpClaimTypes.Role; - //options.InboundJwtClaimTypeMap["email"] = AbpClaimTypes.Email; - //options.InboundJwtClaimTypeMap["email_verified"] = AbpClaimTypes.EmailVerified; - //options.InboundJwtClaimTypeMap["phone_number"] = AbpClaimTypes.PhoneNumber; - //options.InboundJwtClaimTypeMap["phone_number_verified"] = AbpClaimTypes.PhoneNumberVerified; - //options.InboundJwtClaimTypeMap["name"] = AbpClaimTypes.UserName; }); context.Services.AddSwaggerGen(options => @@ -83,6 +78,22 @@ namespace InternalGateway.Host app.UseVirtualFiles(); app.UseRouting(); app.UseAuthentication(); + + app.Use(async (ctx, next) => + { + var currentPrincipalAccessor = ctx.RequestServices.GetRequiredService(); + var map = new Dictionary() + { + { "sub", AbpClaimTypes.UserId }, + { "role", AbpClaimTypes.Role }, + { "email", AbpClaimTypes.Email }, + //any other map + }; + var mapClaims = currentPrincipalAccessor.Principal.Claims.Where(p => map.Keys.Contains(p.Type)).ToList(); + currentPrincipalAccessor.Principal.AddIdentity(new ClaimsIdentity(mapClaims.Select(p => new Claim(map[p.Type], p.Value, p.ValueType, p.Issuer)))); + await next(); + }); + app.UseSwagger(); app.UseSwaggerUI(options => { diff --git a/samples/MicroserviceDemo/gateways/InternalGateway.Host/Properties/launchSettings.json b/samples/MicroserviceDemo/gateways/InternalGateway.Host/Properties/launchSettings.json index f65859f468..c56831d419 100644 --- a/samples/MicroserviceDemo/gateways/InternalGateway.Host/Properties/launchSettings.json +++ b/samples/MicroserviceDemo/gateways/InternalGateway.Host/Properties/launchSettings.json @@ -18,7 +18,7 @@ "InternalGateway.Host": { "commandName": "Project", "launchBrowser": true, - "applicationUrl": "http://localhost:5000", + "applicationUrl": "http://localhost:65129", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } diff --git a/samples/MicroserviceDemo/gateways/PublicWebSiteGateway.Host/Properties/launchSettings.json b/samples/MicroserviceDemo/gateways/PublicWebSiteGateway.Host/Properties/launchSettings.json index fa3d33da52..b24931efcf 100644 --- a/samples/MicroserviceDemo/gateways/PublicWebSiteGateway.Host/Properties/launchSettings.json +++ b/samples/MicroserviceDemo/gateways/PublicWebSiteGateway.Host/Properties/launchSettings.json @@ -18,7 +18,7 @@ "PublicWebSiteGateway.Host": { "commandName": "Project", "launchBrowser": true, - "applicationUrl": "http://localhost:5000", + "applicationUrl": "http://localhost:64897", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } diff --git a/samples/MicroserviceDemo/gateways/PublicWebSiteGateway.Host/PublicWebSiteGatewayHostModule.cs b/samples/MicroserviceDemo/gateways/PublicWebSiteGateway.Host/PublicWebSiteGatewayHostModule.cs index 2add48443a..0129663e5a 100644 --- a/samples/MicroserviceDemo/gateways/PublicWebSiteGateway.Host/PublicWebSiteGatewayHostModule.cs +++ b/samples/MicroserviceDemo/gateways/PublicWebSiteGateway.Host/PublicWebSiteGatewayHostModule.cs @@ -1,4 +1,7 @@ -using Microsoft.AspNetCore.Builder; +using System.Collections.Generic; +using System.Linq; +using System.Security.Claims; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.DataProtection; using Microsoft.Extensions.DependencyInjection; using Ocelot.DependencyInjection; @@ -39,14 +42,6 @@ namespace PublicWebSiteGateway.Host options.Authority = configuration["AuthServer:Authority"]; options.ApiName = configuration["AuthServer:ApiName"]; options.RequireHttpsMetadata = false; - //TODO: Should create an extension method for that (may require to create a new ABP package depending on the IdentityServer4.AccessTokenValidation) - //options.InboundJwtClaimTypeMap["sub"] = AbpClaimTypes.UserId; - //options.InboundJwtClaimTypeMap["role"] = AbpClaimTypes.Role; - //options.InboundJwtClaimTypeMap["email"] = AbpClaimTypes.Email; - //options.InboundJwtClaimTypeMap["email_verified"] = AbpClaimTypes.EmailVerified; - //options.InboundJwtClaimTypeMap["phone_number"] = AbpClaimTypes.PhoneNumber; - //options.InboundJwtClaimTypeMap["phone_number_verified"] = AbpClaimTypes.PhoneNumberVerified; - //options.InboundJwtClaimTypeMap["name"] = AbpClaimTypes.UserName; }); context.Services.AddSwaggerGen(options => @@ -81,6 +76,22 @@ namespace PublicWebSiteGateway.Host app.UseVirtualFiles(); app.UseRouting(); app.UseAuthentication(); + + app.Use(async (ctx, next) => + { + var currentPrincipalAccessor = ctx.RequestServices.GetRequiredService(); + var map = new Dictionary() + { + { "sub", AbpClaimTypes.UserId }, + { "role", AbpClaimTypes.Role }, + { "email", AbpClaimTypes.Email }, + //any other map + }; + var mapClaims = currentPrincipalAccessor.Principal.Claims.Where(p => map.Keys.Contains(p.Type)).ToList(); + currentPrincipalAccessor.Principal.AddIdentity(new ClaimsIdentity(mapClaims.Select(p => new Claim(map[p.Type], p.Value, p.ValueType, p.Issuer)))); + await next(); + }); + app.UseSwagger(); app.UseSwaggerUI(options => { diff --git a/samples/MicroserviceDemo/microservices/BloggingService.Host/BloggingServiceHostModule.cs b/samples/MicroserviceDemo/microservices/BloggingService.Host/BloggingServiceHostModule.cs index 1f80e0c605..2d7e945cf5 100644 --- a/samples/MicroserviceDemo/microservices/BloggingService.Host/BloggingServiceHostModule.cs +++ b/samples/MicroserviceDemo/microservices/BloggingService.Host/BloggingServiceHostModule.cs @@ -1,5 +1,8 @@ using System; +using System.Collections.Generic; using System.IO; +using System.Linq; +using System.Security.Claims; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.DataProtection; @@ -57,14 +60,6 @@ namespace BloggingService.Host options.Authority = configuration["AuthServer:Authority"]; options.ApiName = configuration["AuthServer:ApiName"]; options.RequireHttpsMetadata = false; - //TODO: Should create an extension method for that (may require to create a new ABP package depending on the IdentityServer4.AccessTokenValidation) - //options.InboundJwtClaimTypeMap["sub"] = AbpClaimTypes.UserId; - //options.InboundJwtClaimTypeMap["role"] = AbpClaimTypes.Role; - //options.InboundJwtClaimTypeMap["email"] = AbpClaimTypes.Email; - //options.InboundJwtClaimTypeMap["email_verified"] = AbpClaimTypes.EmailVerified; - //options.InboundJwtClaimTypeMap["phone_number"] = AbpClaimTypes.PhoneNumber; - //options.InboundJwtClaimTypeMap["phone_number_verified"] = AbpClaimTypes.PhoneNumberVerified; - //options.InboundJwtClaimTypeMap["name"] = AbpClaimTypes.UserName; }); context.Services.AddSwaggerGen(options => @@ -113,6 +108,22 @@ namespace BloggingService.Host app.UseVirtualFiles(); app.UseRouting(); app.UseAuthentication(); + + app.Use(async (ctx, next) => + { + var currentPrincipalAccessor = ctx.RequestServices.GetRequiredService(); + var map = new Dictionary() + { + { "sub", AbpClaimTypes.UserId }, + { "role", AbpClaimTypes.Role }, + { "email", AbpClaimTypes.Email }, + //any other map + }; + var mapClaims = currentPrincipalAccessor.Principal.Claims.Where(p => map.Keys.Contains(p.Type)).ToList(); + currentPrincipalAccessor.Principal.AddIdentity(new ClaimsIdentity(mapClaims.Select(p => new Claim(map[p.Type], p.Value, p.ValueType, p.Issuer)))); + await next(); + }); + app.UseAbpRequestLocalization(); //TODO: localization? app.UseSwagger(); app.UseSwaggerUI(options => diff --git a/samples/MicroserviceDemo/microservices/BloggingService.Host/Properties/launchSettings.json b/samples/MicroserviceDemo/microservices/BloggingService.Host/Properties/launchSettings.json index b8f8803266..0ad1aabc2a 100644 --- a/samples/MicroserviceDemo/microservices/BloggingService.Host/Properties/launchSettings.json +++ b/samples/MicroserviceDemo/microservices/BloggingService.Host/Properties/launchSettings.json @@ -18,7 +18,7 @@ "BloggingService.Host": { "commandName": "Project", "launchBrowser": true, - "applicationUrl": "http://localhost:5000", + "applicationUrl": "http://localhost:62157", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } diff --git a/samples/MicroserviceDemo/microservices/IdentityService.Host/IdentityServiceHostModule.cs b/samples/MicroserviceDemo/microservices/IdentityService.Host/IdentityServiceHostModule.cs index 96899af0a0..2bf102a465 100644 --- a/samples/MicroserviceDemo/microservices/IdentityService.Host/IdentityServiceHostModule.cs +++ b/samples/MicroserviceDemo/microservices/IdentityService.Host/IdentityServiceHostModule.cs @@ -1,4 +1,7 @@ -using Microsoft.AspNetCore.Builder; +using System.Collections.Generic; +using System.Linq; +using System.Security.Claims; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.DataProtection; using Microsoft.Extensions.DependencyInjection; using StackExchange.Redis; @@ -44,14 +47,6 @@ namespace IdentityService.Host options.Authority = configuration["AuthServer:Authority"]; options.ApiName = configuration["AuthServer:ApiName"]; options.RequireHttpsMetadata = false; - //TODO: Should create an extension method for that (may require to create a new ABP package depending on the IdentityServer4.AccessTokenValidation) - //options.InboundJwtClaimTypeMap["sub"] = AbpClaimTypes.UserId; - //options.InboundJwtClaimTypeMap["role"] = AbpClaimTypes.Role; - //options.InboundJwtClaimTypeMap["email"] = AbpClaimTypes.Email; - //options.InboundJwtClaimTypeMap["email_verified"] = AbpClaimTypes.EmailVerified; - //options.InboundJwtClaimTypeMap["phone_number"] = AbpClaimTypes.PhoneNumber; - //options.InboundJwtClaimTypeMap["phone_number_verified"] = AbpClaimTypes.PhoneNumberVerified; - //options.InboundJwtClaimTypeMap["name"] = AbpClaimTypes.UserName; }); context.Services.AddSwaggerGen(options => @@ -95,6 +90,22 @@ namespace IdentityService.Host app.UseVirtualFiles(); app.UseRouting(); app.UseAuthentication(); + + app.Use(async (ctx, next) => + { + var currentPrincipalAccessor = ctx.RequestServices.GetRequiredService(); + var map = new Dictionary() + { + { "sub", AbpClaimTypes.UserId }, + { "role", AbpClaimTypes.Role }, + { "email", AbpClaimTypes.Email }, + //any other map + }; + var mapClaims = currentPrincipalAccessor.Principal.Claims.Where(p => map.Keys.Contains(p.Type)).ToList(); + currentPrincipalAccessor.Principal.AddIdentity(new ClaimsIdentity(mapClaims.Select(p => new Claim(map[p.Type], p.Value, p.ValueType, p.Issuer)))); + await next(); + }); + app.UseAbpRequestLocalization(); //TODO: localization? app.UseSwagger(); app.UseSwaggerUI(options => diff --git a/samples/MicroserviceDemo/microservices/IdentityService.Host/Properties/launchSettings.json b/samples/MicroserviceDemo/microservices/IdentityService.Host/Properties/launchSettings.json index cd85573717..d47ed9055c 100644 --- a/samples/MicroserviceDemo/microservices/IdentityService.Host/Properties/launchSettings.json +++ b/samples/MicroserviceDemo/microservices/IdentityService.Host/Properties/launchSettings.json @@ -18,7 +18,7 @@ "IdentityService.Host": { "commandName": "Project", "launchBrowser": true, - "applicationUrl": "http://localhost:5000", + "applicationUrl": "http://localhost:63568", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } diff --git a/samples/MicroserviceDemo/microservices/ProductService.Host/ProductServiceHostModule.cs b/samples/MicroserviceDemo/microservices/ProductService.Host/ProductServiceHostModule.cs index 8389067092..97235133f9 100644 --- a/samples/MicroserviceDemo/microservices/ProductService.Host/ProductServiceHostModule.cs +++ b/samples/MicroserviceDemo/microservices/ProductService.Host/ProductServiceHostModule.cs @@ -1,4 +1,7 @@ -using Microsoft.AspNetCore.Builder; +using System.Collections.Generic; +using System.Linq; +using System.Security.Claims; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.DataProtection; using Microsoft.Extensions.DependencyInjection; using ProductManagement; @@ -46,14 +49,6 @@ namespace ProductService.Host options.Authority = configuration["AuthServer:Authority"]; options.ApiName = configuration["AuthServer:ApiName"]; options.RequireHttpsMetadata = false; - //TODO: Should create an extension method for that (may require to create a new ABP package depending on the IdentityServer4.AccessTokenValidation) - //options.InboundJwtClaimTypeMap["sub"] = AbpClaimTypes.UserId; - //options.InboundJwtClaimTypeMap["role"] = AbpClaimTypes.Role; - //options.InboundJwtClaimTypeMap["email"] = AbpClaimTypes.Email; - //options.InboundJwtClaimTypeMap["email_verified"] = AbpClaimTypes.EmailVerified; - //options.InboundJwtClaimTypeMap["phone_number"] = AbpClaimTypes.PhoneNumber; - //options.InboundJwtClaimTypeMap["phone_number_verified"] = AbpClaimTypes.PhoneNumberVerified; - //options.InboundJwtClaimTypeMap["name"] = AbpClaimTypes.UserName; }); context.Services.AddSwaggerGen(options => @@ -97,6 +92,22 @@ namespace ProductService.Host app.UseVirtualFiles(); app.UseRouting(); app.UseAuthentication(); + + app.Use(async (ctx, next) => + { + var currentPrincipalAccessor = ctx.RequestServices.GetRequiredService(); + var map = new Dictionary() + { + { "sub", AbpClaimTypes.UserId }, + { "role", AbpClaimTypes.Role }, + { "email", AbpClaimTypes.Email }, + //any other map + }; + var mapClaims = currentPrincipalAccessor.Principal.Claims.Where(p => map.Keys.Contains(p.Type)).ToList(); + currentPrincipalAccessor.Principal.AddIdentity(new ClaimsIdentity(mapClaims.Select(p => new Claim(map[p.Type], p.Value, p.ValueType, p.Issuer)))); + await next(); + }); + app.UseAbpRequestLocalization(); //TODO: localization? app.UseSwagger(); app.UseSwaggerUI(options => diff --git a/samples/MicroserviceDemo/microservices/ProductService.Host/Properties/launchSettings.json b/samples/MicroserviceDemo/microservices/ProductService.Host/Properties/launchSettings.json index b93ef90918..d6620ecc08 100644 --- a/samples/MicroserviceDemo/microservices/ProductService.Host/Properties/launchSettings.json +++ b/samples/MicroserviceDemo/microservices/ProductService.Host/Properties/launchSettings.json @@ -18,7 +18,7 @@ "ProductService.Host": { "commandName": "Project", "launchBrowser": true, - "applicationUrl": "http://localhost:5000", + "applicationUrl": "http://localhost:60244", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" }