diff --git a/gateways/internal/src/EShopOnAbp.InternalGateway/EShopOnAbpInternalGatewayModule.cs b/gateways/internal/src/EShopOnAbp.InternalGateway/EShopOnAbpInternalGatewayModule.cs index 69df5f54..2f73ba66 100644 --- a/gateways/internal/src/EShopOnAbp.InternalGateway/EShopOnAbpInternalGatewayModule.cs +++ b/gateways/internal/src/EShopOnAbp.InternalGateway/EShopOnAbpInternalGatewayModule.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.Modularity; @@ -19,18 +21,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) @@ -47,10 +38,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/internal/src/EShopOnAbp.InternalGateway/appsettings.json b/gateways/internal/src/EShopOnAbp.InternalGateway/appsettings.json index 91b520de..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", @@ -18,6 +12,7 @@ "AllowedHosts": "*", "Routes": [ { + "ServiceName": "Identity Service", "DownstreamPathTemplate": "/api/identity/{everything}", "DownstreamScheme": "https", "DownstreamHostAndPorts": [ @@ -30,6 +25,7 @@ "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ] }, { + "ServiceName": "Identity Service", "DownstreamPathTemplate": "/api/account/{everything}", "DownstreamScheme": "https", "DownstreamHostAndPorts": [ @@ -42,6 +38,7 @@ "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ] }, { + "ServiceName": "Saas Service", "DownstreamPathTemplate": "/api/saas/{everything}", "DownstreamScheme": "https", "DownstreamHostAndPorts": [ @@ -54,6 +51,7 @@ "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ] }, { + "ServiceName": "Administration Service", "DownstreamPathTemplate": "/api/abp/{everything}", "DownstreamScheme": "https", "DownstreamHostAndPorts": [ @@ -66,6 +64,7 @@ "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ] }, { + "ServiceName": "Administration Service", "DownstreamPathTemplate": "/api/feature-management/{everything}", "DownstreamScheme": "https", "DownstreamHostAndPorts": [ @@ -78,6 +77,7 @@ "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ] }, { + "ServiceName": "Administration Service", "DownstreamPathTemplate": "/api/permission-management/{everything}", "DownstreamScheme": "https", "DownstreamHostAndPorts": [ @@ -90,6 +90,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/EShopOnAbpWebPublicGatewayModule.cs b/gateways/web-public/src/EShopOnAbp.WebPublicGateway/EShopOnAbpWebPublicGatewayModule.cs index 2b3aa805..4fe91f5f 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.Modularity; @@ -19,15 +21,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) @@ -44,10 +39,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-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/EShopOnAbpWebGatewayModule.cs b/gateways/web/src/EShopOnAbp.WebGateway/EShopOnAbpWebGatewayModule.cs index 41443f3a..ac8bc417 100644 --- a/gateways/web/src/EShopOnAbp.WebGateway/EShopOnAbpWebGatewayModule.cs +++ b/gateways/web/src/EShopOnAbp.WebGateway/EShopOnAbpWebGatewayModule.cs @@ -8,6 +8,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; @@ -22,37 +24,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) @@ -66,14 +38,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( 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": [ 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 1efa97e9..0bb09d1e 100644 --- a/services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/appsettings.json +++ b/services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/appsettings.json @@ -1,10 +1,13 @@ { "App": { - "SelfUrl": "https://localhost:44353" + "SelfUrl": "https://localhost:44353", + "CorsOrigins": "https://localhost:44371,https://localhost:44372,https://localhost:44373" }, "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/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"); } 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(); diff --git a/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/appsettings.json b/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/appsettings.json index 0f39f591..5a226ea8 100644 --- a/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/appsettings.json +++ b/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/appsettings.json @@ -1,10 +1,13 @@ { "App": { - "SelfUrl": "https://localhost:44351" + "SelfUrl": "https://localhost:44351", + "CorsOrigins": "https://localhost:44371,https://localhost:44372,https://localhost:44373" }, "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 3757c456..7f8b284a 100644 --- a/services/saas/src/EShopOnAbp.SaasService.HttpApi.Host/appsettings.json +++ b/services/saas/src/EShopOnAbp.SaasService.HttpApi.Host/appsettings.json @@ -1,10 +1,13 @@ { "App": { - "SelfUrl": "https://localhost:44352" + "SelfUrl": "https://localhost:44352", + "CorsOrigins": "https://localhost:44371,https://localhost:44372,https://localhost:44373" }, "AuthServer": { "Authority": "https://localhost:44330", - "RequireHttpsMetadata": "true" + "RequireHttpsMetadata": "true", + "SwaggerClientId": "IdentityService_Swagger", + "SwaggerClientSecret": "1q2w3e*" }, "Logging": { "LogLevel": { 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.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 { 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..081e8ea2 100644 --- a/shared/EShopOnAbp.Shared.Hosting.Gateways/EShopOnAbp.Shared.Hosting.Gateways.csproj +++ b/shared/EShopOnAbp.Shared.Hosting.Gateways/EShopOnAbp.Shared.Hosting.Gateways.csproj @@ -7,10 +7,10 @@ + - diff --git a/shared/EShopOnAbp.Shared.Hosting.Gateways/EShopOnAbpSharedHostingGatewaysModule.cs b/shared/EShopOnAbp.Shared.Hosting.Gateways/EShopOnAbpSharedHostingGatewaysModule.cs index 614b7a11..c0227815 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; @@ -10,7 +11,6 @@ namespace EShopOnAbp.Shared.Hosting.Gateways { [DependsOn( typeof(EShopOnAbpSharedHostingAspNetCoreModule), - typeof(AbpSwashbuckleModule), typeof(AbpAspNetCoreMvcUiMultiTenancyModule) )] public class EShopOnAbpSharedHostingGatewaysModule : AbpModule @@ -20,6 +20,7 @@ namespace EShopOnAbp.Shared.Hosting.Gateways var configuration = context.Services.GetConfiguration(); context.Services.AddOcelot(configuration) + .AddConsul() .AddPolly(); } } 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