Browse Source

Remove Tenant placeholders when configure Swagger Oidc

pull/20068/head
liangshiwei 2 years ago
parent
commit
747c61472a
  1. 18
      framework/src/Volo.Abp.Swashbuckle/Microsoft/Extensions/DependencyInjection/AbpSwaggerGenServiceCollectionExtensions.cs
  2. 14
      framework/src/Volo.Abp.Swashbuckle/wwwroot/swagger/ui/abp.swagger.js

18
framework/src/Volo.Abp.Swashbuckle/Microsoft/Extensions/DependencyInjection/AbpSwaggerGenServiceCollectionExtensions.cs

@ -5,6 +5,7 @@ using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;
using Swashbuckle.AspNetCore.SwaggerUI;
using Volo.Abp.Content;
using Volo.Abp.MultiTenancy;
using Volo.Abp.Swashbuckle;
namespace Microsoft.Extensions.DependencyInjection;
@ -89,16 +90,15 @@ public static class AbpSwaggerGenServiceCollectionExtensions
Action<SwaggerGenOptions>? setupAction = null)
{
var discoveryUrl = discoveryEndpoint != null ?
new Uri($"{discoveryEndpoint.TrimEnd('/')}/.well-known/openid-configuration") :
new Uri($"{authority.TrimEnd('/')}/.well-known/openid-configuration");
$"{discoveryEndpoint.TrimEnd('/')}/.well-known/openid-configuration":
$"{authority.TrimEnd('/')}/.well-known/openid-configuration";
flows ??= new [] { AbpSwaggerOidcFlows.AuthorizationCode };
services.Configure<SwaggerUIOptions>(swaggerUiOptions =>
{
swaggerUiOptions.ConfigObject.AdditionalItems["oidcSupportedFlows"] = flows;
swaggerUiOptions.ConfigObject.AdditionalItems["oidcSupportedScopes"] = scopes;
swaggerUiOptions.ConfigObject.AdditionalItems["oidcDiscoveryEndpoint"] = discoveryEndpoint;
swaggerUiOptions.ConfigObject.AdditionalItems["oidcDiscoveryEndpoint"] = discoveryUrl;
});
return services
@ -109,7 +109,7 @@ public static class AbpSwaggerGenServiceCollectionExtensions
options.AddSecurityDefinition("oidc", new OpenApiSecurityScheme
{
Type = SecuritySchemeType.OpenIdConnect,
OpenIdConnectUrl = discoveryUrl
OpenIdConnectUrl = new Uri(RemoveTenantPlaceholders(discoveryUrl))
});
options.AddSecurityRequirement(new OpenApiSecurityRequirement
@ -129,4 +129,12 @@ public static class AbpSwaggerGenServiceCollectionExtensions
setupAction?.Invoke(options);
});
}
private static string RemoveTenantPlaceholders(string url)
{
return url
.Replace(MultiTenantUrlProvider.TenantPlaceHolder + ".", string.Empty)
.Replace(MultiTenantUrlProvider.TenantIdPlaceHolder + ".", string.Empty)
.Replace(MultiTenantUrlProvider.TenantNamePlaceHolder + ".", string.Empty);
}
}

14
framework/src/Volo.Abp.Swashbuckle/wwwroot/swagger/ui/abp.swagger.js

@ -90,13 +90,19 @@ var abp = abp || {};
await getAbpApplicationConfiguration();
}
url.replace(tenantPlaceHolders[0], abp.currentTenant.id);
url.replace(tenantPlaceHolders[1], abp.currentTenant.name);
if(abp.currentTenant.id == null && abp.currentTenant.name == null){
return url
.replace(tenantPlaceHolders[0] + ".", "")
.replace(tenantPlaceHolders[1] + ".", "")
.replace(tenantPlaceHolders[2] + ".", "");
}
url = url.replace(tenantPlaceHolders[0], abp.currentTenant.id).url.replace(tenantPlaceHolders[1], abp.currentTenant.name);
if(abp.currentTenant.name != null){
url.replace(tenantPlaceHolders[2], abp.currentTenant.name);
url = url.replace(tenantPlaceHolders[2], abp.currentTenant.name);
}else if (abp.currentTenant.id != null){
url.replace(tenantPlaceHolders[2], abp.currentTenant.id);
url = url.replace(tenantPlaceHolders[2], abp.currentTenant.id);
}
return url;

Loading…
Cancel
Save