mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-19 12:59:39 -07:00
refactor: ♻️ Small changes around the header auth
This commit is contained in:
parent
71aa74ddcc
commit
fdb54989b0
3 changed files with 11 additions and 10 deletions
|
@ -15,6 +15,5 @@ namespace Ombi.Settings.Settings.Models
|
||||||
public bool EnableOAuth { get; set; } // Plex OAuth
|
public bool EnableOAuth { get; set; } // Plex OAuth
|
||||||
public bool EnableHeaderAuth { get; set; } // Header SSO
|
public bool EnableHeaderAuth { get; set; } // Header SSO
|
||||||
public string HeaderAuthVariable { get; set; } // Header SSO
|
public string HeaderAuthVariable { get; set; } // Header SSO
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -106,7 +106,10 @@ export class LoginComponent implements OnDestroy, OnInit {
|
||||||
|
|
||||||
this.settingsService
|
this.settingsService
|
||||||
.getAuthentication()
|
.getAuthentication()
|
||||||
.subscribe((x) => { this.authenticationSettings = x; this.headerAuth(); });
|
.subscribe((x) => {
|
||||||
|
this.authenticationSettings = x;
|
||||||
|
this.headerAuth();
|
||||||
|
});
|
||||||
this.settingsService.getClientId().subscribe((x) => (this.clientId = x));
|
this.settingsService.getClientId().subscribe((x) => (this.clientId = x));
|
||||||
this.images.getRandomBackground().subscribe((x) => {
|
this.images.getRandomBackground().subscribe((x) => {
|
||||||
this.background = this.sanitizer.bypassSecurityTrustStyle(
|
this.background = this.sanitizer.bypassSecurityTrustStyle(
|
||||||
|
@ -255,10 +258,9 @@ export class LoginComponent implements OnDestroy, OnInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
public headerAuth() {
|
public headerAuth() {
|
||||||
|
|
||||||
if (this.authenticationSettings.enableHeaderAuth) {
|
if (this.authenticationSettings.enableHeaderAuth) {
|
||||||
this.authService.headerAuth().subscribe(
|
this.authService.headerAuth().subscribe({
|
||||||
(x) => {
|
next: (x) => {
|
||||||
this.store.save("id_token", x.access_token);
|
this.store.save("id_token", x.access_token);
|
||||||
|
|
||||||
if (this.authService.loggedIn()) {
|
if (this.authService.loggedIn()) {
|
||||||
|
@ -270,10 +272,12 @@ export class LoginComponent implements OnDestroy, OnInit {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
(err) => {
|
error: (e) => {
|
||||||
this.notify.open(this.errorBody, "OK", {
|
this.notify.open(this.errorBody, "OK", {
|
||||||
duration: 3000000,
|
duration: 3000000,
|
||||||
});
|
});
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -147,7 +147,6 @@ namespace Ombi.Controllers.V1
|
||||||
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(StartupSingleton.Instance.SecurityKey));
|
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(StartupSingleton.Instance.SecurityKey));
|
||||||
var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
|
var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
|
||||||
|
|
||||||
|
|
||||||
var token = new JwtSecurityToken(
|
var token = new JwtSecurityToken(
|
||||||
claims: claims,
|
claims: claims,
|
||||||
expires: rememberMe ? DateTime.Now.AddYears(1) : DateTime.Now.AddDays(7),
|
expires: rememberMe ? DateTime.Now.AddYears(1) : DateTime.Now.AddDays(7),
|
||||||
|
@ -279,17 +278,16 @@ namespace Ombi.Controllers.V1
|
||||||
|
|
||||||
[HttpPost("header_auth")]
|
[HttpPost("header_auth")]
|
||||||
[ProducesResponseType(401)]
|
[ProducesResponseType(401)]
|
||||||
|
[ProducesResponseType(200)]
|
||||||
public async Task<IActionResult> HeaderAuth()
|
public async Task<IActionResult> HeaderAuth()
|
||||||
{
|
{
|
||||||
string username = null;
|
|
||||||
|
|
||||||
var authSettings = await _authSettings.GetSettingsAsync();
|
var authSettings = await _authSettings.GetSettingsAsync();
|
||||||
_log.LogInformation("Logging with header: " + authSettings.HeaderAuthVariable);
|
_log.LogInformation("Logging with header: " + authSettings.HeaderAuthVariable);
|
||||||
if (authSettings.HeaderAuthVariable != null && authSettings.EnableHeaderAuth)
|
if (authSettings.HeaderAuthVariable != null && authSettings.EnableHeaderAuth)
|
||||||
{
|
{
|
||||||
if (Request.HttpContext?.Request?.Headers != null && Request.HttpContext.Request.Headers.ContainsKey(authSettings.HeaderAuthVariable))
|
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
|
// Check if user exists
|
||||||
var user = await _userManager.FindByNameAsync(username);
|
var user = await _userManager.FindByNameAsync(username);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue