refactor: ♻️ Small changes around the header auth

pull/4532/head
tidusjar 3 years ago
parent 71aa74ddcc
commit fdb54989b0

@ -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
}
}

@ -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);
}
}
);
}
}

@ -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<IActionResult> 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);

Loading…
Cancel
Save