diff --git a/BuildTask.ps1 b/BuildTask.ps1 new file mode 100644 index 000000000..aa968b3fa --- /dev/null +++ b/BuildTask.ps1 @@ -0,0 +1,20 @@ + +param([String]$env='local', +[String]$ver='3.0.0', +[String]$basePath='') + +"Environment: " + $env | Write-Output; +"Build Version: " + $ver | Write-Output; +"Base Path: " + $basePath | Write-Output; + +$appSettingsPath = $basePath + '\src\Ombi\appsettings.json' +$appSettings = Get-Content $appSettingsPath -raw +$appSettings = $appSettings.Replace("{{VERSIONNUMBER}}",$ver); +Set-Content -Path $appSettingsPath -Value $appSettings + +$configPath = $basePath + '\src\Ombi\wwwroot\app\config.ts'; +$config = Get-Content $configPath -raw + +$config = $config.Replace("{{ENVIRONMENT}}",$env); +$config | Write-Output +#Set-Content -Path $configPath -Value $config \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml index 8f63fc81d..b8e36aa17 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -10,6 +10,7 @@ before_build: - appveyor-retry npm install -g gulp - appveyor-retry npm install - appveyor-retry bower install +- ps: %APPVEYOR_BUILD_FOLDER%\BuildTask.ps1 -env "live" -ver "%APPVEYOR_BUILD_VERSION%" -basePath "%APPVEYOR_BUILD_FOLDER%" - gulp publish build_script: - dotnet build diff --git a/src/Ombi.DependencyInjection/IocExtensions.cs b/src/Ombi.DependencyInjection/IocExtensions.cs index 48f954cb8..861ca00e6 100644 --- a/src/Ombi.DependencyInjection/IocExtensions.cs +++ b/src/Ombi.DependencyInjection/IocExtensions.cs @@ -57,7 +57,7 @@ namespace Ombi.DependencyInjection { services.AddEntityFrameworkSqlite().AddDbContext(); - services.AddTransient(); + services.AddScoped(); services.AddTransient(); services.AddTransient(); services.AddTransient(); diff --git a/src/Ombi.Store/Context/IOmbiContext.cs b/src/Ombi.Store/Context/IOmbiContext.cs index 2b10503d7..977146646 100644 --- a/src/Ombi.Store/Context/IOmbiContext.cs +++ b/src/Ombi.Store/Context/IOmbiContext.cs @@ -17,5 +17,6 @@ namespace Ombi.Store.Context DbSet Users { get; set; } EntityEntry Entry(T entry) where T : class; EntityEntry Attach(TEntity entity) where TEntity : class; + DbSet Set() where TEntity : class; } } \ No newline at end of file diff --git a/src/Ombi.Store/Repository/UserRepository.cs b/src/Ombi.Store/Repository/UserRepository.cs index 0444f410e..9d7230510 100644 --- a/src/Ombi.Store/Repository/UserRepository.cs +++ b/src/Ombi.Store/Repository/UserRepository.cs @@ -41,11 +41,13 @@ namespace Ombi.Store.Repository Db = ctx; } - private IOmbiContext Db { get; } + private IOmbiContext Db { get; } public async Task GetUser(string username) { - return await Db.Users.FirstOrDefaultAsync(x => x.Username.ToLower() == username.ToLower()); + var user = await Db.Users.FirstOrDefaultAsync(x => x.Username.ToLower() == username.ToLower()); + Db.Entry(user).Reload(); + return user; } public async Task CreateUser(User user) diff --git a/src/Ombi.sln b/src/Ombi.sln index c3c621aaf..e7dceb9e4 100644 --- a/src/Ombi.sln +++ b/src/Ombi.sln @@ -1,13 +1,14 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26403.7 +VisualStudioVersion = 15.0.26430.6 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ombi", "Ombi\Ombi.csproj", "{C987AA67-AFE1-468F-ACD3-EAD5A48E1F6A}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{9D30CCF8-A115-4EB7-A34D-07780D752789}" ProjectSection(SolutionItems) = preProject ..\appveyor.yml = ..\appveyor.yml + ..\BuildTask.ps1 = ..\BuildTask.ps1 Build\publish windows.bat = Build\publish windows.bat Build\publish.bat = Build\publish.bat EndProjectSection diff --git a/src/Ombi/Auth/TokenAuthenticationOptions.cs b/src/Ombi/Auth/TokenAuthenticationOptions.cs new file mode 100644 index 000000000..657872e80 --- /dev/null +++ b/src/Ombi/Auth/TokenAuthenticationOptions.cs @@ -0,0 +1,11 @@ +namespace Ombi.Auth +{ + public class TokenAuthenticationOptions + { + public string SecretKey { get; set; } + public string Issuer { get; set; } + public string Audience { get; set; } + public string TokenPath { get; set; } + public string CookieName { get; set; } + } +} \ No newline at end of file diff --git a/src/Ombi/Auth/TokenProviderOptions.cs b/src/Ombi/Auth/TokenProviderOptions.cs index 1128ba086..d48b23392 100644 --- a/src/Ombi/Auth/TokenProviderOptions.cs +++ b/src/Ombi/Auth/TokenProviderOptions.cs @@ -30,7 +30,7 @@ namespace Ombi.Auth /// /// The expiration time for the generated tokens. /// - /// The default is 7 Days. + /// The default is 1 Days. public TimeSpan Expiration { get; set; } = TimeSpan.FromDays(1); /// diff --git a/src/Ombi/Startup.Auth.cs b/src/Ombi/Startup.Auth.cs index c1365762a..f64e33915 100644 --- a/src/Ombi/Startup.Auth.cs +++ b/src/Ombi/Startup.Auth.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Security.Claims; using System.Security.Principal; using System.Text; @@ -9,24 +8,23 @@ using Microsoft.Extensions.Options; using Microsoft.IdentityModel.Tokens; using Ombi.Auth; using Ombi.Core.IdentityResolver; -using Ombi.Core.Models; namespace Ombi { public partial class Startup { - public SymmetricSecurityKey signingKey; - private void ConfigureAuth(IApplicationBuilder app) + public SymmetricSecurityKey SigningKey; + private void ConfigureAuth(IApplicationBuilder app, IOptions options) { - var signingKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes("secretkey_secretkey123!")); + var signingKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(options.Value.SecretKey)); var tokenProviderOptions = new TokenProviderOptions { - Path = "/api/v1/token/", - Audience = "DemoAudience", - Issuer = "DemoIssuer", + Path = options.Value.TokenPath, + Audience = options.Value.Audience, + Issuer = options.Value.Issuer, SigningCredentials = new SigningCredentials(signingKey, SecurityAlgorithms.HmacSha256), IdentityResolver = GetIdentity }; @@ -38,10 +36,10 @@ namespace Ombi IssuerSigningKey = signingKey, // Validate the JWT Issuer (iss) claim ValidateIssuer = true, - ValidIssuer = "DemoIssuer", + ValidIssuer = options.Value.Issuer, // Validate the JWT Audience (aud) claim ValidateAudience = true, - ValidAudience = "DemoAudience", + ValidAudience = options.Value.Audience, // Validate the token expiry ValidateLifetime = true, // If you want to allow a certain amount of clock drift, set that here: diff --git a/src/Ombi/Startup.cs b/src/Ombi/Startup.cs index 1a57e7420..a89893cab 100644 --- a/src/Ombi/Startup.cs +++ b/src/Ombi/Startup.cs @@ -13,6 +13,8 @@ using Microsoft.AspNetCore.StaticFiles; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; +using Ombi.Auth; using Ombi.DependencyInjection; using Ombi.Mapping; using Ombi.Schedule; @@ -69,6 +71,7 @@ namespace Ombi services.AddScoped(sp => sp.GetService().HttpContext.User); + services.Configure(Configuration.GetSection("TokenAuthentication")); services.AddHangfire(x => { @@ -99,7 +102,7 @@ namespace Ombi var jobSetup = (IJobSetup)app.ApplicationServices.GetService(typeof(IJobSetup)); jobSetup.Setup(); - ConfigureAuth(app); + ConfigureAuth(app, (IOptions)app.ApplicationServices.GetService(typeof(IOptions))); var provider = new FileExtensionContentTypeProvider(); provider.Mappings[".map"] = "application/octet-stream"; diff --git a/src/Ombi/appsettings.json b/src/Ombi/appsettings.json index f3d45d9cc..9f2b53bdb 100644 --- a/src/Ombi/appsettings.json +++ b/src/Ombi/appsettings.json @@ -5,10 +5,11 @@ "Default": "Warning" } }, + "Version": "{{VERSIONNUMBER}}", "TokenAuthentication": { - "SecretKey": "secretkey_secretkey123!", - "Issuer": "DemoIssuer", - "Audience": "DemoAudience", + "SecretKey": "OmbiKey", + "Issuer": "OmbiIssuer", + "Audience": "OmbiAudience", "TokenPath": "/api/v1/token/", "CookieName": "access_token" } diff --git a/src/Ombi/wwwroot/app/config.ts b/src/Ombi/wwwroot/app/config.ts index e2c0270f0..8a28d31ed 100644 --- a/src/Ombi/wwwroot/app/config.ts +++ b/src/Ombi/wwwroot/app/config.ts @@ -6,7 +6,7 @@ enum envs { live = 2 } -var envVar = '{something}'; +var envVar = '{{ENVIRONMENT}}'; var env = envs.local; if (envs[envVar]) { env = envs[envVar]; diff --git a/src/Ombi/wwwroot/app/login/login.component.ts b/src/Ombi/wwwroot/app/login/login.component.ts index 6c725f8c8..3344f6e9a 100644 --- a/src/Ombi/wwwroot/app/login/login.component.ts +++ b/src/Ombi/wwwroot/app/login/login.component.ts @@ -3,7 +3,6 @@ import { Router } from '@angular/router'; import { AuthService } from '../auth/auth.service'; import { StatusService } from '../services/status.service'; -import { IdentityService } from '../services/identity.service'; import { NotificationService } from '../services/notification.service'; @Component({ @@ -12,7 +11,7 @@ import { NotificationService } from '../services/notification.service'; templateUrl: './login.component.html', }) export class LoginComponent { - constructor(private authService: AuthService, private router: Router, private notify: NotificationService, private status: StatusService, private identityService: IdentityService) { + constructor(private authService: AuthService, private router: Router, private notify: NotificationService, private status: StatusService) { this.status.getWizardStatus().subscribe(x => { if (!x.result) { this.router.navigate(['Wizard']);