Compare commits

...

3 Commits

Author SHA1 Message Date
Galip Tolga Erdem a6fd7060f1 Updated gateways to use oidc for swagger 3 years ago
Galip Tolga Erdem 09b5bb62b5 Updated yarp configurations 3 years ago
Galip Tolga Erdem df2386e970 Updated swagger config and gateway hosting 3 years ago
  1. 32
      gateways/web-public/src/EShopOnAbp.WebPublicGateway/EShopOnAbpWebPublicGatewayModule.cs
  2. 52
      gateways/web-public/src/EShopOnAbp.WebPublicGateway/appsettings.Docker.json
  3. 113
      gateways/web-public/src/EShopOnAbp.WebPublicGateway/appsettings.Staging.json
  4. 44
      gateways/web-public/src/EShopOnAbp.WebPublicGateway/yarp.json
  5. 32
      gateways/web/src/EShopOnAbp.WebGateway/EShopOnAbpWebGatewayModule.cs
  6. 64
      gateways/web/src/EShopOnAbp.WebGateway/appsettings.Docker.json
  7. 65
      gateways/web/src/EShopOnAbp.WebGateway/yarp.json
  8. 2
      shared/EShopOnAbp.Shared.Hosting.AspNetCore/EShopOnAbp.Shared.Hosting.AspNetCore.csproj
  9. 24
      shared/EShopOnAbp.Shared.Hosting.AspNetCore/SwaggerConfigurationHelper.cs
  10. 2
      shared/EShopOnAbp.Shared.Hosting.Gateways/EShopOnAbp.Shared.Hosting.Gateways.csproj
  11. 31
      shared/EShopOnAbp.Shared.Hosting.Gateways/YarpSwaggerUIBuilderExtensions.cs

32
gateways/web-public/src/EShopOnAbp.WebPublicGateway/EShopOnAbpWebPublicGatewayModule.cs

@ -21,25 +21,19 @@ public class EShopOnAbpWebPublicGatewayModule : AbpModule
var configuration = context.Services.GetConfiguration();
var hostingEnvironment = context.Services.GetHostingEnvironment();
SwaggerConfigurationHelper.ConfigureWithAuth(
context: context,
authority: configuration["AuthServer:Authority"],
scopes: new Dictionary<string, string> /* Requested scopes for authorization code request and descriptions for swagger UI only */
{
{ "AccountService", "Account Service API" },
{ "IdentityService", "Identity Service API" },
{ "AdministrationService", "Administration Service API" },
{ "CatalogService", "Catalog Service API" },
{ "BasketService", "Basket Service API" },
{ "PaymentService", "Payment Service API" },
{ "OrderingService", "Ordering Service API" },
{ "CmskitService", "Cmskit Service API" },
},
apiTitle: "WebPublic Gateway"
);
// context.Services.AddReverseProxy()
// .LoadFromConfig(configuration.GetSection("ReverseProxy"));
SwaggerConfigurationHelper
.ConfigureWithOidc(
context: context,
authority: configuration["AuthServer:Authority"]!,
/* Requested scopes for authorization code request and descriptions for swagger UI only */
scopes: new[]
{
"AccountService", "IdentityService", "AdministrationService", "CatalogService", "BasketService",
"OrderingService", "CmskitService"
},
apiTitle: "Public Web Gateway API",
discoveryEndpoint: configuration["AuthServer:MetadataAddress"]
);
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)

52
gateways/web-public/src/EShopOnAbp.WebPublicGateway/appsettings.Docker.json

