Browse Source

Merge pull request #238 from abpframework/gterdem/swagger_fix

eShopOnAbp: Keycloak swagger authorization
pull/244/head
maliming 3 years ago
committed by GitHub
parent
commit
acc8a1c8be
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 2
      gateways/web-public/src/EShopOnAbp.WebPublicGateway/appsettings.json
  2. 2
      gateways/web/src/EShopOnAbp.WebGateway/appsettings.json
  3. 16
      services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/AdministrationServiceHttpApiHostModule.cs
  4. 2
      services/basket/src/EShopOnAbp.BasketService/BasketServiceModule.cs
  5. 2
      services/basket/src/EShopOnAbp.BasketService/appsettings.json
  6. 2
      services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/CatalogServiceHttpApiHostModule.cs
  7. 2
      services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/appsettings.json
  8. 2
      services/cmskit/src/EShopOnAbp.CmskitService.HttpApi.Host/CmskitServiceHttpApiHostModule.cs
  9. 2
      services/cmskit/src/EShopOnAbp.CmskitService.HttpApi.Host/appsettings.json
  10. 1
      services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/EShopOnAbp.IdentityService.HttpApi.Host.csproj
  11. 5
      services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/IdentityServiceHttpApiHostModule.cs
  12. 2
      services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/appsettings.json
  13. 2
      services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/OrderingServiceHttpApiHostModule.cs
  14. 2
      services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/appsettings.json
  15. 2
      services/payment/src/EShopOnAbp.PaymentService.HttpApi.Host/PaymentServiceHttpApiHostModule.cs
  16. 2
      services/payment/src/EShopOnAbp.PaymentService.HttpApi.Host/appsettings.json
  17. 27
      shared/EShopOnAbp.Shared.Hosting.AspNetCore/AbpSwaggerUIBuilderExtensions.cs
  18. 15
      shared/EShopOnAbp.Shared.Hosting.AspNetCore/EShopOnAbp.Shared.Hosting.AspNetCore.csproj
  19. 5
      shared/EShopOnAbp.Shared.Hosting.AspNetCore/EShopOnAbpSharedHostingAspNetCoreModule.cs
  20. 9
      shared/EShopOnAbp.Shared.Hosting.AspNetCore/wwwroot/swagger/ui/requestinterceptor.js
  21. 3
      shared/EShopOnAbp.Shared.Hosting.Gateways/YarpSwaggerUIBuilderExtensions.cs

2
gateways/web-public/src/EShopOnAbp.WebPublicGateway/appsettings.json

