Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the option for header authentication to create users #4841

Merged
merged 3 commits into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ public class AuthenticationSettings : Settings
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
}
}
1 change: 1 addition & 0 deletions src/Ombi/ClientApp/src/app/interfaces/ISettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ export interface IAuthenticationSettings extends ISettings {
enableOAuth: boolean;
enableHeaderAuth: boolean;
headerAuthVariable: string;
headerAuthCreateUser: boolean;
}

export interface ICustomPage extends ISettings {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
<div class="checkbox">
<mat-slide-toggle id="enableHeaderAuth" name="enableHeaderAuth" formControlName="enableHeaderAuth">Enable Authentication with Header Variable</mat-slide-toggle>
</div>
<div class="alert warning-box">
Enabling Header Authentication will allow anyone to bypass authentication unless you are using a properly configured reverse proxy. Use with caution!
</div>
</div>

<div class="form-group" *ngIf="form.controls.enableHeaderAuth.value">
Expand All @@ -32,6 +35,15 @@
</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 class="alert warning-box" *ngIf="form.controls.headerAuthCreateUser.value">
If the user in the Header Authentication variable does not exist, a new user will be created. You can configure the default permissions for new users in the <a target="_blank" href="/Settings/UserManagement">User Management settings</a>.
</div>
</div>


<div class="form-group">
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@
::ng-deep .dark .btn:hover {
box-shadow: 0 5px 11px 0 rgba(255, 255, 255, 0.18), 0 4px 15px 0 rgba(255, 255, 255, 0.15);
color: inherit;
}
}

.warning-box {
margin: 16px 0;
color: white;
background-color: $ombi-background-accent;
border-color: $warn;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
28 changes: 26 additions & 2 deletions src/Ombi/Controllers/V1/TokenController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,23 @@ public class Token
public class TokenController : ControllerBase
{
public TokenController(OmbiUserManager um, ITokenRepository token,
IPlexOAuthManager oAuthManager, ILogger<TokenController> logger, ISettingsService<AuthenticationSettings> auth)
IPlexOAuthManager oAuthManager, ILogger<TokenController> logger, ISettingsService<AuthenticationSettings> auth,
ISettingsService<UserManagementSettings> userManagement)
{
_userManager = um;
_token = token;
_plexOAuthManager = oAuthManager;
_log = logger;
_authSettings = auth;
_userManagementSettings = userManagement;
}

private readonly ITokenRepository _token;
private readonly OmbiUserManager _userManager;
private readonly IPlexOAuthManager _plexOAuthManager;
private readonly ILogger<TokenController> _log;
private readonly ISettingsService<AuthenticationSettings> _authSettings;
private readonly ISettingsService<UserManagementSettings> _userManagementSettings;

/// <summary>
/// Gets the token.
Expand Down Expand Up @@ -305,7 +308,28 @@ public async Task<IActionResult> HeaderAuth()
var user = await _userManager.FindByNameAsync(username);
if (user == null)
{
return new UnauthorizedResult();
if (authSettings.HeaderAuthCreateUser)
{
var defaultSettings = await _userManagementSettings.GetSettingsAsync();
user = new OmbiUser {
UserName = username,
UserType = UserType.LocalUser,
StreamingCountry = defaultSettings.DefaultStreamingCountry ?? "US",
MovieRequestLimit = defaultSettings.MovieRequestLimit,
MovieRequestLimitType = defaultSettings.MovieRequestLimitType,
EpisodeRequestLimit = defaultSettings.EpisodeRequestLimit,
EpisodeRequestLimitType = defaultSettings.EpisodeRequestLimitType,
MusicRequestLimit = defaultSettings.MusicRequestLimit,
MusicRequestLimitType = defaultSettings.MusicRequestLimitType,
};

await _userManager.CreateAsync(user);
await _userManager.AddToRolesAsync(user, defaultSettings.DefaultRoles);
}
else
{
return new UnauthorizedResult();
}
}

return await CreateToken(true, user);
Expand Down