From fcbce7259198435276273ccf28a0224804fea930 Mon Sep 17 00:00:00 2001 From: Lea Date: Tue, 3 Jan 2023 21:07:23 +0100 Subject: [PATCH] feat: allow SSO to create new users automatically --- .../Settings/Models/AuthenticationSettings.cs | 1 + .../ClientApp/src/app/interfaces/ISettings.ts | 1 + .../authentication/authentication.component.html | 6 ++++++ .../authentication/authentication.component.ts | 1 + src/Ombi/Controllers/V1/TokenController.cs | 15 ++++++++++++++- 5 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Ombi.Settings/Settings/Models/AuthenticationSettings.cs b/src/Ombi.Settings/Settings/Models/AuthenticationSettings.cs index ed2775480..4e40bcee7 100644 --- a/src/Ombi.Settings/Settings/Models/AuthenticationSettings.cs +++ b/src/Ombi.Settings/Settings/Models/AuthenticationSettings.cs @@ -15,5 +15,6 @@ 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 + public bool HeaderAuthCreateUser { get; set; } // Header SSO } } \ No newline at end of file diff --git a/src/Ombi/ClientApp/src/app/interfaces/ISettings.ts b/src/Ombi/ClientApp/src/app/interfaces/ISettings.ts index cd7956fdd..596a79549 100644 --- a/src/Ombi/ClientApp/src/app/interfaces/ISettings.ts +++ b/src/Ombi/ClientApp/src/app/interfaces/ISettings.ts @@ -245,6 +245,7 @@ export interface IAuthenticationSettings extends ISettings { enableOAuth: boolean; enableHeaderAuth: boolean; headerAuthVariable: string; + headerAuthCreateUser: boolean; } export interface ICustomPage extends ISettings { diff --git a/src/Ombi/ClientApp/src/app/settings/authentication/authentication.component.html b/src/Ombi/ClientApp/src/app/settings/authentication/authentication.component.html index 5960c79f7..a99491360 100644 --- a/src/Ombi/ClientApp/src/app/settings/authentication/authentication.component.html +++ b/src/Ombi/ClientApp/src/app/settings/authentication/authentication.component.html @@ -32,6 +32,12 @@ +
+
+ SSO creates new users automatically +
+
+
diff --git a/src/Ombi/ClientApp/src/app/settings/authentication/authentication.component.ts b/src/Ombi/ClientApp/src/app/settings/authentication/authentication.component.ts index 80135b195..0620ea97f 100644 --- a/src/Ombi/ClientApp/src/app/settings/authentication/authentication.component.ts +++ b/src/Ombi/ClientApp/src/app/settings/authentication/authentication.component.ts @@ -28,6 +28,7 @@ export class AuthenticationComponent implements OnInit { enableOAuth: [x.enableOAuth], enableHeaderAuth: [x.enableHeaderAuth], headerAuthVariable: [x.headerAuthVariable], + headerAuthCreateUser: [x.headerAuthCreateUser], }); this.form.controls.enableHeaderAuth.valueChanges.subscribe(x => { if (x) { diff --git a/src/Ombi/Controllers/V1/TokenController.cs b/src/Ombi/Controllers/V1/TokenController.cs index 657c95f91..3dff87857 100644 --- a/src/Ombi/Controllers/V1/TokenController.cs +++ b/src/Ombi/Controllers/V1/TokenController.cs @@ -305,7 +305,20 @@ namespace Ombi.Controllers.V1 var user = await _userManager.FindByNameAsync(username); if (user == null) { - return new UnauthorizedResult(); + if (authSettings.HeaderAuthCreateUser) + { + user = new OmbiUser { + UserName = username, + UserType = UserType.LocalUser, + StreamingCountry = "US", + }; + + await _userManager.CreateAsync(user); + } + else + { + return new UnauthorizedResult(); + } } return await CreateToken(true, user);