@ -2,16 +2,13 @@
using System.IO ;
using System.IO ;
using System.Linq ;
using System.Linq ;
using System.Security.Principal ;
using System.Security.Principal ;
using System.Text ;
using AutoMapper ;
using AutoMapper ;
using AutoMapper.EquivalencyExpression ;
using AutoMapper.EquivalencyExpression ;
using Hangfire ;
using Hangfire ;
using Hangfire.MemoryStorage ;
using Hangfire.MemoryStorage ;
using Hangfire.SQLite ;
using IdentityServer4.Services ;
using IdentityServer4.Validation ;
using Microsoft.AspNetCore.Builder ;
using Microsoft.AspNetCore.Builder ;
using Microsoft.AspNetCore.Hosting ;
using Microsoft.AspNetCore.Hosting ;
using Microsoft.AspNetCore.Hosting.Server.Features ;
using Microsoft.AspNetCore.Http ;
using Microsoft.AspNetCore.Http ;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore ;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore ;
using Microsoft.AspNetCore.SpaServices.Webpack ;
using Microsoft.AspNetCore.SpaServices.Webpack ;
@ -25,10 +22,10 @@ using Microsoft.Extensions.Options;
using Microsoft.Extensions.PlatformAbstractions ;
using Microsoft.Extensions.PlatformAbstractions ;
using Microsoft.IdentityModel.Tokens ;
using Microsoft.IdentityModel.Tokens ;
using Ombi.Config ;
using Ombi.Config ;
using Ombi.Core.IdentityResolver ;
using Ombi.DependencyInjection ;
using Ombi.DependencyInjection ;
using Ombi.Helpers ;
using Ombi.Helpers ;
using Ombi.Mapping ;
using Ombi.Mapping ;
using Ombi.Models.Identity ;
using Ombi.Schedule ;
using Ombi.Schedule ;
using Ombi.Store.Context ;
using Ombi.Store.Context ;
using Ombi.Store.Entities ;
using Ombi.Store.Entities ;
@ -83,15 +80,16 @@ namespace Ombi
. AddEntityFrameworkStores < OmbiContext > ( )
. AddEntityFrameworkStores < OmbiContext > ( )
. AddDefaultTokenProviders ( ) ;
. AddDefaultTokenProviders ( ) ;
services . AddIdentityServer ( )
. AddTemporarySigningCredential ( )
//services.AddIdentityServer()
. AddInMemoryPersistedGrants ( )
// .AddTemporarySigningCredential()
. AddInMemoryIdentityResources ( IdentityConfig . GetIdentityResources ( ) )
// .AddInMemoryPersistedGrants()
. AddInMemoryApiResources ( IdentityConfig . GetApiResources ( ) )
// .AddInMemoryIdentityResources(IdentityConfig.GetIdentityResources())
. AddInMemoryClients ( IdentityConfig . GetClients ( ) )
// .AddInMemoryApiResources(IdentityConfig.GetApiResources())
. AddAspNetIdentity < OmbiUser > ( )
// .AddInMemoryClients(IdentityConfig.GetClients())
. Services . AddTransient < IResourceOwnerPasswordValidator , OmbiOwnerPasswordValidator > ( )
// .AddAspNetIdentity<OmbiUser>()
. AddTransient < IProfileService , OmbiProfileService > ( ) ;
// .Services.AddTransient<IResourceOwnerPasswordValidator, OmbiOwnerPasswordValidator>()
// .AddTransient<IProfileService, OmbiProfileService>();
services . Configure < IdentityOptions > ( options = >
services . Configure < IdentityOptions > ( options = >
{
{
@ -151,10 +149,9 @@ namespace Ombi
services . AddSingleton < IHttpContextAccessor , HttpContextAccessor > ( ) ;
services . AddSingleton < IHttpContextAccessor , HttpContextAccessor > ( ) ;
services . AddScoped < IPrincipal > ( sp = > sp . GetService < IHttpContextAccessor > ( ) . HttpContext . User ) ;
services . AddScoped < IPrincipal > ( sp = > sp . GetService < IHttpContextAccessor > ( ) . HttpContext . User ) ;
//services.Configure<TokenAuthenticationOptions>(Configuration.GetSection("TokenAuthentication"));
services . Configure < ApplicationSettings > ( Configuration . GetSection ( "ApplicationSettings" ) ) ;
services . Configure < ApplicationSettings > ( Configuration . GetSection ( "ApplicationSettings" ) ) ;
services . Configure < UserSettings > ( Configuration . GetSection ( "UserSettings" ) ) ;
services . Configure < UserSettings > ( Configuration . GetSection ( "UserSettings" ) ) ;
services . Configure < TokenAuthentication > ( Configuration . GetSection ( "TokenAuthentication" ) ) ;
services . Configure < LandingPageBackground > ( Configuration . GetSection ( "LandingPageBackground" ) ) ;
services . Configure < LandingPageBackground > ( Configuration . GetSection ( "LandingPageBackground" ) ) ;
services . AddHangfire ( x = >
services . AddHangfire ( x = >
@ -179,8 +176,8 @@ namespace Ombi
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure ( IApplicationBuilder app , IHostingEnvironment env , ILoggerFactory loggerFactory , IMemoryCache cache )
public void Configure ( IApplicationBuilder app , IHostingEnvironment env , ILoggerFactory loggerFactory , IMemoryCache cache )
{
{
var options = ( IOptions < UserSettings> ) app . ApplicationServices . GetService (
var t okenO ptions = ( IOptions < TokenAuthentication> ) app . ApplicationServices . GetService (
typeof ( IOptions < UserSettings > ) ) ;
typeof ( IOptions < TokenAuthentication > ) ) ;
var ctx = ( IOmbiContext ) app . ApplicationServices . GetService ( typeof ( IOmbiContext ) ) ;
var ctx = ( IOmbiContext ) app . ApplicationServices . GetService ( typeof ( IOmbiContext ) ) ;
@ -190,26 +187,54 @@ namespace Ombi
Console . WriteLine ( $"Using Url {url.Value}:{port.Value} for Identity Server" ) ;
Console . WriteLine ( $"Using Url {url.Value}:{port.Value} for Identity Server" ) ;
app . UseIdentity ( ) ;
app . UseIdentity ( ) ;
app . UseIdentityServer ( ) ;
app . UseIdentityServerAuthentication ( new IdentityServerAuthenticationOptions
{
#if !DEBUG
#if !DEBUG
Authority = $"{url.Value}:{port.Value}" ,
var audience = $"{url.Value}:{port.Value}" ;
# else
# else
Authority = $"http://localhost:52038/" ,
var audience = $"http://localhost:52038/" ;
# endif
# endif
ApiName = "api" ,
ApiSecret = "secret" ,
EnableCaching = true ,
var tokenValidationParameters = new TokenValidationParameters
CacheDuration = TimeSpan . FromMinutes ( 10 ) , // that's the default
{
RequireHttpsMetadata = options . Value . UseHttps , // FOR DEV set to false
AutomaticAuthenticate = true ,
ValidateIssuerSigningKey = true ,
AutomaticChallenge = true ,
IssuerSigningKey = new SymmetricSecurityKey ( Encoding . UTF8 . GetBytes ( tokenOptions . Value . SecretKey ) ) ,
RequireExpirationTime = true ,
ValidateLifetime = true ,
ValidAudience = "Ombi" ,
ValidIssuer = "Ombi" ,
ClockSkew = TimeSpan . Zero
} ;
app . UseJwtBearerAuthentication ( new JwtBearerOptions ( )
{
Audience = "Ombi" ,
AutomaticAuthenticate = true ,
TokenValidationParameters = tokenValidationParameters
} ) ;
} ) ;
// app.UseIdentityServer();
// app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
// {
//#if !DEBUG
// Authority = $"{url.Value}:{port.Value}",
//#else
// Authority = $"http://localhost:52038/",
//#endif
// ApiName = "api",
// ApiSecret = "secret",
// EnableCaching = true,
// CacheDuration = TimeSpan.FromMinutes(10), // that's the default
// RequireHttpsMetadata = options.Value.UseHttps, // FOR DEV set to false
// AutomaticAuthenticate = true,
// AutomaticChallenge = true,
// });
loggerFactory . AddSerilog ( ) ;
loggerFactory . AddSerilog ( ) ;
if ( env . IsDevelopment ( ) )
if ( env . IsDevelopment ( ) )