From 9a2b0f6102d105664a7d1568570f05a6df290c61 Mon Sep 17 00:00:00 2001 From: "Jamie.Rees" Date: Wed, 13 Sep 2017 14:26:22 +0100 Subject: [PATCH] #1486 --- appveyor.yml | 15 +++-- build.cake | 35 +++++++---- src/Ombi.DependencyInjection/IocExtensions.cs | 11 ---- src/Ombi.sln | 3 +- src/Ombi/Controllers/TokenController.cs | 1 + src/Ombi/Startup.cs | 62 ++++++++++--------- 6 files changed, 69 insertions(+), 58 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index f6a14f1b0..d7547db5b 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,6 +1,6 @@ version: 3.0.{build} configuration: Release -os: Visual Studio 2015 +os: Visual Studio 2017 environment: nodejs_version: "7.8.0" @@ -13,19 +13,22 @@ build_script: after_build: - cmd: >- - appveyor PushArtifact "%APPVEYOR_BUILD_FOLDER%\src\Ombi\bin\Release\netcoreapp1.1\windows.zip" + appveyor PushArtifact "%APPVEYOR_BUILD_FOLDER%\src\Ombi\bin\Release\netcoreapp2.0\windows.zip" - appveyor PushArtifact "%APPVEYOR_BUILD_FOLDER%\src\Ombi\bin\Release\netcoreapp1.1\osx.tar.gz" + appveyor PushArtifact "%APPVEYOR_BUILD_FOLDER%\src\Ombi\bin\Release\netcoreapp2.0\osx.tar.gz" - appveyor PushArtifact "%APPVEYOR_BUILD_FOLDER%\src\Ombi\bin\Release\netcoreapp1.1\ubuntu.tar.gz" + appveyor PushArtifact "%APPVEYOR_BUILD_FOLDER%\src\Ombi\bin\Release\netcoreapp2.0\ubuntu.tar.gz" - appveyor PushArtifact "%APPVEYOR_BUILD_FOLDER%\src\Ombi\bin\Release\netcoreapp1.1\debian.tar.gz" + appveyor PushArtifact "%APPVEYOR_BUILD_FOLDER%\src\Ombi\bin\Release\netcoreapp2.0\debian.tar.gz" - appveyor PushArtifact "%APPVEYOR_BUILD_FOLDER%\src\Ombi\bin\Release\netcoreapp1.1\centos.tar.gz" + appveyor PushArtifact "%APPVEYOR_BUILD_FOLDER%\src\Ombi\bin\Release\netcoreapp2.0\centos.tar.gz" + + + appveyor PushArtifact "%APPVEYOR_BUILD_FOLDER%\src\Ombi\bin\Release\netcoreapp2.0\linux.tar.gz" diff --git a/build.cake b/build.cake index 17130e9dd..066c37259 100644 --- a/build.cake +++ b/build.cake @@ -42,10 +42,11 @@ var publishSettings = new DotNetCorePublishSettings var artifactsFolder = buildDir + "/netcoreapp2.0/"; var windowsArtifactsFolder = artifactsFolder + "win10-x64/published"; -var osxArtifactsFolder = artifactsFolder + "osx.10.12-x64/published"; -var ubuntuArtifactsFolder = artifactsFolder + "ubuntu.16.04-x64/published"; +var osxArtifactsFolder = artifactsFolder + "osx-x64/published"; +var ubuntuArtifactsFolder = artifactsFolder + "ubuntu-x64/published"; var debianArtifactsFolder = artifactsFolder + "debian.8-x64/published"; var centosArtifactsFolder = artifactsFolder + "centos.7-x64/published"; +var linuxArtifactsFolder = artifactsFolder + "linux-x64/published"; @@ -89,8 +90,8 @@ Task("SetVersionInfo") buildSettings.ArgumentCustomization = args => args.Append("/p:FullVer=" + fullVer); publishSettings.ArgumentCustomization = args => args.Append("/p:SemVer=" + versionInfo.AssemblySemVer); publishSettings.ArgumentCustomization = args => args.Append("/p:FullVer=" + fullVer); - buildSettings.VersionSuffix = versionInfo.BranchName; - publishSettings.VersionSuffix = versionInfo.BranchName; +// buildSettings.VersionSuffix = versionInfo.BranchName; +// publishSettings.VersionSuffix = versionInfo.BranchName; }); Task("Restore") @@ -139,12 +140,13 @@ Task("Package") GZipCompress(ubuntuArtifactsFolder, artifactsFolder + "ubuntu.tar.gz"); GZipCompress(debianArtifactsFolder, artifactsFolder + "debian.tar.gz"); GZipCompress(centosArtifactsFolder, artifactsFolder + "centos.tar.gz"); + GZipCompress(linuxArtifactsFolder, artifactsFolder + "linux.tar.gz"); }); Task("Publish") .IsDependentOn("Build") .IsDependentOn("Publish-Windows") - .IsDependentOn("Publish-OSX").IsDependentOn("Publish-Ubuntu").IsDependentOn("Publish-Debian").IsDependentOn("Publish-Centos") + .IsDependentOn("Publish-OSX").IsDependentOn("Publish-Ubuntu").IsDependentOn("Publish-Debian").IsDependentOn("Publish-Centos").IsDependentOn("Publish-Linux") .IsDependentOn("Package"); Task("Publish-Windows") @@ -161,22 +163,22 @@ Task("Publish-Windows") Task("Publish-OSX") .Does(() => { - publishSettings.Runtime = "osx.10.12-x64"; - publishSettings.OutputDirectory = Directory(buildDir) + Directory("netcoreapp2.0/osx.10.12-x64/published"); + publishSettings.Runtime = "osx-x64"; + publishSettings.OutputDirectory = Directory(buildDir) + Directory("netcoreapp2.0/osx-x64/published"); DotNetCorePublish("./src/Ombi/Ombi.csproj", publishSettings); - CopyFile(buildDir + "/netcoreapp2.0/osx.10.12-x64/Swagger.xml", buildDir + "/netcoreapp2.0/osx.10.12-x64/published/Swagger.xml"); + CopyFile(buildDir + "/netcoreapp2.0/osx-x64/Swagger.xml", buildDir + "/netcoreapp2.0/osx-x64/published/Swagger.xml"); DotNetCorePublish("./src/Ombi.Updater/Ombi.Updater.csproj", publishSettings); }); Task("Publish-Ubuntu") .Does(() => { - publishSettings.Runtime = "ubuntu.16.04-x64"; - publishSettings.OutputDirectory = Directory(buildDir) + Directory("netcoreapp2.0/ubuntu.16.04-x64/published"); + publishSettings.Runtime = "ubuntu-x64"; + publishSettings.OutputDirectory = Directory(buildDir) + Directory("netcoreapp2.0/ubuntu-x64/published"); DotNetCorePublish("./src/Ombi/Ombi.csproj", publishSettings); - CopyFile(buildDir + "/netcoreapp2.0/ubuntu.16.04-x64/Swagger.xml", buildDir + "/netcoreapp2.0/ubuntu.16.04-x64/published/Swagger.xml"); + CopyFile(buildDir + "/netcoreapp2.0/ubuntu-x64/Swagger.xml", buildDir + "/netcoreapp2.0/ubuntu-x64/published/Swagger.xml"); DotNetCorePublish("./src/Ombi.Updater/Ombi.Updater.csproj", publishSettings); }); Task("Publish-Debian") @@ -200,6 +202,17 @@ Task("Publish-Centos") DotNetCorePublish("./src/Ombi.Updater/Ombi.Updater.csproj", publishSettings); }); +Task("Publish-Linux") + .Does(() => +{ + publishSettings.Runtime = "linux-x64"; + publishSettings.OutputDirectory = Directory(buildDir) + Directory("netcoreapp2.0/linux-x64/published"); + + DotNetCorePublish("./src/Ombi/Ombi.csproj", publishSettings); + CopyFile(buildDir + "/netcoreapp2.0/linux-x64/Swagger.xml", buildDir + "/netcoreapp2.0/linux-x64/published/Swagger.xml"); + DotNetCorePublish("./src/Ombi.Updater/Ombi.Updater.csproj", publishSettings); +}); + Task("Run-Unit-Tests") .IsDependentOn("Publish") .Does(() => diff --git a/src/Ombi.DependencyInjection/IocExtensions.cs b/src/Ombi.DependencyInjection/IocExtensions.cs index 8f8effd87..645abc49e 100644 --- a/src/Ombi.DependencyInjection/IocExtensions.cs +++ b/src/Ombi.DependencyInjection/IocExtensions.cs @@ -54,7 +54,6 @@ namespace Ombi.DependencyInjection services.RegisterApi(); services.RegisterServices(); services.RegisterStore(); - services.RegisterIdentity(); services.RegisterJobs(); } @@ -135,15 +134,5 @@ namespace Ombi.DependencyInjection services.AddTransient(); services.AddTransient(); } - - public static void RegisterIdentity(this IServiceCollection services) - { - services.AddAuthorization(auth => - { - auth.AddPolicy("Bearer", new AuthorizationPolicyBuilder() - .AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme) - .RequireAuthenticatedUser().Build()); - }); - } } } diff --git a/src/Ombi.sln b/src/Ombi.sln index 3b5a3f2e9..111bfb95b 100644 --- a/src/Ombi.sln +++ b/src/Ombi.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26730.10 +VisualStudioVersion = 15.0.26730.15 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ombi", "Ombi\Ombi.csproj", "{C987AA67-AFE1-468F-ACD3-EAD5A48E1F6A}" EndProject @@ -10,7 +10,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution ..\appveyor.yml = ..\appveyor.yml ..\build.cake = ..\build.cake ..\CHANGELOG.md = ..\CHANGELOG.md - ..\global.json = ..\global.json EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ombi.Core", "Ombi.Core\Ombi.Core.csproj", "{F56E79C7-791D-4668-A0EC-29E3BBC8D24B}" diff --git a/src/Ombi/Controllers/TokenController.cs b/src/Ombi/Controllers/TokenController.cs index abe505ddd..fd2332bce 100644 --- a/src/Ombi/Controllers/TokenController.cs +++ b/src/Ombi/Controllers/TokenController.cs @@ -77,6 +77,7 @@ namespace Ombi.Controllers var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_tokenAuthenticationOptions.SecretKey)); var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256); + var token = new JwtSecurityToken( claims: claims, expires: DateTime.UtcNow.AddHours(5), diff --git a/src/Ombi/Startup.cs b/src/Ombi/Startup.cs index 695b60bc5..86642c272 100644 --- a/src/Ombi/Startup.cs +++ b/src/Ombi/Startup.cs @@ -90,7 +90,32 @@ namespace Ombi }); 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.AddMvc() .AddJsonOptions(x => x.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore); @@ -156,29 +181,8 @@ namespace Ombi }); - 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().AddJwtBearer(x => - { - x.Audience = "Ombi"; - x.TokenValidationParameters = tokenValidationParameters; - }); - // Build the intermediate service provider var serviceProvider = services.BuildServiceProvider(); @@ -195,17 +199,15 @@ namespace Ombi - app.UseAuthentication(); - loggerFactory.AddSerilog(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); - app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions - { - HotModuleReplacement = true - }); + //app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions + //{ + // HotModuleReplacement = true + //}); } app.UseHangfireServer(); @@ -235,6 +237,10 @@ namespace Ombi ContentTypeProvider = provider }); + + + app.UseAuthentication(); + app.UseMvc(routes => { routes.MapRoute(