@ -1,50 +1,62 @@
{
"ReverseProxy": {
"Routes": {
"Account Service": {
"ClusterId": "accountCluster",
"AbpApi": {
"ClusterId": "Administration",
"Match": {
"Path": "/api/account/{**everything}"
"Path": "/api/abp/{**catch-all}"
}
},
"Administration Service": {
"ClusterId": "administrationCluster",
"Account Service": {
"ClusterId": "Account",
"Match": {
"Path": "/api/abp/{**everything}"
"Path": "/api/account/{**everything}"
}
},
"Catalog Service": {
"ClusterId": "catalogCluster",
"ClusterId": "Catalog",
"Match": {
"Path": "/api/catalog/{**everything}"
}
},
"Basket Service": {
"ClusterId": "basketCluster",
"ClusterId": "Basket",
"Match": {
"Path": "/api/basket/{**everything}"
}
},
"Ordering Service": {
"ClusterId": "orderingCluster",
"ClusterId": "Ordering",
"Match": {
"Path": "/api/ordering/{**everything}"
}
},
"Payment Service": {
"ClusterId": "paymentCluster",
"ClusterId": "Payment",
"Match": {
"Path": "/api/payment/{**everything}"
}
},
"Cmskit Service": {
"ClusterId": "cmskitCluster",
"ClusterId": "CmsKit",
"Match": {
"Path": "/api/cmskit/{**everything}"
}
},
"Cmskit Public Service": {
"ClusterId": "CmsKit",
"Match": {
"Path": "/api/cms-kit-public/{**everything}"
}
},
"Cmskit Admin Service": {
"ClusterId": "CmsKit",
"Match": {
"Path": "/api/cms-kit-admin/{**everything}"
}
},
"product-picture-route": {
"ClusterId": "productPictureCluster",
"ClusterId": "ProductPictures",
"Match": {
"Path": "/product-images/{**everything}",
"Methods": [ "GET" ]
@ -52,56 +64,56 @@
}
},
"Clusters": {
"accountCluster": {
"Account": {
"Destinations": {
"destination1": {
"Address": "http://app-authserver"
}
}
},
"administrationCluster": {
"Administration": {
"Destinations": {
"destination1": {
"Address": "http://administration-service"
}
}
},
"catalogCluster": {
"Catalog": {
"Destinations": {
"destination1": {
"Address": "http://catalog-service"
}
}
},
"basketCluster": {
"Basket": {
"Destinations": {
"destination1": {
"Address": "http://basket-service"
}
}
},
"orderingCluster": {
"Ordering": {
"Destinations": {
"destination1": {
"Address": "http://ordering-service"
}
}
},
"paymentCluster": {
"Payment": {
"Destinations": {
"destination1": {
"Address": "http://payment-service"
}
}
},
"cmskitCluster": {
"CmsKit": {
"Destinations": {
"destination1": {
"Address": "http://cmskit-service"
}
}
},
"productPictureCluster": {
"ProductPictures": {
"Destinations": {
"destination1": {
"Address": "http://catalog-service"

113
gateways/web-public/src/EShopOnAbp.WebPublicGateway/appsettings.Staging.json

@ -1,113 +0,0 @@
{
"ReverseProxy": {
"Routes": {
"Account Service": {
"ClusterId": "accountCluster",
"Match": {
"Path": "/api/account/{**everything}"
}
},
"Administration Service": {
"ClusterId": "administrationCluster",
"Match": {
"Path": "/api/abp/{**everything}"
}
},
"Catalog Service": {
"ClusterId": "catalogCluster",
"Match": {
"Path": "/api/catalog/{**everything}"
}
},
"Basket Service": {
"ClusterId": "basketCluster",
"Match": {
"Path": "/api/basket/{**everything}"
}
},
"Ordering Service": {
"ClusterId": "orderingCluster",
"Match": {
"Path": "/api/ordering/{**everything}"
}
},
"Payment Service": {
"ClusterId": "paymentCluster",
"Match": {
"Path": "/api/payment/{**everything}"
}
},
"Cmskit Service": {
"ClusterId": "cmskitCluster",
"Match": {
"Path": "/api/cmskit/{**everything}"
}
},
"product-picture-route": {
"ClusterId": "productPictureCluster",
"Match": {
"Path": "/product-images/{**everything}",
"Methods": [ "GET" ]
}
}
},
"Clusters": {
"accountCluster": {
"Destinations": {
"destination1": {
"Address": "http://eshop-st-authserver"
}
}
},
"administrationCluster": {
"Destinations": {
"destination1": {
"Address": "http://eshop-st-administration"
}
}
},
"catalogCluster": {
"Destinations": {
"destination1": {
"Address": "http://eshop-st-catalog"
}
}
},
"basketCluster": {
"Destinations": {
"destination1": {
"Address": "http://eshop-st-basket"
}
}
},
"orderingCluster": {
"Destinations": {
"destination1": {
"Address": "http://eshop-st-ordering"
}
}
},
"paymentCluster": {
"Destinations": {
"destination1": {
"Address": "http://eshop-st-payment"
}
}
},
"cmskitCluster": {
"Destinations": {
"destination1": {
"Address": "http://eshop-st-cmskit"
}
}
},
"productPictureCluster": {
"Destinations": {
"destination1": {
"Address": "http://eshop-st-catalog"
}
}
}
}
}
}

44
gateways/web-public/src/EShopOnAbp.WebPublicGateway/yarp.json

@ -1,62 +1,62 @@
{
"ReverseProxy": {
"Routes": {
"Account Service": {
"ClusterId": "accountCluster",
"AbpApi": {
"ClusterId": "Administration",
"Match": {
"Path": "/api/account/{**everything}"
"Path": "/api/abp/{**catch-all}"
}
},
"Administration Service": {
"ClusterId": "administrationCluster",
"Account Service": {
"ClusterId": "Account",
"Match": {
"Path": "/api/abp/{**everything}"
"Path": "/api/account/{**everything}"
}
},
"Catalog Service": {
"ClusterId": "catalogCluster",
"ClusterId": "Catalog",
"Match": {
"Path": "/api/catalog/{**everything}"
}
},
"Basket Service": {
"ClusterId": "basketCluster",
"ClusterId": "Basket",
"Match": {
"Path": "/api/basket/{**everything}"
}
},
"Ordering Service": {
"ClusterId": "orderingCluster",
"ClusterId": "Ordering",
"Match": {
"Path": "/api/ordering/{**everything}"
}
},
"Payment Service": {
"ClusterId": "paymentCluster",
"ClusterId": "Payment",
"Match": {
"Path": "/api/payment/{**everything}"
}
},
"Cmskit Service": {
"ClusterId": "cmskitCluster",
"ClusterId": "CmsKit",
"Match": {
"Path": "/api/cmskit/{**everything}"
}
},
"Cmskit Public Service": {
"ClusterId": "cmskitCluster",
"ClusterId": "CmsKit",
"Match": {
"Path": "/api/cms-kit-public/{**everything}"
}
},
"Cmskit Admin Service": {
"ClusterId": "cmskitCluster",
"ClusterId": "CmsKit",
"Match": {
"Path": "/api/cms-kit-admin/{**everything}"
}
},
"product-picture-route": {
"ClusterId": "productPictureCluster",
"ClusterId": "ProductPictures",
"Match": {
"Path": "/product-images/{**everything}",
"Methods": [ "GET" ]
@ -64,56 +64,56 @@
}
},
"Clusters": {
"accountCluster": {
"Account": {
"Destinations": {
"destination1": {
"Address": "https://localhost:44330"
}
}
},
"administrationCluster": {
"Administration": {
"Destinations": {
"destination1": {
"Address": "https://localhost:44353"
}
}
},
"catalogCluster": {
"Catalog": {
"Destinations": {
"destination1": {
"Address": "https://localhost:44354"
}
}
},
"basketCluster": {
"Basket": {
"Destinations": {
"destination1": {
"Address": "https://localhost:44355"
}
}
},
"orderingCluster": {
"Ordering": {
"Destinations": {
"destination1": {
"Address": "https://localhost:44356"
}
}
},
"paymentCluster": {
"Payment": {
"Destinations": {
"destination1": {
"Address": "https://localhost:44357"
}
}
},
"cmskitCluster": {
"CmsKit": {
"Destinations": {
"destination1": {
"Address": "https://localhost:44358"
}
}
},
"productPictureCluster": {
"ProductPictures": {
"Destinations": {
"destination1": {
"Address": "https://localhost:44354"

32
gateways/web/src/EShopOnAbp.WebGateway/EShopOnAbpWebGatewayModule.cs

@ -23,23 +23,19 @@ public class EShopOnAbpWebGatewayModule : AbpModule
var configuration = context.Services.GetConfiguration();
var hostingEnvironment = context.Services.GetHostingEnvironment();
SwaggerConfigurationHelper.ConfigureWithAuth(
context: context,
authority: configuration["AuthServer:Authority"],
scopes: new
Dictionary<string, string> /* Requested scopes for authorization code request and descriptions for swagger UI only */
SwaggerConfigurationHelper
.ConfigureWithOidc(
context: context,
authority: configuration["AuthServer:Authority"]!,
/* Requested scopes for authorization code request and descriptions for swagger UI only */
scopes: new[]
{
{"AccountService", "Account Service API"},
{"IdentityService", "Identity Service API"},
{"AdministrationService", "Administration Service API"},
{"CatalogService", "Catalog Service API"},
{"BasketService", "Basket Service API"},
{"PaymentService", "Payment Service API"},
{"OrderingService", "Ordering Service API"},
{"CmskitService", "Cmskit Service API"},
"AccountService", "IdentityService", "AdministrationService", "CatalogService", "BasketService",
"PaymentService", "OrderingService", "CmskitService"
},
apiTitle: "Web Gateway"
);
apiTitle: "Web Gateway",
discoveryEndpoint: configuration["AuthServer:MetadataAddress"]
);
context.Services.AddCors(options =>
{
@ -70,6 +66,7 @@ public class EShopOnAbpWebGatewayModule : AbpModule
{
app.UseDeveloperExceptionPage();
}
app.UseCorrelationId();
app.UseAbpSerilogEnrichers();
app.UseCors();
@ -80,9 +77,6 @@ public class EShopOnAbpWebGatewayModule : AbpModule
.AddRedirect("^(|\\|\\s+)$", "/swagger"));
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapReverseProxy();
});
app.UseEndpoints(endpoints => { endpoints.MapReverseProxy(); });
}
}

64
gateways/web/src/EShopOnAbp.WebGateway/appsettings.Docker.json

@ -1,6 +1,12 @@
{
"ReverseProxy": {
"Routes": {
"AbpApi": {
"ClusterId": "Administration",
"Match": {
"Path": "/api/abp/{**catch-all}"
}
},
"Account Service": {
"ClusterId": "accountCluster",
"Match": {
@ -8,79 +14,91 @@
}
},
"Identity Service": {
"ClusterId": "identityCluster",
"ClusterId": "Identity",
"Match": {
"Path": "/api/identity/{**everything}"
}
},
"Administration Service": {
"ClusterId": "administrationCluster",
"Match": {
"Path": "/api/abp/{**everything}"
}
},
"feature-management-route": {
"ClusterId": "featureManagementCluster",
"FeatureManagement": {
"ClusterId": "Administration",
"Match": {
"Path": "/api/feature-management/{**everything}"
}
},
"permission-management-route": {
"ClusterId": "permissionManagementCluster",
"PermissionManagement": {
"ClusterId": "Administration",
"Match": {
"Path": "/api/permission-management/{**everything}"
}
},
"setting-management-route": {
"ClusterId": "settingManagementCluster",
"SettingManagement": {
"ClusterId": "Administration",
"Match": {
"Path": "/api/setting-management/{**everything}"
}
},
"Catalog Service": {
"ClusterId": "Catalog",
"Match": {
"Path": "/api/catalog/{**everything}"
}
},
"Ordering Service": {
"ClusterId": "Ordering",
"Match": {
"Path": "/api/ordering/{**everything}"
}
},
"Cmskit Service": {
"ClusterId": "CmsKit",
"Match": {
"Path": "/api/cmskit/{**everything}"
}
}
},
"Clusters": {
"accountCluster": {
"Account": {
"Destinations": {
"destination1": {
"Address": "http://app-authserver"
}
}
},
"identityCluster": {
"Identity": {
"Destinations": {
"destination1": {
"Address": "http://identity-service"
}
}
},
"administrationCluster": {
"Administration": {
"Destinations": {
"destination1": {
"Address": "http://administration-service"
}
}
},
"featureManagementCluster": {
"Catalog": {
"Destinations": {
"destination1": {
"Address": "http://administration-service"
"Address": "http://catalog-service"
}
}
},
"permissionManagementCluster": {
"Ordering": {
"Destinations": {
"destination1": {
"Address": "http://administration-service"
"Address": "http://ordering-service"
}
}
},
"settingManagementCluster": {
"CmsKit": {
"Destinations": {
"destination1": {
"Address": "http://administration-service"
"Address": "http://cmskit-service"
}
}
}
},
}
}
}

65
gateways/web/src/EShopOnAbp.WebGateway/yarp.json

@ -1,6 +1,12 @@
{
"ReverseProxy": {
"Routes": {
"AbpApi": {
"ClusterId": "Administration",
"Match": {
"Path": "/api/abp/{**catch-all}"
}
},
"Account Service": {
"ClusterId": "accountCluster",
"Match": {
@ -8,112 +14,85 @@
}
},
"Identity Service": {
"ClusterId": "identityCluster",
"ClusterId": "Identity",
"Match": {
"Path": "/api/identity/{**everything}"
}
},
"Administration Service": {
"ClusterId": "administrationCluster",
"Match": {
"Path": "/api/abp/{**everything}"
}
},
"feature-management-route": {
"ClusterId": "feature-management-cluster",
"FeatureManagement": {
"ClusterId": "Administration",
"Match": {
"Path": "/api/feature-management/{**everything}"
}
},
"permission-management-route": {
"ClusterId": "permission-management-cluster",
"PermissionManagement": {
"ClusterId": "Administration",
"Match": {
"Path": "/api/permission-management/{**everything}"
}
},
"setting-management-route": {
"ClusterId": "setting-management-cluster",
"SettingManagement": {
"ClusterId": "Administration",
"Match": {
"Path": "/api/setting-management/{**everything}"
}
},
"Catalog Service": {
"ClusterId": "catalogCluster",
"ClusterId": "Catalog",
"Match": {
"Path": "/api/catalog/{**everything}"
}
},
"Ordering Service": {
"ClusterId": "orderingCluster",
"ClusterId": "Ordering",
"Match": {
"Path": "/api/ordering/{**everything}"
}
},
"Cmskit Service": {
"ClusterId": "cmskitCluster",
"ClusterId": "CmsKit",
"Match": {
"Path": "/api/cmskit/{**everything}"
}
}
},
"Clusters": {
"accountCluster": {
"Account": {
"Destinations": {
"destination1": {
"Address": "https://localhost:44330"
}
}
},
"identityCluster": {
"Identity": {
"Destinations": {
"destination1": {
"Address": "https://localhost:44351"
}
}
},
"administrationCluster": {
"Destinations": {
"destination1": {
"Address": "https://localhost:44353"
}
}
},
"feature-management-cluster": {
"Destinations": {
"destination1": {
"Address": "https://localhost:44353"
}
}
},
"permission-management-cluster": {
"Destinations": {
"destination1": {
"Address": "https://localhost:44353"
}
}
},
"setting-management-cluster": {
"Administration": {
"Destinations": {
"destination1": {
"Address": "https://localhost:44353"
}
}
},
"catalogCluster": {
"Catalog": {
"Destinations": {
"destination1": {
"Address": "https://localhost:44354"
}
}
},
"orderingCluster": {
"Ordering": {
"Destinations": {
"destination1": {
"Address": "https://localhost:44356"
}
}
},
"cmskitCluster": {
"CmsKit": {
"Destinations": {
"destination1": {
"Address": "https://localhost:44358"

2
shared/EShopOnAbp.Shared.Hosting.AspNetCore/EShopOnAbp.Shared.Hosting.AspNetCore.csproj

@ -8,7 +8,7 @@
<ItemGroup>
<PackageReference Include="Serilog.AspNetCore" Version="5.0.0" />
<PackageReference Include="Volo.Abp.AspNetCore.Serilog" Version="7.0.0" />
<PackageReference Include="Volo.Abp.Swashbuckle" Version="7.0.0" />
<PackageReference Include="Volo.Abp.Swashbuckle" Version="7.4.0-rc.2" />
</ItemGroup>
<ItemGroup>

24
shared/EShopOnAbp.Shared.Hosting.AspNetCore/SwaggerConfigurationHelper.cs

@ -38,4 +38,28 @@ public static class SwaggerConfigurationHelper
options.CustomSchemaIds(type => type.FullName);
});
}
public static void ConfigureWithOidc(
ServiceConfigurationContext context,
string authority,
string[] scopes,
string apiTitle,
string apiVersion = "v1",
string apiName = "v1",
string[]? flows = null,
string? discoveryEndpoint = null
)
{
context.Services.AddAbpSwaggerGenWithOidc(
authority: authority,
scopes: scopes,
flows: flows,
discoveryEndpoint: discoveryEndpoint,
options =>
{
options.SwaggerDoc(apiName, new OpenApiInfo { Title = apiTitle, Version = apiVersion });
options.DocInclusionPredicate((docName, description) => true);
options.CustomSchemaIds(type => type.FullName);
});
}
}

2
shared/EShopOnAbp.Shared.Hosting.Gateways/EShopOnAbp.Shared.Hosting.Gateways.csproj

@ -5,7 +5,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Yarp.ReverseProxy" Version="1.0.0" />
<PackageReference Include="Yarp.ReverseProxy" Version="2.0.1" />
</ItemGroup>
<ItemGroup>

31
shared/EShopOnAbp.Shared.Hosting.Gateways/YarpSwaggerUIBuilderExtensions.cs

@ -1,5 +1,4 @@
using System.Linq;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
@ -18,32 +17,12 @@ public static class YarpSwaggerUIBuilderExtensions
{
var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>();
var logger = context.ServiceProvider.GetRequiredService<ILogger<ApplicationInitializationContext>>();
var proxyConfigProvider = context.ServiceProvider.GetRequiredService<IProxyConfigProvider>();
var yarpConfig = proxyConfigProvider.GetConfig();
var proxyConfig = context.ServiceProvider.GetRequiredService<IProxyConfigProvider>().GetConfig();
var routedClusters = yarpConfig.Clusters
.SelectMany(t => t.Destinations,
(clusterId, destination) => new {clusterId.ClusterId, destination.Value});
var groupedClusters = routedClusters
.GroupBy(q => q.Value.Address)
.Select(t => t.First())
.Distinct()
.ToList();
foreach (var clusterGroup in groupedClusters)
foreach (var cluster in proxyConfig.Clusters)
{
var routeConfig = yarpConfig.Routes.FirstOrDefault(q =>
q.ClusterId == clusterGroup.ClusterId);
if (routeConfig == null)
{
logger.LogWarning($"Swagger UI: Couldn't find route configuration for {clusterGroup.ClusterId}...");
continue;
}
options.SwaggerEndpoint($"{clusterGroup.Value.Address}/swagger/v1/swagger.json", $"{routeConfig.RouteId} API");
options.OAuthClientId(configuration["AuthServer:SwaggerClientId"]);
options.OAuthClientSecret(configuration["AuthServer:SwaggerClientSecret"]);
options.SwaggerEndpoint($"/swagger-json/{cluster.ClusterId}/swagger/v1/swagger.json",
$"{cluster.ClusterId} API");
}
});

Loading…
Cancel
Save