Browse Source

Merge branch 'dev' of https://github.com/abpframework/abp into dev

pull/2238/head
mehmet-erim 7 years ago
parent
commit
d0f3f385cb
  1. 24
      .github/workflows/main.yml
  2. 1
      .gitignore
  3. 2
      docs/zh-Hans/Best-Practices/Application-Services.md
  4. 2
      docs/zh-Hans/Best-Practices/Entity-Framework-Core-Integration.md
  5. 8
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Localization/Resources/tr.json
  6. 2
      samples/MicroserviceDemo/_run/01_AuthServer.ps1
  7. 2
      samples/MicroserviceDemo/_run/02_IdentityService.ps1
  8. 2
      samples/MicroserviceDemo/_run/03_BloggingService.ps1
  9. 2
      samples/MicroserviceDemo/_run/04_ProductService.ps1
  10. 2
      samples/MicroserviceDemo/_run/05_InternalGateway.ps1
  11. 2
      samples/MicroserviceDemo/_run/06_BackendAdminAppGateway.ps1
  12. 2
      samples/MicroserviceDemo/_run/07_PublicWebSiteGateway.ps1
  13. 2
      samples/MicroserviceDemo/_run/08_BackendAdminApp.ps1
  14. 2
      samples/MicroserviceDemo/_run/09_PublicWebSite.ps1
  15. 2
      samples/MicroserviceDemo/_run/10_ConsoleClientDemo.ps1
  16. 19
      samples/MicroserviceDemo/_run/README.md
  17. 9
      samples/MicroserviceDemo/_run/__Run_All_Application.ps1
  18. 1
      samples/MicroserviceDemo/_run/__Run_Browser.ps1
  19. 2
      samples/MicroserviceDemo/applications/AuthServer.Host/Properties/launchSettings.json
  20. 2
      samples/MicroserviceDemo/applications/BackendAdminApp.Host/Properties/launchSettings.json
  21. 2
      samples/MicroserviceDemo/applications/PublicWebSite.Host/Properties/launchSettings.json
  22. 29
      samples/MicroserviceDemo/gateways/BackendAdminAppGateway.Host/BackendAdminAppGatewayHostModule.cs
  23. 2
      samples/MicroserviceDemo/gateways/BackendAdminAppGateway.Host/Properties/launchSettings.json
  24. 29
      samples/MicroserviceDemo/gateways/InternalGateway.Host/InternalGatewayHostModule.cs
  25. 2
      samples/MicroserviceDemo/gateways/InternalGateway.Host/Properties/launchSettings.json
  26. 2
      samples/MicroserviceDemo/gateways/PublicWebSiteGateway.Host/Properties/launchSettings.json
  27. 29
      samples/MicroserviceDemo/gateways/PublicWebSiteGateway.Host/PublicWebSiteGatewayHostModule.cs
  28. 27
      samples/MicroserviceDemo/microservices/BloggingService.Host/BloggingServiceHostModule.cs
  29. 2
      samples/MicroserviceDemo/microservices/BloggingService.Host/Properties/launchSettings.json
  30. 29
      samples/MicroserviceDemo/microservices/IdentityService.Host/IdentityServiceHostModule.cs
  31. 2
      samples/MicroserviceDemo/microservices/IdentityService.Host/Properties/launchSettings.json
  32. 29
      samples/MicroserviceDemo/microservices/ProductService.Host/ProductServiceHostModule.cs
  33. 2
      samples/MicroserviceDemo/microservices/ProductService.Host/Properties/launchSettings.json

24
.github/workflows/main.yml

@ -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

1
.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

2
docs/zh-Hans/Best-Practices/Application-Services.md

@ -45,7 +45,7 @@ public class IssueLabelDto
##### 详细DTO
**Do** 如果实体持有对其他聚合根的引用,那么应该为其定义**详细**DTO.
**推荐** 如果实体持有对其他聚合根的引用,那么应该为其定义**详细**DTO.
* 直接包含实体中所有的 **原始属性**.
- 例外-1: 出于**安全**原因,可以**排除**某些属性(像 `User.Password`).

2
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)

8
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}"
}
}

2
samples/MicroserviceDemo/_run/01_AuthServer.ps1

@ -0,0 +1,2 @@
cd ../applications/AuthServer.Host
dotnet run

2
samples/MicroserviceDemo/_run/02_IdentityService.ps1

@ -0,0 +1,2 @@
cd ../microservices/IdentityService.Host
dotnet run

2
samples/MicroserviceDemo/_run/03_BloggingService.ps1

@ -0,0 +1,2 @@
cd ../microservices/BloggingService.Host
dotnet run

2
samples/MicroserviceDemo/_run/04_ProductService.ps1

@ -0,0 +1,2 @@
cd ../microservices/ProductService.Host
dotnet run

2
samples/MicroserviceDemo/_run/05_InternalGateway.ps1

@ -0,0 +1,2 @@
cd ../gateways/InternalGateway.Host
dotnet run

2
samples/MicroserviceDemo/_run/06_BackendAdminAppGateway.ps1

@ -0,0 +1,2 @@
cd ../gateways/BackendAdminAppGateway.Host
dotnet run

2
samples/MicroserviceDemo/_run/07_PublicWebSiteGateway.ps1

@ -0,0 +1,2 @@
cd ../gateways/PublicWebSiteGateway.Host
dotnet run

2
samples/MicroserviceDemo/_run/08_BackendAdminApp.ps1

@ -0,0 +1,2 @@
cd ../applications/BackendAdminApp.Host
dotnet run

2
samples/MicroserviceDemo/_run/09_PublicWebSite.ps1

@ -0,0 +1,2 @@
cd ../applications/PublicWebSite.Host
dotnet run

2
samples/MicroserviceDemo/_run/10_ConsoleClientDemo.ps1

@ -0,0 +1,2 @@
cd ../applications/ConsoleClientDemo
dotnet run

19
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)

9
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

1
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

2
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"
}

2
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"
}

2
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"
}

29
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<ICurrentPrincipalAccessor>();
var map = new Dictionary<string, string>()
{
{ "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 =>
{

2
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"
}

29
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<ICurrentPrincipalAccessor>();
var map = new Dictionary<string, string>()
{
{ "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 =>
{

2
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"
}

2
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"
}

29
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<ICurrentPrincipalAccessor>();
var map = new Dictionary<string, string>()
{
{ "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 =>
{

27
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<ICurrentPrincipalAccessor>();
var map = new Dictionary<string, string>()
{
{ "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 =>

2
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"
}

29
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<ICurrentPrincipalAccessor>();
var map = new Dictionary<string, string>()
{
{ "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 =>

2
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"
}

29
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<ICurrentPrincipalAccessor>();
var map = new Dictionary<string, string>()
{
{ "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 =>

2
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"
}

Loading…
Cancel
Save