|
|
@ -1,13 +1,9 @@
|
|
|
|
using System;
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
using System.IO;
|
|
|
|
using System.IO;
|
|
|
|
using System.Reflection;
|
|
|
|
using System.Reflection;
|
|
|
|
using System.Text;
|
|
|
|
using System.Text;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
|
|
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
|
|
|
using Microsoft.AspNetCore.JsonPatch.Operations;
|
|
|
|
|
|
|
|
using Microsoft.AspNetCore.Mvc.ApiExplorer;
|
|
|
|
|
|
|
|
using Microsoft.AspNetCore.SignalR;
|
|
|
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
using Microsoft.IdentityModel.Tokens;
|
|
|
|
using Microsoft.IdentityModel.Tokens;
|
|
|
@ -15,8 +11,6 @@ using Microsoft.OpenApi.Models;
|
|
|
|
using Ombi.Config;
|
|
|
|
using Ombi.Config;
|
|
|
|
using Ombi.Helpers;
|
|
|
|
using Ombi.Helpers;
|
|
|
|
using Ombi.Models.Identity;
|
|
|
|
using Ombi.Models.Identity;
|
|
|
|
using Swashbuckle.AspNetCore.Swagger;
|
|
|
|
|
|
|
|
using Swashbuckle.AspNetCore.SwaggerGen;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Ombi
|
|
|
|
namespace Ombi
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -26,7 +20,7 @@ namespace Ombi
|
|
|
|
{
|
|
|
|
{
|
|
|
|
services.AddSwaggerGen(c =>
|
|
|
|
services.AddSwaggerGen(c =>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
c.SwaggerDoc("v1", new OpenApiInfo()
|
|
|
|
c.SwaggerDoc("v1", new OpenApiInfo
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Version = "v1",
|
|
|
|
Version = "v1",
|
|
|
|
Title = "Ombi Api V1",
|
|
|
|
Title = "Ombi Api V1",
|
|
|
@ -37,9 +31,6 @@ namespace Ombi
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
c.AddSecurityDefinition("ApiKey", new OpenApiSecurityScheme
|
|
|
|
c.AddSecurityDefinition("ApiKey", new OpenApiSecurityScheme
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Description = "API Key provided by Ombi. Example: \"ApiKey: {token}\"",
|
|
|
|
Description = "API Key provided by Ombi. Example: \"ApiKey: {token}\"",
|
|
|
@ -47,25 +38,32 @@ namespace Ombi
|
|
|
|
In = ParameterLocation.Header,
|
|
|
|
In = ParameterLocation.Header,
|
|
|
|
Type = SecuritySchemeType.ApiKey
|
|
|
|
Type = SecuritySchemeType.ApiKey
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
c.CustomSchemaIds(x => x.FullName);
|
|
|
|
c.CustomSchemaIds(x => x.FullName);
|
|
|
|
var basePath = Path.GetDirectoryName(AppContext.BaseDirectory);
|
|
|
|
|
|
|
|
var xmlPath = Path.Combine(basePath, "Swagger.xml");
|
|
|
|
|
|
|
|
try
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
string basePath = Path.GetDirectoryName(AppContext.BaseDirectory);
|
|
|
|
|
|
|
|
string assemblyName = Assembly.GetExecutingAssembly().GetName().Name;
|
|
|
|
|
|
|
|
string xmlPath = Path.Combine(basePath ?? string.Empty, $"{assemblyName}.xml");
|
|
|
|
|
|
|
|
if (File.Exists(xmlPath))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
c.IncludeXmlComments(xmlPath);
|
|
|
|
c.IncludeXmlComments(xmlPath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Console.WriteLine($"Swagger failed to find documentation file at '{xmlPath}'.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Console.WriteLine(e);
|
|
|
|
Console.WriteLine(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
c.DescribeAllParametersInCamelCase();
|
|
|
|
c.DescribeAllParametersInCamelCase();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void AddAppSettingsValues(this IServiceCollection services, IConfigurationRoot configuration)
|
|
|
|
public static void AddAppSettingsValues(this IServiceCollection services, IConfigurationRoot configuration)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
services.Configure<ApplicationSettings>(configuration.GetSection("ApplicationSettings"));
|
|
|
|
services.Configure<ApplicationSettings>(configuration.GetSection("ApplicationSettings"));
|
|
|
@ -78,13 +76,10 @@ namespace Ombi
|
|
|
|
|
|
|
|
|
|
|
|
public static void AddJwtAuthentication(this IServiceCollection services, IConfigurationRoot configuration)
|
|
|
|
public static void AddJwtAuthentication(this IServiceCollection services, IConfigurationRoot configuration)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var tokenOptions = configuration.GetSection("TokenAuthentication");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var tokenValidationParameters = new TokenValidationParameters
|
|
|
|
var tokenValidationParameters = new TokenValidationParameters
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ValidateIssuerSigningKey = true,
|
|
|
|
ValidateIssuerSigningKey = true,
|
|
|
|
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(StartupSingleton.Instance.SecurityKey)),
|
|
|
|
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(StartupSingleton.Instance.SecurityKey)),
|
|
|
|
|
|
|
|
|
|
|
|
RequireExpirationTime = true,
|
|
|
|
RequireExpirationTime = true,
|
|
|
|
ValidateLifetime = true,
|
|
|
|
ValidateLifetime = true,
|
|
|
|
ValidAudience = "Ombi",
|
|
|
|
ValidAudience = "Ombi",
|
|
|
@ -92,11 +87,13 @@ namespace Ombi
|
|
|
|
ClockSkew = TimeSpan.Zero,
|
|
|
|
ClockSkew = TimeSpan.Zero,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
services.AddAuthentication(options =>
|
|
|
|
services
|
|
|
|
|
|
|
|
.AddAuthentication(options =>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
|
|
|
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
|
|
|
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
|
|
|
|
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
|
|
|
|
}).AddJwtBearer(x =>
|
|
|
|
})
|
|
|
|
|
|
|
|
.AddJwtBearer(x =>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
x.Audience = "Ombi";
|
|
|
|
x.Audience = "Ombi";
|
|
|
|
x.TokenValidationParameters = tokenValidationParameters;
|
|
|
|
x.TokenValidationParameters = tokenValidationParameters;
|
|
|
@ -114,11 +111,11 @@ namespace Ombi
|
|
|
|
// Read the token out of the query string
|
|
|
|
// Read the token out of the query string
|
|
|
|
context.Token = accessToken;
|
|
|
|
context.Token = accessToken;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
return Task.CompletedTask;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|