Browse Source

Removed swagger auth from gateways

pull/6/head
Galip Tolga Erdem 5 years ago
parent
commit
55671fb266
  1. 29
      gateways/internal/src/EShopOnAbp.InternalGateway/EShopOnAbpInternalGatewayModule.cs
  2. 26
      gateways/web-public/src/EShopOnAbp.WebPublicGateway/EShopOnAbpWebPublicGatewayModule.cs
  3. 49
      gateways/web/src/EShopOnAbp.WebGateway/EShopOnAbpWebGatewayModule.cs

29
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<string, string> /* 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<IConfiguration>();
options.OAuthClientId(configuration["AuthServer:SwaggerClientId"]);
options.OAuthClientSecret(configuration["AuthServer:SwaggerClientSecret"]);
var routes = configuration.GetSection("Routes").Get<List<OcelotConfiguration>>();
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(

26
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<string, string> /* 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<IConfiguration>();
options.OAuthClientId(configuration["AuthServer:SwaggerClientId"]);
options.OAuthClientSecret(configuration["AuthServer:SwaggerClientSecret"]);
var routes = configuration.GetSection("Routes").Get<List<OcelotConfiguration>>();
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(

49
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<string, string> /* 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<IConfiguration>();
options.OAuthClientId(configuration["AuthServer:SwaggerClientId"]);
options.OAuthClientSecret(configuration["AuthServer:SwaggerClientSecret"]);
var routes = configuration.GetSection("Routes").Get<List<OcelotConfiguration>>();
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(

Loading…
Cancel
Save