From fdb54989b0767fa90a210655482d61d7bd24d5df Mon Sep 17 00:00:00 2001 From: tidusjar Date: Wed, 2 Mar 2022 20:15:56 +0000 Subject: [PATCH] refactor: :recycle: Small changes around the header auth --- .../Settings/Models/AuthenticationSettings.cs | 1 - .../ClientApp/src/app/login/login.component.ts | 14 +++++++++----- src/Ombi/Controllers/V1/TokenController.cs | 6 ++---- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/Ombi.Settings/Settings/Models/AuthenticationSettings.cs b/src/Ombi.Settings/Settings/Models/AuthenticationSettings.cs index a72708123..ed2775480 100644 --- a/src/Ombi.Settings/Settings/Models/AuthenticationSettings.cs +++ b/src/Ombi.Settings/Settings/Models/AuthenticationSettings.cs @@ -15,6 +15,5 @@ namespace Ombi.Settings.Settings.Models public bool EnableOAuth { get; set; } // Plex OAuth public bool EnableHeaderAuth { get; set; } // Header SSO public string HeaderAuthVariable { get; set; } // Header SSO - } } \ No newline at end of file diff --git a/src/Ombi/ClientApp/src/app/login/login.component.ts b/src/Ombi/ClientApp/src/app/login/login.component.ts index 132554f4f..f6f519191 100644 --- a/src/Ombi/ClientApp/src/app/login/login.component.ts +++ b/src/Ombi/ClientApp/src/app/login/login.component.ts @@ -106,7 +106,10 @@ export class LoginComponent implements OnDestroy, OnInit { this.settingsService .getAuthentication() - .subscribe((x) => { this.authenticationSettings = x; this.headerAuth(); }); + .subscribe((x) => { + this.authenticationSettings = x; + this.headerAuth(); + }); this.settingsService.getClientId().subscribe((x) => (this.clientId = x)); this.images.getRandomBackground().subscribe((x) => { this.background = this.sanitizer.bypassSecurityTrustStyle( @@ -255,10 +258,9 @@ export class LoginComponent implements OnDestroy, OnInit { } public headerAuth() { - if (this.authenticationSettings.enableHeaderAuth) { - this.authService.headerAuth().subscribe( - (x) => { + this.authService.headerAuth().subscribe({ + next: (x) => { this.store.save("id_token", x.access_token); if (this.authService.loggedIn()) { @@ -270,11 +272,13 @@ export class LoginComponent implements OnDestroy, OnInit { }); } }, - (err) => { + error: (e) => { this.notify.open(this.errorBody, "OK", { duration: 3000000, }); + console.error(e); } + } ); } } diff --git a/src/Ombi/Controllers/V1/TokenController.cs b/src/Ombi/Controllers/V1/TokenController.cs index 67f0e1189..3a409c206 100644 --- a/src/Ombi/Controllers/V1/TokenController.cs +++ b/src/Ombi/Controllers/V1/TokenController.cs @@ -147,7 +147,6 @@ namespace Ombi.Controllers.V1 var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(StartupSingleton.Instance.SecurityKey)); var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256); - var token = new JwtSecurityToken( claims: claims, expires: rememberMe ? DateTime.Now.AddYears(1) : DateTime.Now.AddDays(7), @@ -279,17 +278,16 @@ namespace Ombi.Controllers.V1 [HttpPost("header_auth")] [ProducesResponseType(401)] + [ProducesResponseType(200)] public async Task HeaderAuth() { - string username = null; - var authSettings = await _authSettings.GetSettingsAsync(); _log.LogInformation("Logging with header: " + authSettings.HeaderAuthVariable); if (authSettings.HeaderAuthVariable != null && authSettings.EnableHeaderAuth) { if (Request.HttpContext?.Request?.Headers != null && Request.HttpContext.Request.Headers.ContainsKey(authSettings.HeaderAuthVariable)) { - username = Request.HttpContext.Request.Headers[authSettings.HeaderAuthVariable].ToString(); + var username = Request.HttpContext.Request.Headers[authSettings.HeaderAuthVariable].ToString(); // Check if user exists var user = await _userManager.FindByNameAsync(username);