From c3aa39d6d32e819dc05fd05dd86db7d84c8058e5 Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Tue, 5 Oct 2021 15:57:11 +0300 Subject: [PATCH 01/11] Added OcelotConfiguration file --- .../OcelotConfiguration.cs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 shared/EShopOnAbp.Shared.Hosting.Gateways/OcelotConfiguration.cs diff --git a/shared/EShopOnAbp.Shared.Hosting.Gateways/OcelotConfiguration.cs b/shared/EShopOnAbp.Shared.Hosting.Gateways/OcelotConfiguration.cs new file mode 100644 index 00000000..12b69886 --- /dev/null +++ b/shared/EShopOnAbp.Shared.Hosting.Gateways/OcelotConfiguration.cs @@ -0,0 +1,20 @@ +using System.Collections.Generic; + +namespace EShopOnAbp.Shared.Hosting.Gateways +{ + public class OcelotConfiguration + { + public string ServiceName { get; set; } + public string DownstreamPathTemplate { get; set; } + public string DownstreamScheme { get; set; } + public string UpstreamPathTemplate { get; set; } + public List UpstreamHttpMethod { get; set; } + public List DownstreamHostAndPorts { get; set; } + } + + public class HostAndPort + { + public string Host { get; set; } + public int Port { get; set; } + } +} \ No newline at end of file From fbcfe6cfef6713f893e2b462be45edd2068084be Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Tue, 5 Oct 2021 15:57:56 +0300 Subject: [PATCH 02/11] Added consul --- .../EShopOnAbp.Shared.Hosting.Gateways.csproj | 1 + .../EShopOnAbpSharedHostingGatewaysModule.cs | 2 ++ 2 files changed, 3 insertions(+) diff --git a/shared/EShopOnAbp.Shared.Hosting.Gateways/EShopOnAbp.Shared.Hosting.Gateways.csproj b/shared/EShopOnAbp.Shared.Hosting.Gateways/EShopOnAbp.Shared.Hosting.Gateways.csproj index 50f7c15c..0ad22634 100644 --- a/shared/EShopOnAbp.Shared.Hosting.Gateways/EShopOnAbp.Shared.Hosting.Gateways.csproj +++ b/shared/EShopOnAbp.Shared.Hosting.Gateways/EShopOnAbp.Shared.Hosting.Gateways.csproj @@ -7,6 +7,7 @@ + diff --git a/shared/EShopOnAbp.Shared.Hosting.Gateways/EShopOnAbpSharedHostingGatewaysModule.cs b/shared/EShopOnAbp.Shared.Hosting.Gateways/EShopOnAbpSharedHostingGatewaysModule.cs index 614b7a11..57f8daa9 100644 --- a/shared/EShopOnAbp.Shared.Hosting.Gateways/EShopOnAbpSharedHostingGatewaysModule.cs +++ b/shared/EShopOnAbp.Shared.Hosting.Gateways/EShopOnAbpSharedHostingGatewaysModule.cs @@ -1,6 +1,7 @@ using EShopOnAbp.Shared.Hosting.AspNetCore; using Microsoft.Extensions.DependencyInjection; using Ocelot.DependencyInjection; +using Ocelot.Provider.Consul; using Ocelot.Provider.Polly; using Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy; using Volo.Abp.Modularity; @@ -20,6 +21,7 @@ namespace EShopOnAbp.Shared.Hosting.Gateways var configuration = context.Services.GetConfiguration(); context.Services.AddOcelot(configuration) + .AddConsul() .AddPolly(); } } From 82d06b9feeba029cb7eaa869b182a1ebc895ddb3 Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Tue, 5 Oct 2021 15:58:24 +0300 Subject: [PATCH 03/11] updated gateway configurations with service names --- .../src/EShopOnAbp.InternalGateway/appsettings.json | 7 +++++++ .../src/EShopOnAbp.WebPublicGateway/appsettings.json | 2 ++ gateways/web/src/EShopOnAbp.WebGateway/appsettings.json | 7 +++++++ 3 files changed, 16 insertions(+) diff --git a/gateways/internal/src/EShopOnAbp.InternalGateway/appsettings.json b/gateways/internal/src/EShopOnAbp.InternalGateway/appsettings.json index 91b520de..536ed6c5 100644 --- a/gateways/internal/src/EShopOnAbp.InternalGateway/appsettings.json +++ b/gateways/internal/src/EShopOnAbp.InternalGateway/appsettings.json @@ -18,6 +18,7 @@ "AllowedHosts": "*", "Routes": [ { + "ServiceName": "Identity Service", "DownstreamPathTemplate": "/api/identity/{everything}", "DownstreamScheme": "https", "DownstreamHostAndPorts": [ @@ -30,6 +31,7 @@ "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ] }, { + "ServiceName": "Administration Service", "DownstreamPathTemplate": "/api/account/{everything}", "DownstreamScheme": "https", "DownstreamHostAndPorts": [ @@ -42,6 +44,7 @@ "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ] }, { + "ServiceName": "Saas Service", "DownstreamPathTemplate": "/api/saas/{everything}", "DownstreamScheme": "https", "DownstreamHostAndPorts": [ @@ -54,6 +57,7 @@ "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ] }, { + "ServiceName": "Administration Service", "DownstreamPathTemplate": "/api/abp/{everything}", "DownstreamScheme": "https", "DownstreamHostAndPorts": [ @@ -66,6 +70,7 @@ "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ] }, { + "ServiceName": "Administration Service", "DownstreamPathTemplate": "/api/feature-management/{everything}", "DownstreamScheme": "https", "DownstreamHostAndPorts": [ @@ -78,6 +83,7 @@ "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ] }, { + "ServiceName": "Administration Service", "DownstreamPathTemplate": "/api/permission-management/{everything}", "DownstreamScheme": "https", "DownstreamHostAndPorts": [ @@ -90,6 +96,7 @@ "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ] }, { + "ServiceName": "Administration Service", "DownstreamPathTemplate": "/api/setting-management/{everything}", "DownstreamScheme": "https", "DownstreamHostAndPorts": [ diff --git a/gateways/web-public/src/EShopOnAbp.WebPublicGateway/appsettings.json b/gateways/web-public/src/EShopOnAbp.WebPublicGateway/appsettings.json index 4d945a08..229c363c 100644 --- a/gateways/web-public/src/EShopOnAbp.WebPublicGateway/appsettings.json +++ b/gateways/web-public/src/EShopOnAbp.WebPublicGateway/appsettings.json @@ -19,6 +19,7 @@ "AllowedHosts": "*", "Routes": [ { + "ServiceName": "Identity Service", "DownstreamPathTemplate": "/api/account/{everything}", "DownstreamScheme": "https", "DownstreamHostAndPorts": [ @@ -31,6 +32,7 @@ "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ] }, { + "ServiceName": "Administration Service", "DownstreamPathTemplate": "/api/abp/{everything}", "DownstreamScheme": "https", "DownstreamHostAndPorts": [ diff --git a/gateways/web/src/EShopOnAbp.WebGateway/appsettings.json b/gateways/web/src/EShopOnAbp.WebGateway/appsettings.json index e93436e2..c8e3a58e 100644 --- a/gateways/web/src/EShopOnAbp.WebGateway/appsettings.json +++ b/gateways/web/src/EShopOnAbp.WebGateway/appsettings.json @@ -19,6 +19,7 @@ "AllowedHosts": "*", "Routes": [ { + "ServiceName": "Identity Service", "DownstreamPathTemplate": "/api/identity/{everything}", "DownstreamScheme": "https", "DownstreamHostAndPorts": [ @@ -31,6 +32,7 @@ "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ] }, { + "ServiceName": "Identity Service", "DownstreamPathTemplate": "/api/account/{everything}", "DownstreamScheme": "https", "DownstreamHostAndPorts": [ @@ -43,6 +45,7 @@ "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ] }, { + "ServiceName": "Saas Service", "DownstreamPathTemplate": "/api/multi-tenancy/{everything}", "DownstreamScheme": "https", "DownstreamHostAndPorts": [ @@ -55,6 +58,7 @@ "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ] }, { + "ServiceName": "Administration Service", "DownstreamPathTemplate": "/api/abp/{everything}", "DownstreamScheme": "https", "DownstreamHostAndPorts": [ @@ -67,6 +71,7 @@ "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ] }, { + "ServiceName": "Administration Service", "DownstreamPathTemplate": "/api/feature-management/{everything}", "DownstreamScheme": "https", "DownstreamHostAndPorts": [ @@ -79,6 +84,7 @@ "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ] }, { + "ServiceName": "Administration Service", "DownstreamPathTemplate": "/api/permission-management/{everything}", "DownstreamScheme": "https", "DownstreamHostAndPorts": [ @@ -91,6 +97,7 @@ "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ] }, { + "ServiceName": "Administration Service", "DownstreamPathTemplate": "/api/setting-management/{everything}", "DownstreamScheme": "https", "DownstreamHostAndPorts": [ From f63d1db9ab8fa9063c6f76f1fd4d50980d74cc62 Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Tue, 5 Oct 2021 15:59:51 +0300 Subject: [PATCH 04/11] Added cors for gateway endpoints --- .../appsettings.json | 3 ++- .../EShopOnAbp.IdentityService.HttpApi.Host/appsettings.json | 3 ++- .../src/EShopOnAbp.SaasService.HttpApi.Host/appsettings.json | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/appsettings.json b/services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/appsettings.json index 1efa97e9..5298c316 100644 --- a/services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/appsettings.json +++ b/services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/appsettings.json @@ -1,6 +1,7 @@ { "App": { - "SelfUrl": "https://localhost:44353" + "SelfUrl": "https://localhost:44353", + "CorsOrigins": "https://localhost:44371,https://localhost:44372,https://localhost:44373" }, "AuthServer": { "Authority": "https://localhost:44330", diff --git a/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/appsettings.json b/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/appsettings.json index 0f39f591..f9ca551d 100644 --- a/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/appsettings.json +++ b/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/appsettings.json @@ -1,6 +1,7 @@ { "App": { - "SelfUrl": "https://localhost:44351" + "SelfUrl": "https://localhost:44351", + "CorsOrigins": "https://localhost:44371,https://localhost:44372,https://localhost:44373" }, "AuthServer": { "Authority": "https://localhost:44330", diff --git a/services/saas/src/EShopOnAbp.SaasService.HttpApi.Host/appsettings.json b/services/saas/src/EShopOnAbp.SaasService.HttpApi.Host/appsettings.json index 3757c456..25b7b4c1 100644 --- a/services/saas/src/EShopOnAbp.SaasService.HttpApi.Host/appsettings.json +++ b/services/saas/src/EShopOnAbp.SaasService.HttpApi.Host/appsettings.json @@ -1,6 +1,7 @@ { "App": { - "SelfUrl": "https://localhost:44352" + "SelfUrl": "https://localhost:44352", + "CorsOrigins": "https://localhost:44371,https://localhost:44372,https://localhost:44373" }, "AuthServer": { "Authority": "https://localhost:44330", From 46567d9b0c45c514abb0b8d59fad3435345afa79 Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Tue, 5 Oct 2021 16:38:37 +0300 Subject: [PATCH 05/11] swagger configuration moved to shared AspNetCore library --- .../SwaggerConfigurationHelper.cs | 42 +++++++++---------- .../SwaggerWithAuthConfigurationHelper.cs | 6 +-- 2 files changed, 24 insertions(+), 24 deletions(-) rename shared/{EShopOnAbp.Shared.Hosting.Microservices => EShopOnAbp.Shared.Hosting.AspNetCore}/SwaggerConfigurationHelper.cs (89%) rename shared/{EShopOnAbp.Shared.Hosting.Gateways => EShopOnAbp.Shared.Hosting.AspNetCore}/SwaggerWithAuthConfigurationHelper.cs (86%) diff --git a/shared/EShopOnAbp.Shared.Hosting.Microservices/SwaggerConfigurationHelper.cs b/shared/EShopOnAbp.Shared.Hosting.AspNetCore/SwaggerConfigurationHelper.cs similarity index 89% rename from shared/EShopOnAbp.Shared.Hosting.Microservices/SwaggerConfigurationHelper.cs rename to shared/EShopOnAbp.Shared.Hosting.AspNetCore/SwaggerConfigurationHelper.cs index 22dd7058..256828ef 100644 --- a/shared/EShopOnAbp.Shared.Hosting.Microservices/SwaggerConfigurationHelper.cs +++ b/shared/EShopOnAbp.Shared.Hosting.AspNetCore/SwaggerConfigurationHelper.cs @@ -1,22 +1,22 @@ -using Microsoft.Extensions.DependencyInjection; -using Microsoft.OpenApi.Models; -using Volo.Abp.Modularity; - -namespace EShopOnAbp.Shared.Hosting.Microservices -{ - public static class SwaggerConfigurationHelper - { - public static void Configure( - ServiceConfigurationContext context, - string apiTitle - ) - { - context.Services.AddSwaggerGen(options => - { - options.SwaggerDoc("v1", new OpenApiInfo {Title = apiTitle, Version = "v1"}); - options.DocInclusionPredicate((docName, description) => true); - options.CustomSchemaIds(type => type.FullName); - }); - } - } +using Microsoft.Extensions.DependencyInjection; +using Microsoft.OpenApi.Models; +using Volo.Abp.Modularity; + +namespace EShopOnAbp.Shared.Hosting.AspNetCore +{ + public static class SwaggerConfigurationHelper + { + public static void Configure( + ServiceConfigurationContext context, + string apiTitle + ) + { + context.Services.AddSwaggerGen(options => + { + options.SwaggerDoc("v1", new OpenApiInfo {Title = apiTitle, Version = "v1"}); + options.DocInclusionPredicate((docName, description) => true); + options.CustomSchemaIds(type => type.FullName); + }); + } + } } \ No newline at end of file diff --git a/shared/EShopOnAbp.Shared.Hosting.Gateways/SwaggerWithAuthConfigurationHelper.cs b/shared/EShopOnAbp.Shared.Hosting.AspNetCore/SwaggerWithAuthConfigurationHelper.cs similarity index 86% rename from shared/EShopOnAbp.Shared.Hosting.Gateways/SwaggerWithAuthConfigurationHelper.cs rename to shared/EShopOnAbp.Shared.Hosting.AspNetCore/SwaggerWithAuthConfigurationHelper.cs index fe892a65..33ac56a8 100644 --- a/shared/EShopOnAbp.Shared.Hosting.Gateways/SwaggerWithAuthConfigurationHelper.cs +++ b/shared/EShopOnAbp.Shared.Hosting.AspNetCore/SwaggerWithAuthConfigurationHelper.cs @@ -1,9 +1,9 @@ -using Microsoft.Extensions.DependencyInjection; +using System.Collections.Generic; +using Microsoft.Extensions.DependencyInjection; using Microsoft.OpenApi.Models; -using System.Collections.Generic; using Volo.Abp.Modularity; -namespace EShopOnAbp.Shared.Hosting.Gateways +namespace EShopOnAbp.Shared.Hosting.AspNetCore { public static class SwaggerWithAuthConfigurationHelper { From dc502d36ee30efa40ed986821f92d8e435d685f6 Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Wed, 6 Oct 2021 10:51:46 +0300 Subject: [PATCH 06/11] Moved AbpSwashbuckle to shared AspNetCore module --- .../EShopOnAbp.Shared.Hosting.AspNetCore.csproj | 1 + .../EShopOnAbpSharedHostingAspNetCoreModule.cs | 2 ++ .../EShopOnAbp.Shared.Hosting.Gateways.csproj | 1 - .../EShopOnAbpSharedHostingGatewaysModule.cs | 1 - 4 files changed, 3 insertions(+), 2 deletions(-) diff --git a/shared/EShopOnAbp.Shared.Hosting.AspNetCore/EShopOnAbp.Shared.Hosting.AspNetCore.csproj b/shared/EShopOnAbp.Shared.Hosting.AspNetCore/EShopOnAbp.Shared.Hosting.AspNetCore.csproj index 34b2eea5..08bdd32e 100644 --- a/shared/EShopOnAbp.Shared.Hosting.AspNetCore/EShopOnAbp.Shared.Hosting.AspNetCore.csproj +++ b/shared/EShopOnAbp.Shared.Hosting.AspNetCore/EShopOnAbp.Shared.Hosting.AspNetCore.csproj @@ -9,6 +9,7 @@ + diff --git a/shared/EShopOnAbp.Shared.Hosting.AspNetCore/EShopOnAbpSharedHostingAspNetCoreModule.cs b/shared/EShopOnAbp.Shared.Hosting.AspNetCore/EShopOnAbpSharedHostingAspNetCoreModule.cs index 5457a486..d641b79d 100644 --- a/shared/EShopOnAbp.Shared.Hosting.AspNetCore/EShopOnAbpSharedHostingAspNetCoreModule.cs +++ b/shared/EShopOnAbp.Shared.Hosting.AspNetCore/EShopOnAbpSharedHostingAspNetCoreModule.cs @@ -1,10 +1,12 @@ using Volo.Abp.AspNetCore.Serilog; using Volo.Abp.Modularity; +using Volo.Abp.Swashbuckle; namespace EShopOnAbp.Shared.Hosting.AspNetCore { [DependsOn( typeof(EShopOnAbpSharedHostingModule), + typeof(AbpSwashbuckleModule), typeof(AbpAspNetCoreSerilogModule) )] public class EShopOnAbpSharedHostingAspNetCoreModule : AbpModule diff --git a/shared/EShopOnAbp.Shared.Hosting.Gateways/EShopOnAbp.Shared.Hosting.Gateways.csproj b/shared/EShopOnAbp.Shared.Hosting.Gateways/EShopOnAbp.Shared.Hosting.Gateways.csproj index 0ad22634..081e8ea2 100644 --- a/shared/EShopOnAbp.Shared.Hosting.Gateways/EShopOnAbp.Shared.Hosting.Gateways.csproj +++ b/shared/EShopOnAbp.Shared.Hosting.Gateways/EShopOnAbp.Shared.Hosting.Gateways.csproj @@ -11,7 +11,6 @@ - diff --git a/shared/EShopOnAbp.Shared.Hosting.Gateways/EShopOnAbpSharedHostingGatewaysModule.cs b/shared/EShopOnAbp.Shared.Hosting.Gateways/EShopOnAbpSharedHostingGatewaysModule.cs index 57f8daa9..c0227815 100644 --- a/shared/EShopOnAbp.Shared.Hosting.Gateways/EShopOnAbpSharedHostingGatewaysModule.cs +++ b/shared/EShopOnAbp.Shared.Hosting.Gateways/EShopOnAbpSharedHostingGatewaysModule.cs @@ -11,7 +11,6 @@ namespace EShopOnAbp.Shared.Hosting.Gateways { [DependsOn( typeof(EShopOnAbpSharedHostingAspNetCoreModule), - typeof(AbpSwashbuckleModule), typeof(AbpAspNetCoreMvcUiMultiTenancyModule) )] public class EShopOnAbpSharedHostingGatewaysModule : AbpModule From 55671fb266e70f8b4b24b0caaf52705e6a18f521 Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Wed, 6 Oct 2021 10:52:37 +0300 Subject: [PATCH 07/11] Removed swagger auth from gateways --- .../EShopOnAbpInternalGatewayModule.cs | 29 ++++++----- .../EShopOnAbpWebPublicGatewayModule.cs | 26 +++++----- .../EShopOnAbpWebGatewayModule.cs | 49 ++++++------------- 3 files changed, 42 insertions(+), 62 deletions(-) diff --git a/gateways/internal/src/EShopOnAbp.InternalGateway/EShopOnAbpInternalGatewayModule.cs b/gateways/internal/src/EShopOnAbp.InternalGateway/EShopOnAbpInternalGatewayModule.cs index d6fd6028..06558c29 100644 --- a/gateways/internal/src/EShopOnAbp.InternalGateway/EShopOnAbpInternalGatewayModule.cs +++ b/gateways/internal/src/EShopOnAbp.InternalGateway/EShopOnAbpInternalGatewayModule.cs @@ -8,6 +8,8 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Ocelot.Middleware; using System.Collections.Generic; +using System.Linq; +using EShopOnAbp.Shared.Hosting.AspNetCore; using Volo.Abp; using Volo.Abp.Modularity; @@ -25,18 +27,7 @@ namespace EShopOnAbp.InternalGateway { var configuration = context.Services.GetConfiguration(); var hostingEnvironment = context.Services.GetHostingEnvironment(); - - SwaggerWithAuthConfigurationHelper.Configure( - context: context, - authority: configuration["AuthServer:Authority"], - scopes: new Dictionary /* Requested scopes for authorization code request and descriptions for swagger UI only */ - { - {"IdentityService", "Identity Service API"}, - {"AdministrationService", "Administration Service API"}, - {"SaasService", "Saas Service API"}, - }, - apiTitle: "Internal Gateway API" - ); + SwaggerConfigurationHelper.Configure(context, "Internal Gateway"); } public override void OnApplicationInitialization(ApplicationInitializationContext context) @@ -53,10 +44,18 @@ namespace EShopOnAbp.InternalGateway app.UseSwagger(); app.UseSwaggerUI(options => { - options.SwaggerEndpoint("/swagger/v1/swagger.json", "Internal Gateway API"); var configuration = context.ServiceProvider.GetRequiredService(); - options.OAuthClientId(configuration["AuthServer:SwaggerClientId"]); - options.OAuthClientSecret(configuration["AuthServer:SwaggerClientSecret"]); + var routes = configuration.GetSection("Routes").Get>(); + + foreach (var config in routes.GroupBy(t => t.ServiceName).Select(r => r.First()).Distinct()) + { + var url = + $"{config.DownstreamScheme}://{config.DownstreamHostAndPorts.FirstOrDefault()?.Host}:{config.DownstreamHostAndPorts.FirstOrDefault()?.Port}"; + + options.SwaggerEndpoint($"{url}/swagger/v1/swagger.json", $"{config.ServiceName} API"); + options.OAuthClientId(configuration["AuthServer:SwaggerClientId"]); + options.OAuthClientSecret(configuration["AuthServer:SwaggerClientSecret"]); + } }); app.UseAbpSerilogEnrichers(); app.MapWhen( diff --git a/gateways/web-public/src/EShopOnAbp.WebPublicGateway/EShopOnAbpWebPublicGatewayModule.cs b/gateways/web-public/src/EShopOnAbp.WebPublicGateway/EShopOnAbpWebPublicGatewayModule.cs index 71917b2b..4aa892a3 100644 --- a/gateways/web-public/src/EShopOnAbp.WebPublicGateway/EShopOnAbpWebPublicGatewayModule.cs +++ b/gateways/web-public/src/EShopOnAbp.WebPublicGateway/EShopOnAbpWebPublicGatewayModule.cs @@ -5,6 +5,8 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Ocelot.Middleware; using System.Collections.Generic; +using System.Linq; +using EShopOnAbp.Shared.Hosting.AspNetCore; using Volo.Abp; using Volo.Abp.Account; using Volo.Abp.Modularity; @@ -21,15 +23,8 @@ namespace EShopOnAbp.WebPublicGateway { var configuration = context.Services.GetConfiguration(); var hostingEnvironment = context.Services.GetHostingEnvironment(); - - SwaggerWithAuthConfigurationHelper.Configure( - context: context, - authority: configuration["AuthServer:Authority"], - scopes: new Dictionary /* Requested scopes for authorization code request and descriptions for swagger UI only */ - { - }, - apiTitle: "WebPublic Gateway API" - ); + + SwaggerConfigurationHelper.Configure(context, "WebPublic Gateway"); } public override void OnApplicationInitialization(ApplicationInitializationContext context) @@ -46,10 +41,17 @@ namespace EShopOnAbp.WebPublicGateway app.UseSwagger(); app.UseSwaggerUI(options => { - options.SwaggerEndpoint("/swagger/v1/swagger.json", "Web Public Gateway API"); var configuration = context.ServiceProvider.GetRequiredService(); - options.OAuthClientId(configuration["AuthServer:SwaggerClientId"]); - options.OAuthClientSecret(configuration["AuthServer:SwaggerClientSecret"]); + var routes = configuration.GetSection("Routes").Get>(); + foreach (var config in routes.GroupBy(t => t.ServiceName).Select(r => r.First()).Distinct()) + { + var url = + $"{config.DownstreamScheme}://{config.DownstreamHostAndPorts.FirstOrDefault()?.Host}:{config.DownstreamHostAndPorts.FirstOrDefault()?.Port}"; + + options.SwaggerEndpoint($"{url}/swagger/v1/swagger.json", $"{config.ServiceName} API"); + options.OAuthClientId(configuration["AuthServer:SwaggerClientId"]); + options.OAuthClientSecret(configuration["AuthServer:SwaggerClientSecret"]); + } }); app.UseAbpSerilogEnrichers(); app.MapWhen( diff --git a/gateways/web/src/EShopOnAbp.WebGateway/EShopOnAbpWebGatewayModule.cs b/gateways/web/src/EShopOnAbp.WebGateway/EShopOnAbpWebGatewayModule.cs index 680ca239..9f23ad35 100644 --- a/gateways/web/src/EShopOnAbp.WebGateway/EShopOnAbpWebGatewayModule.cs +++ b/gateways/web/src/EShopOnAbp.WebGateway/EShopOnAbpWebGatewayModule.cs @@ -11,6 +11,8 @@ using Ocelot.Middleware; using System; using System.Collections.Generic; using System.Linq; +using EShopOnAbp.Shared.Hosting.AspNetCore; +using Microsoft.OpenApi.Models; using Volo.Abp; using Volo.Abp.Modularity; @@ -28,37 +30,7 @@ namespace EShopOnAbp.WebGateway { var configuration = context.Services.GetConfiguration(); var hostingEnvironment = context.Services.GetHostingEnvironment(); - - SwaggerWithAuthConfigurationHelper.Configure( - context: context, - authority: configuration["AuthServer:Authority"], - scopes: new Dictionary /* Requested scopes for authorization code request and descriptions for swagger UI only */ - { - {"IdentityService", "Identity Service API"}, - {"AdministrationService", "Administration Service API"}, - {"SaasService", "Saas Service API"}, - }, - apiTitle: "Web Gateway API" - ); - - context.Services.AddCors(options => - { - options.AddDefaultPolicy(builder => - { - builder - .WithOrigins( - configuration["App:CorsOrigins"] - .Split(",", StringSplitOptions.RemoveEmptyEntries) - .Select(o => o.Trim().RemovePostFix("/")) - .ToArray() - ) - .WithAbpExposedHeaders() - .SetIsOriginAllowedToAllowWildcardSubdomains() - .AllowAnyHeader() - .AllowAnyMethod() - .AllowCredentials(); - }); - }); + SwaggerConfigurationHelper.Configure(context, "Web Gateway"); } public override void OnApplicationInitialization(ApplicationInitializationContext context) @@ -72,14 +44,21 @@ namespace EShopOnAbp.WebGateway } app.UseCorrelationId(); - app.UseCors(); app.UseSwagger(); app.UseSwaggerUI(options => { - options.SwaggerEndpoint("/swagger/v1/swagger.json", "Web Gateway API"); var configuration = context.ServiceProvider.GetRequiredService(); - options.OAuthClientId(configuration["AuthServer:SwaggerClientId"]); - options.OAuthClientSecret(configuration["AuthServer:SwaggerClientSecret"]); + var routes = configuration.GetSection("Routes").Get>(); + + foreach (var config in routes.GroupBy(t => t.ServiceName).Select(r => r.First()).Distinct()) + { + var url = + $"{config.DownstreamScheme}://{config.DownstreamHostAndPorts.FirstOrDefault()?.Host}:{config.DownstreamHostAndPorts.FirstOrDefault()?.Port}"; + + options.SwaggerEndpoint($"{url}/swagger/v1/swagger.json", $"{config.ServiceName} API"); + options.OAuthClientId(configuration["AuthServer:SwaggerClientId"]); + options.OAuthClientSecret(configuration["AuthServer:SwaggerClientSecret"]); + } }); app.UseAbpSerilogEnrichers(); app.MapWhen( From bcc7f6a32f5910e90ba53f33bd7a76ffd80c117a Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Wed, 6 Oct 2021 10:53:00 +0300 Subject: [PATCH 08/11] Removed swagger auth config and service name fix --- .../src/EShopOnAbp.InternalGateway/appsettings.json | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/gateways/internal/src/EShopOnAbp.InternalGateway/appsettings.json b/gateways/internal/src/EShopOnAbp.InternalGateway/appsettings.json index 536ed6c5..9c1f87e5 100644 --- a/gateways/internal/src/EShopOnAbp.InternalGateway/appsettings.json +++ b/gateways/internal/src/EShopOnAbp.InternalGateway/appsettings.json @@ -2,12 +2,6 @@ "App": { "SelfUrl": "https://localhost:44371" }, - "AuthServer": { - "Authority": "https://localhost:44330", - "RequireHttpsMetadata": "true", - "SwaggerClientId": "InternalGateway_Swagger", - "SwaggerClientSecret": "1q2w3e*" - }, "Logging": { "LogLevel": { "Default": "Information", @@ -31,7 +25,7 @@ "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ] }, { - "ServiceName": "Administration Service", + "ServiceName": "Identity Service", "DownstreamPathTemplate": "/api/account/{everything}", "DownstreamScheme": "https", "DownstreamHostAndPorts": [ From 268a0b64b54b7e0092bf096f1755046b985c335b Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Wed, 6 Oct 2021 10:55:41 +0300 Subject: [PATCH 09/11] Microservice swagger auth configurations --- .../AdministrationServiceHttpApiHostModule.cs | 39 ++++++++++++++++++- .../appsettings.json | 4 +- .../appsettings.json | 4 +- .../SaasServiceHttpApiHostModule.cs | 34 +++++++++++++++- .../appsettings.json | 4 +- 5 files changed, 80 insertions(+), 5 deletions(-) diff --git a/services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/AdministrationServiceHttpApiHostModule.cs b/services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/AdministrationServiceHttpApiHostModule.cs index afc8ab09..2e64a6ab 100644 --- a/services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/AdministrationServiceHttpApiHostModule.cs +++ b/services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/AdministrationServiceHttpApiHostModule.cs @@ -1,8 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; using EShopOnAbp.AdministrationService.DbMigrations; using EShopOnAbp.AdministrationService.EntityFrameworkCore; using EShopOnAbp.SaasService; +using EShopOnAbp.Shared.Hosting.AspNetCore; using EShopOnAbp.Shared.Hosting.Microservices; using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Cors; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Volo.Abp; @@ -31,8 +36,39 @@ namespace EShopOnAbp.AdministrationService { public override void ConfigureServices(ServiceConfigurationContext context) { + var configuration = context.Services.GetConfiguration(); + JwtBearerConfigurationHelper.Configure(context, "AdministrationService"); - SwaggerConfigurationHelper.Configure(context, "Administration Service API"); + // SwaggerConfigurationHelper.Configure(context, "Administration Service API"); + + SwaggerWithAuthConfigurationHelper.Configure( + context: context, + authority: configuration["AuthServer:Authority"], + scopes: new Dictionary /* Requested scopes for authorization code request and descriptions for swagger UI only */ + { + {"Administration", "Administration Service API"}, + }, + apiTitle: "Administration Service API" + ); + + context.Services.AddCors(options => + { + options.AddDefaultPolicy(builder => + { + builder + .WithOrigins( + configuration["App:CorsOrigins"] + .Split(",", StringSplitOptions.RemoveEmptyEntries) + .Select(o => o.Trim().RemovePostFix("/")) + .ToArray() + ) + .WithAbpExposedHeaders() + .SetIsOriginAllowedToAllowWildcardSubdomains() + .AllowAnyHeader() + .AllowAnyMethod() + .AllowCredentials(); + }); + }); } public override void OnApplicationInitialization(ApplicationInitializationContext context) { @@ -45,6 +81,7 @@ namespace EShopOnAbp.AdministrationService } app.UseCorrelationId(); + app.UseCors(); app.UseAbpRequestLocalization(); app.UseStaticFiles(); app.UseRouting(); diff --git a/services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/appsettings.json b/services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/appsettings.json index 5298c316..0bb09d1e 100644 --- a/services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/appsettings.json +++ b/services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/appsettings.json @@ -5,7 +5,9 @@ }, "AuthServer": { "Authority": "https://localhost:44330", - "RequireHttpsMetadata": "true" + "RequireHttpsMetadata": "true", + "SwaggerClientId": "AdministrationService_Swagger", + "SwaggerClientSecret": "1q2w3e*" }, "RemoteServices": { "Default": { diff --git a/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/appsettings.json b/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/appsettings.json index f9ca551d..5a226ea8 100644 --- a/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/appsettings.json +++ b/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/appsettings.json @@ -5,7 +5,9 @@ }, "AuthServer": { "Authority": "https://localhost:44330", - "RequireHttpsMetadata": "true" + "RequireHttpsMetadata": "true", + "SwaggerClientId": "IdentityService_Swagger", + "SwaggerClientSecret": "1q2w3e*" }, "Logging": { "LogLevel": { diff --git a/services/saas/src/EShopOnAbp.SaasService.HttpApi.Host/SaasServiceHttpApiHostModule.cs b/services/saas/src/EShopOnAbp.SaasService.HttpApi.Host/SaasServiceHttpApiHostModule.cs index a748904c..a635fe06 100644 --- a/services/saas/src/EShopOnAbp.SaasService.HttpApi.Host/SaasServiceHttpApiHostModule.cs +++ b/services/saas/src/EShopOnAbp.SaasService.HttpApi.Host/SaasServiceHttpApiHostModule.cs @@ -10,6 +10,7 @@ using Microsoft.AspNetCore.DataProtection; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using EShopOnAbp.SaasService.EntityFrameworkCore; +using EShopOnAbp.Shared.Hosting.AspNetCore; using EShopOnAbp.Shared.Hosting.Microservices; using StackExchange.Redis; using Microsoft.OpenApi.Models; @@ -34,10 +35,40 @@ namespace EShopOnAbp.SaasService { public override void ConfigureServices(ServiceConfigurationContext context) { + var configuration = context.Services.GetConfiguration(); context.Services.AddAbpDbContext(); JwtBearerConfigurationHelper.Configure(context, "SaasService"); - SwaggerConfigurationHelper.Configure(context, "Saas Service API"); + // SwaggerConfigurationHelper.Configure(context, "Saas Service API"); + + SwaggerWithAuthConfigurationHelper.Configure( + context: context, + authority: configuration["AuthServer:Authority"], + scopes: new Dictionary /* Requested scopes for authorization code request and descriptions for swagger UI only */ + { + {"SaasService", "Saas Service API"}, + }, + apiTitle: "Saas Service API" + ); + + context.Services.AddCors(options => + { + options.AddDefaultPolicy(builder => + { + builder + .WithOrigins( + configuration["App:CorsOrigins"] + .Split(",", StringSplitOptions.RemoveEmptyEntries) + .Select(o => o.Trim().RemovePostFix("/")) + .ToArray() + ) + .WithAbpExposedHeaders() + .SetIsOriginAllowedToAllowWildcardSubdomains() + .AllowAnyHeader() + .AllowAnyMethod() + .AllowCredentials(); + }); + }); } public override void OnApplicationInitialization(ApplicationInitializationContext context) @@ -51,6 +82,7 @@ namespace EShopOnAbp.SaasService } app.UseCorrelationId(); + app.UseCors(); app.UseAbpRequestLocalization(); app.UseStaticFiles(); app.UseRouting(); diff --git a/services/saas/src/EShopOnAbp.SaasService.HttpApi.Host/appsettings.json b/services/saas/src/EShopOnAbp.SaasService.HttpApi.Host/appsettings.json index 25b7b4c1..7f8b284a 100644 --- a/services/saas/src/EShopOnAbp.SaasService.HttpApi.Host/appsettings.json +++ b/services/saas/src/EShopOnAbp.SaasService.HttpApi.Host/appsettings.json @@ -5,7 +5,9 @@ }, "AuthServer": { "Authority": "https://localhost:44330", - "RequireHttpsMetadata": "true" + "RequireHttpsMetadata": "true", + "SwaggerClientId": "IdentityService_Swagger", + "SwaggerClientSecret": "1q2w3e*" }, "Logging": { "LogLevel": { From 6429f46165efed3ac903b649ad49ac4784ae4fe1 Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Wed, 6 Oct 2021 10:56:44 +0300 Subject: [PATCH 10/11] Dataseeder update --- .../DbMigrations/IdentityServerDataSeeder.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServerDataSeeder.cs b/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServerDataSeeder.cs index da93e1c8..064ec572 100644 --- a/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServerDataSeeder.cs +++ b/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServerDataSeeder.cs @@ -97,10 +97,10 @@ namespace EShopOnAbp.IdentityService.DbMigrations private async Task CreateSwaggerClientsAsync() { - await CreateSwaggerClientAsync("InternalGateway", - new[] { "IdentityService", "AdministrationService", "SaasService" }); - await CreateSwaggerClientAsync("WebGateway", - new[] { "IdentityService", "AdministrationService", "SaasService" }); + await CreateSwaggerClientAsync("IdentityService", + new[] { "IdentityService"}); + await CreateSwaggerClientAsync("AdministrationService", + new[] { "AdministrationService" }); await CreateSwaggerClientAsync("WebPublicGateway"); } From a3a736a36576b1a06c78c62ba4821e274546f506 Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Wed, 6 Oct 2021 10:57:08 +0300 Subject: [PATCH 11/11] Added swagger auth to identity service --- ...pOnAbp.IdentityService.HttpApi.Host.csproj | 1 + .../IdentityServiceHttpApiHostModule.cs | 40 ++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/EShopOnAbp.IdentityService.HttpApi.Host.csproj b/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/EShopOnAbp.IdentityService.HttpApi.Host.csproj index d4b1ac1c..ffeb26e8 100644 --- a/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/EShopOnAbp.IdentityService.HttpApi.Host.csproj +++ b/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/EShopOnAbp.IdentityService.HttpApi.Host.csproj @@ -13,6 +13,7 @@ + diff --git a/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/IdentityServiceHttpApiHostModule.cs b/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/IdentityServiceHttpApiHostModule.cs index 2f70a5ae..80122c46 100644 --- a/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/IdentityServiceHttpApiHostModule.cs +++ b/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/IdentityServiceHttpApiHostModule.cs @@ -1,7 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; using EShopOnAbp.IdentityService.DbMigrations; using EShopOnAbp.IdentityService.EntityFrameworkCore; +using EShopOnAbp.Shared.Hosting.AspNetCore; +using EShopOnAbp.Shared.Hosting.Gateways; using EShopOnAbp.Shared.Hosting.Microservices; using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Cors; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Volo.Abp; @@ -15,7 +21,8 @@ namespace EShopOnAbp.IdentityService typeof(EShopOnAbpSharedHostingMicroservicesModule), typeof(IdentityServiceHttpApiModule), typeof(IdentityServiceApplicationModule), - typeof(IdentityServiceEntityFrameworkCoreModule) + typeof(IdentityServiceEntityFrameworkCoreModule), + typeof(EShopOnAbpSharedHostingGatewaysModule) )] public class IdentityServiceHttpApiHostModule : AbpModule { @@ -25,7 +32,35 @@ namespace EShopOnAbp.IdentityService var hostingEnvironment = context.Services.GetHostingEnvironment(); JwtBearerConfigurationHelper.Configure(context, "IdentityService"); - SwaggerConfigurationHelper.Configure(context, "Identity Service API"); + // SwaggerConfigurationHelper.Configure(context, "Identity Service API"); + context.Services.AddCors(options => + { + options.AddDefaultPolicy(builder => + { + builder + .WithOrigins( + configuration["App:CorsOrigins"] + .Split(",", StringSplitOptions.RemoveEmptyEntries) + .Select(o => o.Trim().RemovePostFix("/")) + .ToArray() + ) + .WithAbpExposedHeaders() + .SetIsOriginAllowedToAllowWildcardSubdomains() + .AllowAnyHeader() + .AllowAnyMethod() + .AllowCredentials(); + }); + }); + + SwaggerWithAuthConfigurationHelper.Configure( + context: context, + authority: configuration["AuthServer:Authority"], + scopes: new Dictionary /* Requested scopes for authorization code request and descriptions for swagger UI only */ + { + {"IdentityService", "Identity Service API"} + }, + apiTitle: "IdentityService Gateway API" + ); } public override void OnApplicationInitialization(ApplicationInitializationContext context) @@ -39,6 +74,7 @@ namespace EShopOnAbp.IdentityService } app.UseCorrelationId(); + app.UseCors(); app.UseAbpRequestLocalization(); app.UseStaticFiles(); app.UseRouting();