feat: allow SSO to create new users automatically

This commit is contained in:
Lea 2023-01-03 21:07:23 +01:00
commit fcbce72591
No known key found for this signature in database
GPG key ID: 1BAFFE8347019C42
5 changed files with 23 additions and 1 deletions

View file

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

View file

@ -245,6 +245,7 @@ export interface IAuthenticationSettings extends ISettings {
enableOAuth: boolean;
enableHeaderAuth: boolean;
headerAuthVariable: string;
headerAuthCreateUser: boolean;
}
export interface ICustomPage extends ISettings {

View file

@ -32,6 +32,12 @@
</div>
</div>
<div class="form-group" *ngIf="form.controls.enableHeaderAuth.value">
<div class="checkbox">
<mat-slide-toggle id="headerAuthCreateUser" name="headerAuthCreateUser" formControlName="headerAuthCreateUser">SSO creates new users automatically</mat-slide-toggle>
</div>
</div>
<div class="form-group">
<div>

View file

@ -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) {

View file

@ -304,9 +304,22 @@ namespace Ombi.Controllers.V1
// Check if user exists
var user = await _userManager.FindByNameAsync(username);
if (user == null)
{
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);
}