Browse Source

Merge pull request #8661 from abpframework/auto-merge/rel-4-3/315

Merge branch dev with rel-4.3
pull/8662/head
Ahmet Çotur 6 years ago
committed by GitHub
parent
commit
29045c2c36
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 74
      framework/src/Volo.Abp.Swashbuckle/Microsoft/Extensions/DependencyInjection/AbpSwaggerGenServiceCollectionExtensions.cs

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

@ -3,52 +3,74 @@ using System.Collections.Generic;
using JetBrains.Annotations; using JetBrains.Annotations;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen; using Swashbuckle.AspNetCore.SwaggerGen;
using Volo.Abp.Content;
namespace Microsoft.Extensions.DependencyInjection namespace Microsoft.Extensions.DependencyInjection
{ {
public static class AbpSwaggerGenServiceCollectionExtensions public static class AbpSwaggerGenServiceCollectionExtensions
{ {
public static IServiceCollection AddAbpSwaggerGenWithOAuth( public static IServiceCollection AddAbpSwaggerGen(
this IServiceCollection services, this IServiceCollection services,
[NotNull] string authority,
[NotNull] Dictionary<string, string> scopes,
Action<SwaggerGenOptions> setupAction = null) Action<SwaggerGenOptions> setupAction = null)
{ {
return services.AddSwaggerGen( return services.AddSwaggerGen(
options => options =>
{ {
options.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme Func<OpenApiSchema> remoteStreamContentSchemaFactory = () => new OpenApiSchema()
{ {
Type = SecuritySchemeType.OAuth2, Type = "string",
Flows = new OpenApiOAuthFlows Format = "binary"
{ };
AuthorizationCode = new OpenApiOAuthFlow
{
AuthorizationUrl = new Uri($"{authority.EnsureEndsWith('/')}connect/authorize"),
Scopes = scopes,
TokenUrl = new Uri($"{authority.EnsureEndsWith('/')}connect/token")
}
}
});
options.AddSecurityRequirement(new OpenApiSecurityRequirement options.MapType<RemoteStreamContent>(remoteStreamContentSchemaFactory);
options.MapType<IRemoteStreamContent>(remoteStreamContentSchemaFactory);
setupAction?.Invoke(options);
});
}
public static IServiceCollection AddAbpSwaggerGenWithOAuth(
this IServiceCollection services,
[NotNull] string authority,
[NotNull] Dictionary<string, string> scopes,
Action<SwaggerGenOptions> setupAction = null)
{
return services
.AddAbpSwaggerGen()
.AddSwaggerGen(
options =>
{ {
options.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme
{ {
new OpenApiSecurityScheme Type = SecuritySchemeType.OAuth2,
Flows = new OpenApiOAuthFlows
{ {
Reference = new OpenApiReference AuthorizationCode = new OpenApiOAuthFlow
{ {
Type = ReferenceType.SecurityScheme, AuthorizationUrl = new Uri($"{authority.EnsureEndsWith('/')}connect/authorize"),
Id = "oauth2" Scopes = scopes,
TokenUrl = new Uri($"{authority.EnsureEndsWith('/')}connect/token")
} }
}, }
Array.Empty<string>() });
}
});
options.AddSecurityRequirement(new OpenApiSecurityRequirement
{
{
new OpenApiSecurityScheme
{
Reference = new OpenApiReference
{
Type = ReferenceType.SecurityScheme,
Id = "oauth2"
}
},
Array.Empty<string>()
}
});
setupAction?.Invoke(options); setupAction?.Invoke(options);
}); });
} }
} }
} }

Loading…
Cancel
Save