@ -7,7 +7,7 @@
"AuthServer": { "AuthServer": {
"Authority": "http://localhost:8080/realms/master", "Authority": "http://localhost:8080/realms/master",
"RequireHttpsMetadata": "true", "RequireHttpsMetadata": "true",
"SwaggerClientId": "WebGateway_Swagger", "SwaggerClientId": "SwaggerClient",
"SwaggerClientSecret": "1q2w3e*" "SwaggerClientSecret": "1q2w3e*"
}, },
"Logging": { "Logging": {

2
gateways/web/src/EShopOnAbp.WebGateway/appsettings.json

@ -8,7 +8,7 @@
"Authority": "http://localhost:8080/realms/master", "Authority": "http://localhost:8080/realms/master",
"RequireHttpsMetadata": "true", "RequireHttpsMetadata": "true",
"MetadataAddress": "http://localhost:8080/realms/master", "MetadataAddress": "http://localhost:8080/realms/master",
"SwaggerClientId": "WebGateway_Swagger" "SwaggerClientId": "SwaggerClient"
}, },
"Logging": { "Logging": {
"LogLevel": { "LogLevel": {

16
services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/AdministrationServiceHttpApiHostModule.cs

@ -59,17 +59,11 @@ public class AdministrationServiceHttpApiHostModule : AbpModule
.AllowCredentials(); .AllowCredentials();
}); });
}); });
Configure<PermissionManagementOptions>(options =>
{
options.IsDynamicPermissionStoreEnabled = true;
});
Configure<SettingManagementOptions>(options => Configure<PermissionManagementOptions>(options => { options.IsDynamicPermissionStoreEnabled = true; });
{
options.IsDynamicSettingStoreEnabled = true; Configure<SettingManagementOptions>(options => { options.IsDynamicSettingStoreEnabled = true; });
});
// Configure<AbpPermissionOptions>(options => // Configure<AbpPermissionOptions>(options =>
// { // {
// options.ValueProviders.Clear(); // options.ValueProviders.Clear();
@ -99,7 +93,7 @@ public class AdministrationServiceHttpApiHostModule : AbpModule
app.UseUnitOfWork(); app.UseUnitOfWork();
app.UseAuthorization(); app.UseAuthorization();
app.UseSwagger(); app.UseSwagger();
app.UseAbpSwaggerUI(options => app.UseAbpSwaggerWithCustomScriptUI(options =>
{ {
var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>(); var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>();
options.SwaggerEndpoint("/swagger/v1/swagger.json", "Administration Service API"); options.SwaggerEndpoint("/swagger/v1/swagger.json", "Administration Service API");

2
services/basket/src/EShopOnAbp.BasketService/BasketServiceModule.cs

@ -95,7 +95,7 @@ public class BasketServiceModule : AbpModule
app.UseAbpClaimsMap(); app.UseAbpClaimsMap();
app.UseAuthorization(); app.UseAuthorization();
app.UseSwagger(); app.UseSwagger();
app.UseAbpSwaggerUI(options => app.UseAbpSwaggerWithCustomScriptUI(options =>
{ {
var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>(); var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>();
options.SwaggerEndpoint("/swagger/v1/swagger.json", "Basket Service API"); options.SwaggerEndpoint("/swagger/v1/swagger.json", "Basket Service API");

2
services/basket/src/EShopOnAbp.BasketService/appsettings.json

@ -7,7 +7,7 @@
"Authority": "http://localhost:8080/realms/master", "Authority": "http://localhost:8080/realms/master",
"RequireHttpsMetadata": "false", "RequireHttpsMetadata": "false",
"MetadataAddress": "http://localhost:8080/realms/master", "MetadataAddress": "http://localhost:8080/realms/master",
"SwaggerClientId": "WebGateway_Swagger" "SwaggerClientId": "SwaggerClient"
}, },
"RemoteServices": { "RemoteServices": {
"Catalog": { "Catalog": {

2
services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/CatalogServiceHttpApiHostModule.cs

@ -101,7 +101,7 @@ public class CatalogServiceHttpApiHostModule : AbpModule
app.UseAbpClaimsMap(); app.UseAbpClaimsMap();
app.UseAuthorization(); app.UseAuthorization();
app.UseSwagger(); app.UseSwagger();
app.UseAbpSwaggerUI(options => app.UseAbpSwaggerWithCustomScriptUI(options =>
{ {
var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>(); var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>();
options.SwaggerEndpoint("/swagger/v1/swagger.json", "Catalog Service API"); options.SwaggerEndpoint("/swagger/v1/swagger.json", "Catalog Service API");

2
services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/appsettings.json

@ -7,7 +7,7 @@
"Authority": "http://localhost:8080/realms/master", "Authority": "http://localhost:8080/realms/master",
"RequireHttpsMetadata": "false", "RequireHttpsMetadata": "false",
"MetadataAddress": "http://localhost:8080/realms/master", "MetadataAddress": "http://localhost:8080/realms/master",
"SwaggerClientId": "WebGateway_Swagger" "SwaggerClientId": "SwaggerClient"
}, },
"Logging": { "Logging": {
"LogLevel": { "LogLevel": {

2
services/cmskit/src/EShopOnAbp.CmskitService.HttpApi.Host/CmskitServiceHttpApiHostModule.cs

@ -111,7 +111,7 @@ public class CmskitServiceHttpApiHostModule : AbpModule
app.UseAbpClaimsMap(); app.UseAbpClaimsMap();
app.UseAuthorization(); app.UseAuthorization();
app.UseSwagger(); app.UseSwagger();
app.UseAbpSwaggerUI(options => app.UseAbpSwaggerWithCustomScriptUI(options =>
{ {
var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>(); var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>();
options.SwaggerEndpoint("/swagger/v1/swagger.json", "Cmskit Service API"); options.SwaggerEndpoint("/swagger/v1/swagger.json", "Cmskit Service API");

2
services/cmskit/src/EShopOnAbp.CmskitService.HttpApi.Host/appsettings.json

@ -7,7 +7,7 @@
"Authority": "http://localhost:8080/realms/master", "Authority": "http://localhost:8080/realms/master",
"RequireHttpsMetadata": "false", "RequireHttpsMetadata": "false",
"MetadataAddress": "http://localhost:8080/realms/master", "MetadataAddress": "http://localhost:8080/realms/master",
"SwaggerClientId": "WebGateway_Swagger" "SwaggerClientId": "SwaggerClient"
}, },
"Logging": { "Logging": {
"LogLevel": { "LogLevel": {

1
services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/EShopOnAbp.IdentityService.HttpApi.Host.csproj

@ -3,6 +3,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net8.0</TargetFramework>
<RootNamespace>EShopOnAbp.IdentityService</RootNamespace> <RootNamespace>EShopOnAbp.IdentityService</RootNamespace>
<PreserveCompilationReferences>true</PreserveCompilationReferences>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

5
services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/IdentityServiceHttpApiHostModule.cs

@ -22,8 +22,7 @@ namespace EShopOnAbp.IdentityService;
typeof(EShopOnAbpSharedHostingMicroservicesModule), typeof(EShopOnAbpSharedHostingMicroservicesModule),
typeof(IdentityServiceHttpApiModule), typeof(IdentityServiceHttpApiModule),
typeof(IdentityServiceApplicationModule), typeof(IdentityServiceApplicationModule),
typeof(IdentityServiceEntityFrameworkCoreModule), typeof(IdentityServiceEntityFrameworkCoreModule)
typeof(EShopOnAbpSharedHostingGatewaysModule)
)] )]
public class IdentityServiceHttpApiHostModule : AbpModule public class IdentityServiceHttpApiHostModule : AbpModule
{ {
@ -91,7 +90,7 @@ public class IdentityServiceHttpApiHostModule : AbpModule
app.UseAbpClaimsMap(); app.UseAbpClaimsMap();
app.UseAuthorization(); app.UseAuthorization();
app.UseSwagger(); app.UseSwagger();
app.UseAbpSwaggerUI(options => app.UseAbpSwaggerWithCustomScriptUI(options =>
{ {
var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>(); var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>();
options.SwaggerEndpoint("/swagger/v1/swagger.json", "Identity Service API"); options.SwaggerEndpoint("/swagger/v1/swagger.json", "Identity Service API");

2
services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/appsettings.json

@ -7,7 +7,7 @@
"Authority": "http://localhost:8080/realms/master", "Authority": "http://localhost:8080/realms/master",
"RequireHttpsMetadata": "false", "RequireHttpsMetadata": "false",
"MetadataAddress": "http://localhost:8080/realms/master", "MetadataAddress": "http://localhost:8080/realms/master",
"SwaggerClientId": "WebGateway_Swagger" "SwaggerClientId": "SwaggerClient"
}, },
"Keycloak": { "Keycloak": {
"url": "http://localhost:8080", "url": "http://localhost:8080",

2
services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/OrderingServiceHttpApiHostModule.cs

@ -88,7 +88,7 @@ public class OrderingServiceHttpApiHostModule : AbpModule
app.UseAbpClaimsMap(); app.UseAbpClaimsMap();
app.UseAuthorization(); app.UseAuthorization();
app.UseSwagger(); app.UseSwagger();
app.UseAbpSwaggerUI(options => app.UseAbpSwaggerWithCustomScriptUI(options =>
{ {
var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>(); var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>();
options.SwaggerEndpoint("/swagger/v1/swagger.json", "Ordering Service API"); options.SwaggerEndpoint("/swagger/v1/swagger.json", "Ordering Service API");

2
services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/appsettings.json

@ -7,7 +7,7 @@
"Authority": "http://localhost:8080/realms/master", "Authority": "http://localhost:8080/realms/master",
"RequireHttpsMetadata": "false", "RequireHttpsMetadata": "false",
"MetadataAddress": "http://localhost:8080/realms/master", "MetadataAddress": "http://localhost:8080/realms/master",
"SwaggerClientId": "WebGateway_Swagger" "SwaggerClientId": "SwaggerClient"
}, },
"Logging": { "Logging": {
"LogLevel": { "LogLevel": {

2
services/payment/src/EShopOnAbp.PaymentService.HttpApi.Host/PaymentServiceHttpApiHostModule.cs

@ -81,7 +81,7 @@ public class PaymentServiceHttpApiHostModule : AbpModule
app.UseAbpClaimsMap(); app.UseAbpClaimsMap();
app.UseAuthorization(); app.UseAuthorization();
app.UseSwagger(); app.UseSwagger();
app.UseAbpSwaggerUI(options => app.UseAbpSwaggerWithCustomScriptUI(options =>
{ {
var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>(); var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>();
options.SwaggerEndpoint("/swagger/v1/swagger.json", "Payment Service API"); options.SwaggerEndpoint("/swagger/v1/swagger.json", "Payment Service API");

2
services/payment/src/EShopOnAbp.PaymentService.HttpApi.Host/appsettings.json

@ -7,7 +7,7 @@
"Authority": "http://localhost:8080/realms/master", "Authority": "http://localhost:8080/realms/master",
"RequireHttpsMetadata": "false", "RequireHttpsMetadata": "false",
"MetadataAddress": "http://localhost:8080/realms/master", "MetadataAddress": "http://localhost:8080/realms/master",
"SwaggerClientId": "WebGateway_Swagger" "SwaggerClientId": "SwaggerClient"
}, },
"Logging": { "Logging": {
"LogLevel": { "LogLevel": {

27
shared/EShopOnAbp.Shared.Hosting.AspNetCore/AbpSwaggerUIBuilderExtensions.cs

@ -0,0 +1,27 @@
using System;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Swashbuckle.AspNetCore.SwaggerUI;
using Volo.Abp.Swashbuckle;
namespace EShopOnAbp.Shared.Hosting.AspNetCore;
public static class AbpSwaggerUIBuilderExtensions
{
public static IApplicationBuilder UseAbpSwaggerWithCustomScriptUI(
this IApplicationBuilder app,
Action<SwaggerUIOptions>? setupAction = null)
{
var resolver = app.ApplicationServices.GetService<ISwaggerHtmlResolver>();
return app.UseSwaggerUI(options =>
{
options.InjectJavascript("ui/abp.js");
options.InjectJavascript("ui/abp.swagger.js");
options.InjectJavascript("ui/requestinterceptor.js");
options.IndexStream = () => resolver?.Resolver();
setupAction?.Invoke(options);
});
}
}

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

@ -17,4 +17,19 @@
<ProjectReference Include="..\EShopOnAbp.Shared.Localization\EShopOnAbp.Shared.Localization.csproj" /> <ProjectReference Include="..\EShopOnAbp.Shared.Localization\EShopOnAbp.Shared.Localization.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Remove="wwwroot\swagger\ui\requestinterceptor.js" />
</ItemGroup>
<ItemGroup>
<Content Include="wwwroot\swagger\ui\requestinterceptor.js">
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="wwwroot\swagger\ui\requestinterceptor.js" />
</ItemGroup>
</Project> </Project>

5
shared/EShopOnAbp.Shared.Hosting.AspNetCore/EShopOnAbpSharedHostingAspNetCoreModule.cs

@ -1,6 +1,7 @@
using Volo.Abp.AspNetCore.Serilog; using Volo.Abp.AspNetCore.Serilog;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
using Volo.Abp.Swashbuckle; using Volo.Abp.Swashbuckle;
using Volo.Abp.VirtualFileSystem;
namespace EShopOnAbp.Shared.Hosting.AspNetCore; namespace EShopOnAbp.Shared.Hosting.AspNetCore;
@ -14,5 +15,9 @@ public class EShopOnAbpSharedHostingAspNetCoreModule : AbpModule
{ {
public override void ConfigureServices(ServiceConfigurationContext context) public override void ConfigureServices(ServiceConfigurationContext context)
{ {
Configure<AbpVirtualFileSystemOptions>(options =>
{
options.FileSets.AddEmbedded<EShopOnAbpSharedHostingAspNetCoreModule>("EShopOnAbp.Shared.Hosting.AspNetCore");
});
} }
} }

9
shared/EShopOnAbp.Shared.Hosting.AspNetCore/wwwroot/swagger/ui/requestinterceptor.js

@ -0,0 +1,9 @@
const originalFetch = window.fetch;
window.fetch = function (input, init) {
if (init !== undefined && init.headers['RequestVerificationToken'] !== undefined) {
delete init.headers['RequestVerificationToken'];
}
return originalFetch.apply(this, arguments);
};

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

@ -1,5 +1,6 @@
using System; using System;
using System.Linq; using System.Linq;
using EShopOnAbp.Shared.Hosting.AspNetCore;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
@ -15,7 +16,7 @@ public static class YarpSwaggerUIBuilderExtensions
ApplicationInitializationContext context) ApplicationInitializationContext context)
{ {
app.UseSwagger(); app.UseSwagger();
app.UseAbpSwaggerUI(options => app.UseAbpSwaggerWithCustomScriptUI(options =>
{ {
var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>(); var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>();
var logger = context.ServiceProvider.GetRequiredService<ILogger<ApplicationInitializationContext>>(); var logger = context.ServiceProvider.GetRequiredService<ILogger<ApplicationInitializationContext>>();

Loading…
Cancel
Save