Browse Source

Add scopes

pull/16574/head
liangshiwei 3 years ago
parent
commit
5a7764fc07
  1. 18
      framework/src/Volo.Abp.Swashbuckle/Microsoft/Extensions/DependencyInjection/AbpSwaggerGenServiceCollectionExtensions.cs
  2. 13
      framework/src/Volo.Abp.Swashbuckle/wwwroot/swagger/ui/abp.swagger.js

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

@ -82,16 +82,21 @@ public static class AbpSwaggerGenServiceCollectionExtensions
public static IServiceCollection AddAbpSwaggerGenWithOidc(
this IServiceCollection services,
[NotNull] string authority,
Action<SwaggerGenOptions> setupAction = null,
List<string> flows = null,
string openIdConnectDiscoveryEndpoint = "/.well-known/openid-configuration")
string[] scopes = null,
string[] flows = null,
string discoveryEndpoint = null,
Action<SwaggerGenOptions> setupAction = null)
{
var openIdConnectDiscoveryUrl = new Uri($"{authority.TrimEnd('/')}{openIdConnectDiscoveryEndpoint.EnsureStartsWith('/')}");
flows ??= new List<string> { "authorization_code"};
var discoveryUrl = discoveryEndpoint != null ?
new Uri(discoveryEndpoint) :
new Uri($"{authority.TrimEnd('/')}/.well-known/openid-configuration");
flows ??= new [] { "authorization_code" };
services.Configure<SwaggerUIOptions>(swaggerUiOptions =>
{
swaggerUiOptions.ConfigObject.AdditionalItems["oidcSupportedFlows"] = flows;
swaggerUiOptions.ConfigObject.AdditionalItems["oidcSupportedScopes"] = scopes;
});
return services
@ -102,8 +107,7 @@ public static class AbpSwaggerGenServiceCollectionExtensions
options.AddSecurityDefinition("oidc", new OpenApiSecurityScheme
{
Type = SecuritySchemeType.OpenIdConnect,
OpenIdConnectUrl = openIdConnectDiscoveryUrl,
OpenIdConnectUrl = discoveryUrl
});
options.AddSecurityRequirement(new OpenApiSecurityRequirement

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

@ -7,6 +7,7 @@ var abp = abp || {};
var excludeUrl = ["swagger.json", "connect/token"]
var firstRequest = true;
var oidcSupportedFlows = configObject.oidcSupportedFlows || [];
var oidcSupportedScopes = configObject.oidcSupportedScopes || [];
abp.appPath = configObject.baseUrl || abp.appPath;
var requestInterceptor = configObject.requestInterceptor;
@ -41,9 +42,17 @@ var abp = abp || {};
};
configObject.responseInterceptor = async function(response) {
if(response.url.endsWith(".well-known/openid-configuration") && response.status === 200 && oidcSupportedFlows.length > 0) {
if(response.url.endsWith(".well-known/openid-configuration") && response.status === 200) {
var openIdConnectData = JSON.parse(response.text);
openIdConnectData.grant_types_supported = oidcSupportedFlows;
if(oidcSupportedFlows.length > 0){
openIdConnectData.grant_types_supported = oidcSupportedFlows;
}
if(oidcSupportedScopes.length > 0) {
openIdConnectData.scopes_supported = oidcSupportedScopes;
}
response.text = JSON.stringify(openIdConnectData);
}

Loading…
Cancel
Save