Skip to content
This repository was archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
Merge pull request #238 from abpframework/gterdem/swagger_fix
Browse files Browse the repository at this point in the history
eShopOnAbp: Keycloak swagger authorization
  • Loading branch information
maliming authored Feb 22, 2024
2 parents b09a23e + 8e14075 commit acc8a1c
Show file tree
Hide file tree
Showing 21 changed files with 79 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"AuthServer": {
"Authority": "http://localhost:8080/realms/master",
"RequireHttpsMetadata": "true",
"SwaggerClientId": "WebGateway_Swagger",
"SwaggerClientId": "SwaggerClient",
"SwaggerClientSecret": "1q2w3e*"
},
"Logging": {
Expand Down
2 changes: 1 addition & 1 deletion gateways/web/src/EShopOnAbp.WebGateway/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"Authority": "http://localhost:8080/realms/master",
"RequireHttpsMetadata": "true",
"MetadataAddress": "http://localhost:8080/realms/master",
"SwaggerClientId": "WebGateway_Swagger"
"SwaggerClientId": "SwaggerClient"
},
"Logging": {
"LogLevel": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,11 @@ public override void ConfigureServices(ServiceConfigurationContext context)
.AllowCredentials();
});
});

Configure<PermissionManagementOptions>(options =>
{
options.IsDynamicPermissionStoreEnabled = true;
});

Configure<SettingManagementOptions>(options =>
{
options.IsDynamicSettingStoreEnabled = true;
});

Configure<PermissionManagementOptions>(options => { options.IsDynamicPermissionStoreEnabled = true; });

Configure<SettingManagementOptions>(options => { options.IsDynamicSettingStoreEnabled = true; });

