From 53757f1079d371cf8182462b5c75906c656e6ceb Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Tue, 5 Dec 2023 10:59:25 +0800 Subject: [PATCH 1/2] Swagger Oidc support multi-tenant --- .../wwwroot/swagger/ui/abp.swagger.js | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/framework/src/Volo.Abp.Swashbuckle/wwwroot/swagger/ui/abp.swagger.js b/framework/src/Volo.Abp.Swashbuckle/wwwroot/swagger/ui/abp.swagger.js index 70bf976bc4..aba50b26c2 100644 --- a/framework/src/Volo.Abp.Swashbuckle/wwwroot/swagger/ui/abp.swagger.js +++ b/framework/src/Volo.Abp.Swashbuckle/wwwroot/swagger/ui/abp.swagger.js @@ -9,11 +9,14 @@ var abp = abp || {}; var oidcSupportedFlows = configObject.oidcSupportedFlows || []; var oidcSupportedScopes = configObject.oidcSupportedScopes || []; var oidcDiscoveryEndpoint = configObject.oidcDiscoveryEndpoint || []; + var tenantPlaceHolders = ["{{tenantId}}", "{{tenantName}}" , "{{0}}"] abp.appPath = configObject.baseUrl || abp.appPath; var requestInterceptor = configObject.requestInterceptor; var responseInterceptor = configObject.responseInterceptor; + getAbpApplicationConfiguration(); + configObject.requestInterceptor = async function (request) { if (request.url.includes(excludeUrl[1])) { @@ -29,14 +32,15 @@ var abp = abp || {}; // Intercept .well-known request when the discoveryEndpoint is provided if (!firstRequest && oidcDiscoveryEndpoint.length !== 0 && request.url.includes(".well-known/openid-configuration")) { if (oidcDiscoveryEndpoint.endsWith(".well-known/openid-configuration")) { - request.url = oidcDiscoveryEndpoint; + request.url = replaceTenantPlaceHolder(oidcDiscoveryEndpoint); console.log(request.url); return; } if (!oidcDiscoveryEndpoint.endsWith("/")) { oidcDiscoveryEndpoint += "/" } - request.url = oidcDiscoveryEndpoint + ".well-known/openid-configuration"; + request.url = replaceTenantPlaceHolder(oidcDiscoveryEndpoint) + ".well-known/openid-configuration"; + console.log(request.url); } @@ -79,6 +83,26 @@ var abp = abp || {}; } return response; }; + + function replaceTenantPlaceHolder(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); + }else if (abp.currentTenant.id != null){ + url.replace(tenantPlaceHolders[2], abp.currentTenant.id); + } + + return url; + } + + function getAbpApplicationConfiguration() { + fetch(`${abp.appPath}api/abp/application-configuration`).then(response => response.json()).then(data => { + abp.currentTenant = data.currentTenant; + }); + } return SwaggerUIBundle(configObject); } From 4d0912559dc80692264052add737e2486af54b7f Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Tue, 5 Dec 2023 11:11:03 +0800 Subject: [PATCH 2/2] Update abp.swagger.js --- .../src/Volo.Abp.Swashbuckle/wwwroot/swagger/ui/abp.swagger.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/src/Volo.Abp.Swashbuckle/wwwroot/swagger/ui/abp.swagger.js b/framework/src/Volo.Abp.Swashbuckle/wwwroot/swagger/ui/abp.swagger.js index aba50b26c2..23e9420145 100644 --- a/framework/src/Volo.Abp.Swashbuckle/wwwroot/swagger/ui/abp.swagger.js +++ b/framework/src/Volo.Abp.Swashbuckle/wwwroot/swagger/ui/abp.swagger.js @@ -9,7 +9,7 @@ var abp = abp || {}; var oidcSupportedFlows = configObject.oidcSupportedFlows || []; var oidcSupportedScopes = configObject.oidcSupportedScopes || []; var oidcDiscoveryEndpoint = configObject.oidcDiscoveryEndpoint || []; - var tenantPlaceHolders = ["{{tenantId}}", "{{tenantName}}" , "{{0}}"] + var tenantPlaceHolders = ["{{tenantId}}", "{{tenantName}}" , "{0}"] abp.appPath = configObject.baseUrl || abp.appPath; var requestInterceptor = configObject.requestInterceptor;