Merge pull request #3220 from crobibero/api-swagger-auth

Add Authentication to openapi generation.
This commit is contained in:
dkanada 2020-06-13 13:48:33 +09:00 committed by GitHub
commit d975ad155e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -120,6 +120,25 @@ namespace Jellyfin.Server.Extensions
return serviceCollection.AddSwaggerGen(c =>
{
c.SwaggerDoc("api-docs", new OpenApiInfo { Title = "Jellyfin API", Version = "v1" });
c.AddSecurityDefinition(AuthenticationSchemes.CustomAuthentication, new OpenApiSecurityScheme
{
Type = SecuritySchemeType.ApiKey,
In = ParameterLocation.Header,
Name = "X-Emby-Token",
Description = "API key header parameter"
});
var securitySchemeRef = new OpenApiSecurityScheme
{
Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = AuthenticationSchemes.CustomAuthentication },
};
// TODO: Apply this with an operation filter instead of globally
// https://github.com/domaindrivendev/Swashbuckle.AspNetCore#add-security-definitions-and-requirements
c.AddSecurityRequirement(new OpenApiSecurityRequirement
{
{ securitySchemeRef, Array.Empty<string>() }
});
// Add all xml doc files to swagger generator.
var xmlFiles = Directory.GetFiles(