// Configure<AbpPermissionOptions>(options =>
// {
// options.ValueProviders.Clear();
Expand Down Expand Up @@ -99,7 +93,7 @@ public override void OnApplicationInitialization(ApplicationInitializationContex
app.UseUnitOfWork();
app.UseAuthorization();
app.UseSwagger();
app.UseAbpSwaggerUI(options =>
app.UseAbpSwaggerWithCustomScriptUI(options =>
{
var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>();
options.SwaggerEndpoint("/swagger/v1/swagger.json", "Administration Service API");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public override void OnApplicationInitialization(ApplicationInitializationContex
app.UseAbpClaimsMap();
app.UseAuthorization();
app.UseSwagger();
app.UseAbpSwaggerUI(options =>
app.UseAbpSwaggerWithCustomScriptUI(options =>
{
var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>();
options.SwaggerEndpoint("/swagger/v1/swagger.json", "Basket Service API");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"Authority": "http://localhost:8080/realms/master",
"RequireHttpsMetadata": "false",
"MetadataAddress": "http://localhost:8080/realms/master",
"SwaggerClientId": "WebGateway_Swagger"
"SwaggerClientId": "SwaggerClient"
},
"RemoteServices": {
"Catalog": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public override void OnApplicationInitialization(ApplicationInitializationContex
app.UseAbpClaimsMap();
app.UseAuthorization();
app.UseSwagger();
app.UseAbpSwaggerUI(options =>
app.UseAbpSwaggerWithCustomScriptUI(options =>
{
var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>();
options.SwaggerEndpoint("/swagger/v1/swagger.json", "Catalog Service API");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"Authority": "http://localhost:8080/realms/master",
"RequireHttpsMetadata": "false",
"MetadataAddress": "http://localhost:8080/realms/master",
"SwaggerClientId": "WebGateway_Swagger"
"SwaggerClientId": "SwaggerClient"
},
"Logging": {
"LogLevel": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public override void OnApplicationInitialization(ApplicationInitializationContex
app.UseAbpClaimsMap();
app.UseAuthorization();
app.UseSwagger();
app.UseAbpSwaggerUI(options =>
app.UseAbpSwaggerWithCustomScriptUI(options =>
{
var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>();
options.SwaggerEndpoint("/swagger/v1/swagger.json", "Cmskit Service API");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"Authority": "http://localhost:8080/realms/master",
"RequireHttpsMetadata": "false",
"MetadataAddress": "http://localhost:8080/realms/master",
"SwaggerClientId": "WebGateway_Swagger"
"SwaggerClientId": "SwaggerClient"
},
"Logging": {
"LogLevel": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>EShopOnAbp.IdentityService</RootNamespace>
<PreserveCompilationReferences>true</PreserveCompilationReferences>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ namespace EShopOnAbp.IdentityService;
typeof(EShopOnAbpSharedHostingMicroservicesModule),
typeof(IdentityServiceHttpApiModule),
typeof(IdentityServiceApplicationModule),
typeof(IdentityServiceEntityFrameworkCoreModule),
typeof(EShopOnAbpSharedHostingGatewaysModule)
typeof(IdentityServiceEntityFrameworkCoreModule)
)]
public class IdentityServiceHttpApiHostModule : AbpModule
{
Expand Down Expand Up @@ -91,7 +90,7 @@ public override void OnApplicationInitialization(ApplicationInitializationContex
app.UseAbpClaimsMap();
app.UseAuthorization();
app.UseSwagger();
app.UseAbpSwaggerUI(options =>
app.UseAbpSwaggerWithCustomScriptUI(options =>
{
var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>();
options.SwaggerEndpoint("/swagger/v1/swagger.json", "Identity Service API");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"Authority": "http://localhost:8080/realms/master",
"RequireHttpsMetadata": "false",
"MetadataAddress": "http://localhost:8080/realms/master",
"SwaggerClientId": "WebGateway_Swagger"
"SwaggerClientId": "SwaggerClient"
},
"Keycloak": {
"url": "http://localhost:8080",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public override void OnApplicationInitialization(ApplicationInitializationContex
app.UseAbpClaimsMap();
app.UseAuthorization();
app.UseSwagger();
app.UseAbpSwaggerUI(options =>
app.UseAbpSwaggerWithCustomScriptUI(options =>
{
var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>();
options.SwaggerEndpoint("/swagger/v1/swagger.json", "Ordering Service API");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"Authority": "http://localhost:8080/realms/master",
"RequireHttpsMetadata": "false",
"MetadataAddress": "http://localhost:8080/realms/master",
"SwaggerClientId": "WebGateway_Swagger"
"SwaggerClientId": "SwaggerClient"
},
"Logging": {
"LogLevel": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public override void OnApplicationInitialization(ApplicationInitializationContex
app.UseAbpClaimsMap();
app.UseAuthorization();
app.UseSwagger();
app.UseAbpSwaggerUI(options =>
app.UseAbpSwaggerWithCustomScriptUI(options =>
{
var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>();
options.SwaggerEndpoint("/swagger/v1/swagger.json", "Payment Service API");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"Authority": "http://localhost:8080/realms/master",
"RequireHttpsMetadata": "false",
"MetadataAddress": "http://localhost:8080/realms/master",
"SwaggerClientId": "WebGateway_Swagger"
"SwaggerClientId": "SwaggerClient"
},
"Logging": {
"LogLevel": {
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,19 @@
<ProjectReference Include="..\EShopOnAbp.Shared.Localization\EShopOnAbp.Shared.Localization.csproj" />
</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>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Volo.Abp.AspNetCore.Serilog;
using Volo.Abp.Modularity;
using Volo.Abp.Swashbuckle;
using Volo.Abp.VirtualFileSystem;

namespace EShopOnAbp.Shared.Hosting.AspNetCore;

Expand All @@ -14,5 +15,9 @@ public class EShopOnAbpSharedHostingAspNetCoreModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<AbpVirtualFileSystemOptions>(options =>
{
options.FileSets.AddEmbedded<EShopOnAbpSharedHostingAspNetCoreModule>("EShopOnAbp.Shared.Hosting.AspNetCore");
});
}
}
Original file line number Diff line number Diff line change
@@ -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);
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Linq;
using EShopOnAbp.Shared.Hosting.AspNetCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -15,7 +16,7 @@ public static IApplicationBuilder UseSwaggerUIWithYarp(this IApplicationBuilder
ApplicationInitializationContext context)
{
app.UseSwagger();
app.UseAbpSwaggerUI(options =>
app.UseAbpSwaggerWithCustomScriptUI(options =>
{
var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>();
var logger = context.ServiceProvider.GetRequiredService<ILogger<ApplicationInitializationContext>>();
Expand Down

0 comments on commit acc8a1c

Please sign in to comment.