@ -1,29 +1,38 @@
using System ;
using System ;
using System.Collections.Generic ;
using System.IO ;
using System.IO ;
using System.Linq ;
using System.Net ;
using System.Reflection ;
using System.Reflection ;
using System.Security.Principal ;
using System.Text ;
using System.Text ;
using System.Threading.Tasks ;
using Microsoft.AspNetCore.Authentication.JwtBearer ;
using Microsoft.AspNetCore.Authentication.JwtBearer ;
using Microsoft.AspNetCore.Builder ;
using Microsoft.AspNetCore.Mvc.ApiExplorer ;
using Microsoft.AspNetCore.Http ;
using Microsoft.EntityFrameworkCore ;
using Microsoft.Extensions.Configuration ;
using Microsoft.Extensions.Configuration ;
using Microsoft.Extensions.DependencyInjection ;
using Microsoft.Extensions.DependencyInjection ;
using Microsoft.Extensions.PlatformAbstractions ;
using Microsoft.IdentityModel.Tokens ;
using Microsoft.IdentityModel.Tokens ;
using Ombi.Config ;
using Ombi.Config ;
using Ombi.Core.Authentication ;
using Ombi.Core.Settings ;
using Ombi.Helpers ;
using Ombi.Helpers ;
using Ombi.Models.Identity ;
using Ombi.Models.Identity ;
using Ombi.Settings.Settings.Models ;
using Swashbuckle.AspNetCore.Swagger ;
using Swashbuckle.AspNetCore.Swagger ;
using Swashbuckle.AspNetCore.SwaggerGen ;
namespace Ombi
namespace Ombi
{
{
public class AddRequiredHeaderParameter : IOperationFilter
{
public void Apply ( Operation operation , OperationFilterContext context )
{
if ( operation . Parameters = = null )
operation . Parameters = new List < IParameter > ( ) ;
operation . Parameters . Add ( new NonBodyParameter
{
Name = "ApiKey" ,
In = "header" ,
Type = "apiKey" ,
} ) ;
}
}
public static class StartupExtensions
public static class StartupExtensions
{
{
public static void AddSwagger ( this IServiceCollection services )
public static void AddSwagger ( this IServiceCollection services )
@ -35,17 +44,37 @@ namespace Ombi
{
{
Version = "v1" ,
Version = "v1" ,
Title = "Ombi Api" ,
Title = "Ombi Api" ,
Description = "The API for Ombi, most of these calls require an auth token that you can get from calling POST:\"/api/v1/token\" with the body of: \n {\n\"username\":\"YOURUSERNAME\",\n\"password\":\"YOURPASSWORD\"\n} \n" +
"You can then use the returned token in the JWT Token field e.g. \"Bearer Token123xxff\"" ,
Contact = new Contact
Contact = new Contact
{
{
Email = "tidusjar@gmail.com" ,
Name = "Jamie Rees" ,
Name = "Jamie Rees" ,
Url = "https://www.ombi.io/"
Url = "https://www.ombi.io/"
}
}
} ) ;
} ) ;
var security = new Dictionary < string , IEnumerable < string > >
{
//{"Bearer", new string[] { }},
{ "ApiKey" , new string [ ] { } } ,
} ;
//c.AddSecurityDefinition("Bearer", new ApiKeyScheme
//{
// Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"",
// Name = "Authorization",
// In = "header",
// Type = "apiKey"
//});
c . AddSecurityDefinition ( "ApiKey" , new ApiKeyScheme
{
Description = "API Key provided by Ombi. Example: \"ApiKey: {token}\"" ,
Name = "ApiKey" ,
In = "header" ,
Type = "apiKey"
} ) ;
c . AddSecurityRequirement ( security ) ;
c . CustomSchemaIds ( x = > x . FullName ) ;
c . CustomSchemaIds ( x = > x . FullName ) ;
var basePath = PlatformServices . Default . Application . ApplicationBasePath ;
c . OperationFilter < AddRequiredHeaderParameter > ( ) ;
var basePath = Path . GetDirectoryName ( Assembly . GetEntryAssembly ( ) . Location ) ;
var xmlPath = Path . Combine ( basePath , "Swagger.xml" ) ;
var xmlPath = Path . Combine ( basePath , "Swagger.xml" ) ;
try
try
{
{
@ -55,13 +84,7 @@ namespace Ombi
{
{
Console . WriteLine ( e ) ;
Console . WriteLine ( e ) ;
}
}
c . AddSecurityDefinition ( "Bearer" , new JwtBearer
{
Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"" ,
Name = "Authorization" ,
In = "header" ,
Type = "apiKey" ,
} ) ;
c . OperationFilter < SwaggerOperationFilter > ( ) ;
c . OperationFilter < SwaggerOperationFilter > ( ) ;
c . DescribeAllParametersInCamelCase ( ) ;
c . DescribeAllParametersInCamelCase ( ) ;