@ -96,31 +96,10 @@ namespace Ombi
options . Password . RequireUppercase = false ;
} ) ;
services . AddDataProtection ( ) ;
services . AddMemoryCache ( ) ;
var tokenOptions = Configuration . GetSection ( "TokenAuthentication" ) ;
var tokenValidationParameters = new TokenValidationParameters
{
ValidateIssuerSigningKey = true ,
IssuerSigningKey = new SymmetricSecurityKey ( Encoding . UTF8 . GetBytes ( tokenOptions . GetValue ( "SecretKey" , string . Empty ) ) ) ,
RequireExpirationTime = true ,
ValidateLifetime = true ,
ValidAudience = "Ombi" ,
ValidIssuer = "Ombi" ,
ClockSkew = TimeSpan . Zero ,
} ;
services . AddAuthentication ( options = >
{
options . DefaultAuthenticateScheme = JwtBearerDefaults . AuthenticationScheme ;
options . DefaultChallengeScheme = JwtBearerDefaults . AuthenticationScheme ;
} ) . AddJwtBearer ( x = >
{
x . Audience = "Ombi" ;
x . TokenValidationParameters = tokenValidationParameters ;
} ) ;
services . AddJwtAuthentication ( Configuration ) ;
services . AddMvc ( )
. AddJsonOptions ( x = > x . SerializerSettings . ReferenceLoopHandling = Newtonsoft . Json . ReferenceLoopHandling . Ignore ) ;
@ -130,54 +109,10 @@ namespace Ombi
{
expression . AddCollectionMappers ( ) ;
} ) ;
services . RegisterDependencies ( ) ; // Ioc and EF
services . AddSwaggerGen ( c = >
{
c . DescribeAllEnumsAsStrings ( ) ;
c . SwaggerDoc ( "v1" , new Info
{
Version = "v1" ,
Title = "Ombi Api" ,
Description = "The API for Ombi, most of these calls require an auth token that you can get from calling POST:\"/connect/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
{
Email = "tidusjar@gmail.com" ,
Name = "Jamie Rees" ,
Url = "https://www.ombi.io/"
}
} ) ;
c . CustomSchemaIds ( x = > x . FullName ) ;
var basePath = PlatformServices . Default . Application . ApplicationBasePath ;
var xmlPath = Path . Combine ( basePath , "Swagger.xml" ) ;
try
{
c . IncludeXmlComments ( xmlPath ) ;
}
catch ( Exception e )
{
Console . WriteLine ( e ) ;
}
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 ( "Authentication" , new ApiKeyScheme ( ) ) ;
c . OperationFilter < SwaggerOperationFilter > ( ) ;
c . DescribeAllParametersInCamelCase ( ) ;
} ) ;
services . AddSingleton < IHttpContextAccessor , HttpContextAccessor > ( ) ;
services . AddScoped < IPrincipal > ( sp = > sp . GetService < IHttpContextAccessor > ( ) . HttpContext . User ) ;
services . Configure < ApplicationSettings > ( Configuration . GetSection ( "ApplicationSettings" ) ) ;
services . Configure < UserSettings > ( Configuration . GetSection ( "UserSettings" ) ) ;
services . Configure < TokenAuthentication > ( Configuration . GetSection ( "TokenAuthentication" ) ) ;
services . Configure < LandingPageBackground > ( Configuration . GetSection ( "LandingPageBackground" ) ) ;
services . RegisterApplicationDependencies ( ) ; // Ioc and EF
services . AddSwagger ( ) ;
services . AddAppSettingsValues ( Configuration ) ;
services . AddHangfire ( x = >
{
@ -188,10 +123,7 @@ namespace Ombi
} ) ;
// Build the intermediate service provider
var serviceProvider = services . BuildServiceProvider ( ) ;
//return the provider
return serviceProvider ;
return services . BuildServiceProvider ( ) ;
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@ -221,8 +153,6 @@ namespace Ombi
Authorization = new [ ] { new HangfireAuthorizationFilter ( ) }
} ) ;
// Setup the scheduler
var jobSetup = ( IJobSetup ) app . ApplicationServices . GetService ( typeof ( IJobSetup ) ) ;
jobSetup . Setup ( ) ;
@ -251,7 +181,6 @@ namespace Ombi
} ) ;
app . UseSwaggerUI ( c = >
{
c . SwaggerEndpoint ( "/swagger/v1/swagger.json" , "My API V1" ) ;
c . ShowJsonEditor ( ) ;
} ) ;