From ca246162efed31c5df93f931c1030873aebe8a1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Wed, 4 Mar 2020 18:29:18 +0300 Subject: [PATCH] Authorize clients for tenant management service, configure gateways and make the console client demo working. --- .../AuthServer.Host/AuthServer.Host.csproj | 1 + .../AuthServer.Host/AuthServerDataSeeder.cs | 7 ++-- .../AuthServer.Host/AuthServerHostModule.cs | 6 ++-- .../ConsoleClientDemo/ClientDemoService.cs | 36 ++++++++++++++++++- .../ConsoleClientDemo.csproj | 1 + .../ConsoleClientDemoModule.cs | 4 ++- .../ConsoleClientDemo/appsettings.json | 2 +- .../appsettings.json | 12 +++++++ .../InternalGateway.Host.csproj | 1 + .../InternalGatewayHostModule.cs | 4 ++- .../InternalGateway.Host/appsettings.json | 12 +++++++ .../Properties/launchSettings.json | 2 +- 12 files changed, 78 insertions(+), 10 deletions(-) diff --git a/samples/MicroserviceDemo/applications/AuthServer.Host/AuthServer.Host.csproj b/samples/MicroserviceDemo/applications/AuthServer.Host/AuthServer.Host.csproj index 766d8bc2d4..8ff54297fd 100644 --- a/samples/MicroserviceDemo/applications/AuthServer.Host/AuthServer.Host.csproj +++ b/samples/MicroserviceDemo/applications/AuthServer.Host/AuthServer.Host.csproj @@ -33,6 +33,7 @@ + diff --git a/samples/MicroserviceDemo/applications/AuthServer.Host/AuthServerDataSeeder.cs b/samples/MicroserviceDemo/applications/AuthServer.Host/AuthServerDataSeeder.cs index 835e55cf49..7b07a0eb8c 100644 --- a/samples/MicroserviceDemo/applications/AuthServer.Host/AuthServerDataSeeder.cs +++ b/samples/MicroserviceDemo/applications/AuthServer.Host/AuthServerDataSeeder.cs @@ -10,6 +10,7 @@ using Volo.Abp.IdentityServer.ApiResources; using Volo.Abp.IdentityServer.Clients; using Volo.Abp.IdentityServer.IdentityResources; using Volo.Abp.PermissionManagement; +using Volo.Abp.TenantManagement; using Volo.Abp.Uow; namespace AuthServer.Host @@ -107,15 +108,15 @@ namespace AuthServer.Host await CreateClientAsync( "console-client-demo", - new[] { "BloggingService", "IdentityService", "InternalGateway", "ProductService" }, + new[] { "BloggingService", "IdentityService", "InternalGateway", "ProductService", "TenantManagementService" }, new[] { "client_credentials", "password" }, commonSecret, - permissions: new[] { IdentityPermissions.Users.Default, "ProductManagement.Product" } + permissions: new[] { IdentityPermissions.Users.Default, TenantManagementPermissions.Tenants.Default, "ProductManagement.Product" } ); await CreateClientAsync( "backend-admin-app-client", - commonScopes.Union(new[] { "BackendAdminAppGateway", "IdentityService", "ProductService" }), + commonScopes.Union(new[] { "BackendAdminAppGateway", "IdentityService", "ProductService", "TenantManagementService" }), new[] { "hybrid" }, commonSecret, permissions: new[] { IdentityPermissions.Users.Default, "ProductManagement.Product" }, diff --git a/samples/MicroserviceDemo/applications/AuthServer.Host/AuthServerHostModule.cs b/samples/MicroserviceDemo/applications/AuthServer.Host/AuthServerHostModule.cs index 55747a5f87..6b4bec75af 100644 --- a/samples/MicroserviceDemo/applications/AuthServer.Host/AuthServerHostModule.cs +++ b/samples/MicroserviceDemo/applications/AuthServer.Host/AuthServerHostModule.cs @@ -22,6 +22,7 @@ using Volo.Abp.Modularity; using Volo.Abp.MultiTenancy; using Volo.Abp.PermissionManagement.EntityFrameworkCore; using Volo.Abp.SettingManagement.EntityFrameworkCore; +using Volo.Abp.TenantManagement; using Volo.Abp.TenantManagement.EntityFrameworkCore; using Volo.Abp.Threading; @@ -40,8 +41,9 @@ namespace AuthServer.Host typeof(AbpEntityFrameworkCoreSqlServerModule), typeof(AbpAccountWebIdentityServerModule), typeof(AbpAspNetCoreMvcUiBasicThemeModule), - typeof(AbpTenantManagementEntityFrameworkCoreModule) - )] + typeof(AbpTenantManagementEntityFrameworkCoreModule), + typeof(AbpTenantManagementApplicationContractsModule) + )] public class AuthServerHostModule : AbpModule { public override void ConfigureServices(ServiceConfigurationContext context) diff --git a/samples/MicroserviceDemo/applications/ConsoleClientDemo/ClientDemoService.cs b/samples/MicroserviceDemo/applications/ConsoleClientDemo/ClientDemoService.cs index 6083368d3e..e13bccd88d 100644 --- a/samples/MicroserviceDemo/applications/ConsoleClientDemo/ClientDemoService.cs +++ b/samples/MicroserviceDemo/applications/ConsoleClientDemo/ClientDemoService.cs @@ -7,12 +7,14 @@ using Volo.Abp.DependencyInjection; using Volo.Abp.Http.Client; using Volo.Abp.Identity; using Volo.Abp.IdentityModel; +using Volo.Abp.TenantManagement; namespace ConsoleClientDemo { public class ClientDemoService : ITransientDependency { private readonly IIdentityUserAppService _userAppService; + private readonly ITenantAppService _tenantAppService; private readonly IProductAppService _productAppService; private readonly IIdentityModelAuthenticationService _authenticator; private readonly AbpRemoteServiceOptions _remoteServiceOptions; @@ -21,10 +23,12 @@ namespace ConsoleClientDemo IIdentityUserAppService userAppService, IProductAppService productAppService, IIdentityModelAuthenticationService authenticator, - IOptions remoteServiceOptions) + IOptions remoteServiceOptions, + ITenantAppService tenantAppService) { _userAppService = userAppService; _authenticator = authenticator; + _tenantAppService = tenantAppService; _remoteServiceOptions = remoteServiceOptions.Value; _productAppService = productAppService; } @@ -33,6 +37,7 @@ namespace ConsoleClientDemo { await TestWithHttpClient(); await TestIdentityService(); + await TestTenantManagementService(); await TestProductService(); } @@ -101,6 +106,35 @@ namespace ConsoleClientDemo } } + /// + /// Shows how to use application service interfaces (ITenantAppService in this sample) + /// to call a remote service which is possible by the dynamic http client proxy system. + /// No need to use IIdentityModelAuthenticationService since the dynamic http client proxy + /// system internally uses it. You just inject a service (ITenantAppService) + /// and call a method (GetListAsync) like a local method. + /// + private async Task TestTenantManagementService() + { + Console.WriteLine(); + Console.WriteLine("*** TestTenantManagementService ************************************"); + + try + { + var output = await _tenantAppService.GetListAsync(new GetTenantsInput()); + + Console.WriteLine("Total tenant count: " + output.TotalCount); + + foreach (var tenant in output.Items) + { + Console.WriteLine($"- Id={tenant.Id}, Name={tenant.Name}"); + } + } + catch (Exception e) + { + Console.WriteLine(e); + } + } + /// /// Shows how to use application service interfaces (IProductAppService in this sample) /// to call a remote service which is possible by the dynamic http client proxy system. diff --git a/samples/MicroserviceDemo/applications/ConsoleClientDemo/ConsoleClientDemo.csproj b/samples/MicroserviceDemo/applications/ConsoleClientDemo/ConsoleClientDemo.csproj index 2443f75e5d..9e75f902e8 100644 --- a/samples/MicroserviceDemo/applications/ConsoleClientDemo/ConsoleClientDemo.csproj +++ b/samples/MicroserviceDemo/applications/ConsoleClientDemo/ConsoleClientDemo.csproj @@ -14,6 +14,7 @@ + diff --git a/samples/MicroserviceDemo/applications/ConsoleClientDemo/ConsoleClientDemoModule.cs b/samples/MicroserviceDemo/applications/ConsoleClientDemo/ConsoleClientDemoModule.cs index c69902ee19..86ef487e53 100644 --- a/samples/MicroserviceDemo/applications/ConsoleClientDemo/ConsoleClientDemoModule.cs +++ b/samples/MicroserviceDemo/applications/ConsoleClientDemo/ConsoleClientDemoModule.cs @@ -3,6 +3,7 @@ using Volo.Abp.Autofac; using Volo.Abp.Http.Client.IdentityModel; using Volo.Abp.Identity; using Volo.Abp.Modularity; +using Volo.Abp.TenantManagement; namespace ConsoleClientDemo { @@ -10,7 +11,8 @@ namespace ConsoleClientDemo typeof(AbpAutofacModule), typeof(AbpHttpClientIdentityModelModule), typeof(AbpIdentityHttpApiClientModule), - typeof(ProductManagementHttpApiClientModule) + typeof(ProductManagementHttpApiClientModule), + typeof(AbpTenantManagementHttpApiClientModule) )] public class ConsoleClientDemoModule : AbpModule { diff --git a/samples/MicroserviceDemo/applications/ConsoleClientDemo/appsettings.json b/samples/MicroserviceDemo/applications/ConsoleClientDemo/appsettings.json index 336020aec8..58043efa85 100644 --- a/samples/MicroserviceDemo/applications/ConsoleClientDemo/appsettings.json +++ b/samples/MicroserviceDemo/applications/ConsoleClientDemo/appsettings.json @@ -10,7 +10,7 @@ "ClientId": "console-client-demo", "ClientSecret": "1q2w3e*", "Authority": "http://localhost:64999", - "Scope": "InternalGateway IdentityService ProductService" + "Scope": "InternalGateway IdentityService ProductService TenantManagementService" } } } \ No newline at end of file diff --git a/samples/MicroserviceDemo/gateways/BackendAdminAppGateway.Host/appsettings.json b/samples/MicroserviceDemo/gateways/BackendAdminAppGateway.Host/appsettings.json index 3e6f45b15a..d29e87a577 100644 --- a/samples/MicroserviceDemo/gateways/BackendAdminAppGateway.Host/appsettings.json +++ b/samples/MicroserviceDemo/gateways/BackendAdminAppGateway.Host/appsettings.json @@ -30,6 +30,18 @@ "UpstreamPathTemplate": "/api/identity/{everything}", "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ] }, + { + "DownstreamPathTemplate": "/api/multi-tenancy/{everything}", + "DownstreamScheme": "http", + "DownstreamHostAndPorts": [ + { + "Host": "localhost", + "Port": 59835 + } + ], + "UpstreamPathTemplate": "/api/multi-tenancy/{everything}", + "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ] + }, { "DownstreamPathTemplate": "/api/productManagement/{everything}", "DownstreamScheme": "http", diff --git a/samples/MicroserviceDemo/gateways/InternalGateway.Host/InternalGateway.Host.csproj b/samples/MicroserviceDemo/gateways/InternalGateway.Host/InternalGateway.Host.csproj index c46183b709..5c2506f6c2 100644 --- a/samples/MicroserviceDemo/gateways/InternalGateway.Host/InternalGateway.Host.csproj +++ b/samples/MicroserviceDemo/gateways/InternalGateway.Host/InternalGateway.Host.csproj @@ -26,6 +26,7 @@ + diff --git a/samples/MicroserviceDemo/gateways/InternalGateway.Host/InternalGatewayHostModule.cs b/samples/MicroserviceDemo/gateways/InternalGateway.Host/InternalGatewayHostModule.cs index a3572551f9..01be78ca65 100644 --- a/samples/MicroserviceDemo/gateways/InternalGateway.Host/InternalGatewayHostModule.cs +++ b/samples/MicroserviceDemo/gateways/InternalGateway.Host/InternalGatewayHostModule.cs @@ -19,6 +19,7 @@ using Volo.Abp.Modularity; using Volo.Abp.PermissionManagement.EntityFrameworkCore; using Volo.Abp.Security.Claims; using Volo.Abp.SettingManagement.EntityFrameworkCore; +using Volo.Abp.TenantManagement; using Volo.Blogging; namespace InternalGateway.Host @@ -30,7 +31,8 @@ namespace InternalGateway.Host typeof(ProductManagementHttpApiModule), typeof(AbpEntityFrameworkCoreSqlServerModule), typeof(AbpPermissionManagementEntityFrameworkCoreModule), - typeof(AbpSettingManagementEntityFrameworkCoreModule) + typeof(AbpSettingManagementEntityFrameworkCoreModule), + typeof(AbpTenantManagementHttpApiModule) )] public class InternalGatewayHostModule : AbpModule { diff --git a/samples/MicroserviceDemo/gateways/InternalGateway.Host/appsettings.json b/samples/MicroserviceDemo/gateways/InternalGateway.Host/appsettings.json index c3863ac907..44ca565d47 100644 --- a/samples/MicroserviceDemo/gateways/InternalGateway.Host/appsettings.json +++ b/samples/MicroserviceDemo/gateways/InternalGateway.Host/appsettings.json @@ -25,6 +25,18 @@ "UpstreamPathTemplate": "/api/identity/{everything}", "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ] }, + { + "DownstreamPathTemplate": "/api/multi-tenancy/{everything}", + "DownstreamScheme": "http", + "DownstreamHostAndPorts": [ + { + "Host": "localhost", + "Port": 59835 + } + ], + "UpstreamPathTemplate": "/api/multi-tenancy/{everything}", + "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ] + }, { "DownstreamPathTemplate": "/api/productManagement/{everything}", "DownstreamScheme": "http", diff --git a/samples/MicroserviceDemo/microservices/TenantManagementService.Host/Properties/launchSettings.json b/samples/MicroserviceDemo/microservices/TenantManagementService.Host/Properties/launchSettings.json index 9c88d1143c..f763b95884 100644 --- a/samples/MicroserviceDemo/microservices/TenantManagementService.Host/Properties/launchSettings.json +++ b/samples/MicroserviceDemo/microservices/TenantManagementService.Host/Properties/launchSettings.json @@ -18,7 +18,7 @@ "TenantManagementService.Host": { "commandName": "Project", "launchBrowser": true, - "applicationUrl": "http://localhost:5000", + "applicationUrl": "http://localhost:59835", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" }