1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2025-09-16 09:26:36 +02:00

Change authentication to Forms if set to Basic

This commit is contained in:
Mark McDowall
2025-06-19 16:47:34 -07:00
parent 29d0073ee6
commit dfb6fdfbeb
3 changed files with 24 additions and 10 deletions

View File

@@ -209,9 +209,20 @@ namespace NzbDrone.Core.Configuration
return AuthenticationType.Forms; return AuthenticationType.Forms;
} }
return Enum.TryParse<AuthenticationType>(_authOptions.Method, out var enumValue) var value = Enum.TryParse<AuthenticationType>(_authOptions.Method, out var enumValue)
? enumValue ? enumValue
: GetValueEnum("AuthenticationMethod", AuthenticationType.None); : GetValueEnum("AuthenticationMethod", AuthenticationType.None);
#pragma warning disable CS0618 // Type or member is obsolete
if (value == AuthenticationType.Basic)
#pragma warning restore CS0618 // Type or member is obsolete
{
SetValue("AuthenticationMethod", AuthenticationType.Forms);
return AuthenticationType.Forms;
}
return value;
} }
} }
@@ -386,6 +397,12 @@ namespace NzbDrone.Core.Configuration
{ {
SetValue("EnableSsl", false); SetValue("EnableSsl", false);
} }
#pragma warning disable CS0618 // Type or member is obsolete
if (AuthenticationMethod == AuthenticationType.Basic)
#pragma warning restore CS0618 // Type or member is obsolete
{
SetValue("AuthenticationMethod", AuthenticationType.Forms);
}
} }
private void DeleteOldValues() private void DeleteOldValues()

View File

@@ -30,7 +30,7 @@ namespace Sonarr.Http.Authentication
public static AuthenticationBuilder AddAppAuthentication(this IServiceCollection services) public static AuthenticationBuilder AddAppAuthentication(this IServiceCollection services)
{ {
services.AddOptions<CookieAuthenticationOptions>(AuthenticationType.Forms.ToString()) services.AddOptions<CookieAuthenticationOptions>(nameof(AuthenticationType.Forms))
.Configure<IConfigFileProvider>((options, configFileProvider) => .Configure<IConfigFileProvider>((options, configFileProvider) =>
{ {
// Replace diacritics and replace non-word characters to ensure cookie name doesn't contain any valid URL characters not allowed in cookie names // Replace diacritics and replace non-word characters to ensure cookie name doesn't contain any valid URL characters not allowed in cookie names
@@ -47,12 +47,9 @@ namespace Sonarr.Http.Authentication
}); });
return services.AddAuthentication() return services.AddAuthentication()
.AddNone(AuthenticationType.None.ToString()) .AddNone(nameof(AuthenticationType.None))
.AddExternal(AuthenticationType.External.ToString()) .AddExternal(nameof(AuthenticationType.External))
#pragma warning disable CS0618 // Type or member is obsolete .AddCookie(nameof(AuthenticationType.Forms))
.AddCookie(AuthenticationType.Basic.ToString())
#pragma warning restore CS0618 // Type or member is obsolete
.AddCookie(AuthenticationType.Forms.ToString())
.AddApiKey("API", options => .AddApiKey("API", options =>
{ {
options.HeaderName = "X-Api-Key"; options.HeaderName = "X-Api-Key";

View File

@@ -8,7 +8,7 @@ namespace NzbDrone.Http.Authentication
{ {
public class UiAuthorizationPolicyProvider : IAuthorizationPolicyProvider public class UiAuthorizationPolicyProvider : IAuthorizationPolicyProvider
{ {
private const string POLICY_NAME = "UI"; private const string PolicyName = "UI";
private readonly IConfigFileProvider _config; private readonly IConfigFileProvider _config;
public DefaultAuthorizationPolicyProvider FallbackPolicyProvider { get; } public DefaultAuthorizationPolicyProvider FallbackPolicyProvider { get; }
@@ -26,7 +26,7 @@ namespace NzbDrone.Http.Authentication
public Task<AuthorizationPolicy> GetPolicyAsync(string policyName) public Task<AuthorizationPolicy> GetPolicyAsync(string policyName)
{ {
if (policyName.Equals(POLICY_NAME, StringComparison.OrdinalIgnoreCase)) if (policyName.Equals(PolicyName, StringComparison.OrdinalIgnoreCase))
{ {
var policy = new AuthorizationPolicyBuilder(_config.AuthenticationMethod.ToString()) var policy = new AuthorizationPolicyBuilder(_config.AuthenticationMethod.ToString())
.AddRequirements(new BypassableDenyAnonymousAuthorizationRequirement()); .AddRequirements(new BypassableDenyAnonymousAuthorizationRequirement());